feat(file retrieval): select procedure to recover
This commit is contained in:
parent
e91eeadccb
commit
96a8e7888e
5 changed files with 83 additions and 1 deletions
|
@ -26,9 +26,22 @@ class RecoveriesController < ApplicationController
|
|||
end
|
||||
|
||||
def selection
|
||||
previous_user = User.find_by(email: cookies[:recover_previous_email])
|
||||
|
||||
@recoverables = RecoveryService
|
||||
.recoverable_procedures(previous_user:, siret:)
|
||||
|
||||
redirect_to support_recovery_path(error: :no_dossier) if @recoverables.empty?
|
||||
end
|
||||
|
||||
def post_selection
|
||||
previous_user = User.find_by(email: cookies[:recover_previous_email])
|
||||
|
||||
RecoveryService.recover_procedure!(previous_user:,
|
||||
next_user: current_user,
|
||||
siret:,
|
||||
procedure_ids:)
|
||||
|
||||
redirect_to terminee_recovery_path
|
||||
end
|
||||
|
||||
|
@ -43,6 +56,7 @@ class RecoveriesController < ApplicationController
|
|||
def nature_params = params[:nature]
|
||||
def siret = current_instructeur.agent_connect_information.siret
|
||||
def previous_email = params[:previous_email]
|
||||
def procedure_ids = params[:procedure_ids].map(&:to_i)
|
||||
|
||||
def structure_name
|
||||
# we know that the structure exists because
|
||||
|
|
16
app/helpers/recovery_selection_helper.rb
Normal file
16
app/helpers/recovery_selection_helper.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module RecoverySelectionHelper
|
||||
def recoverable_id_and_libelles(recoverables)
|
||||
recoverables
|
||||
.map { |r| [r[:procedure_id], nice_libelle(r)] }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def nice_libelle(recoverable)
|
||||
sanitize(
|
||||
"Nº #{number_with_html_delimiter(recoverable[:procedure_id])}" \
|
||||
" - #{recoverable[:libelle]} " \
|
||||
"#{tag.span(pluralize(recoverable[:count], 'dossier'), class: 'fr-tag fr-tag--sm')}"
|
||||
)
|
||||
end
|
||||
end
|
|
@ -4,5 +4,15 @@
|
|||
%h1.fr-h1 Récupération de dossiers
|
||||
|
||||
%h2.fr-h2 Sélection des démarches
|
||||
= form_tag do
|
||||
= form_tag nil do
|
||||
%fieldset#checkboxes.fr-fieldset{ 'aria-labelledby': "checkboxes-legend checkboxes-messages" }
|
||||
%legend#checkboxes-legend.fr-fieldset__legend--regular.fr-fieldset__legend
|
||||
Sélectionner les démarches que vous souhaitez récuperer.
|
||||
|
||||
- recoverable_id_and_libelles(@recoverables).each do |procedure_id, libelle|
|
||||
.fr-fieldset__element
|
||||
.fr-checkbox-group
|
||||
= check_box_tag 'procedure_ids[]', procedure_id, false, class: 'fr-checkbox', id: procedure_id
|
||||
= label_tag procedure_id, libelle, class: 'fr-label'
|
||||
|
||||
%button.fr-btn Continuer
|
||||
|
|
|
@ -22,3 +22,15 @@
|
|||
|
||||
%p Vous n'avez pas encore de compte AgentConnect ? Vous pouvez en créer un en utilisant MonComptePro.
|
||||
= link_to 'MonComptePro', 'https://moncomptepro.beta.gouv.fr', class: 'fr-btn'
|
||||
|
||||
- when 'no_dossier'
|
||||
%p Lʼadresse email « #{cookies[:retrieve_email]} » que vous avez renseignée nʼa pas de dossier concernant votre organisation.
|
||||
|
||||
%ul.fr-btns-group.fr-btns-group--inline
|
||||
%li
|
||||
= link_to 'Essayer avec une autre adresse email', identification_recovery_path, class: 'fr-btn'
|
||||
%li
|
||||
= mail_to(CONTACT_EMAIL,
|
||||
'Contactez le support',
|
||||
subject: 'Récupération de dossiers',
|
||||
class: 'fr-btn fr-btn--secondary')
|
||||
|
|
|
@ -104,5 +104,35 @@ describe RecoveriesController, type: :controller do
|
|||
expect(cookies[:recover_previous_email]).to eq('email@a.com')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #selection' do
|
||||
subject { get :selection }
|
||||
|
||||
context 'when there are no recoverable procedures' do
|
||||
before do
|
||||
allow(RecoveryService).to receive(:recoverable_procedures).and_return([])
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to(support_recovery_path(error: :no_dossier)) }
|
||||
end
|
||||
|
||||
context 'when there are recoverable procedures' do
|
||||
let(:recoverable_procedures) { [[1, 'libelle', 2]] }
|
||||
|
||||
before do
|
||||
allow(RecoveryService).to receive(:recoverable_procedures).and_return(recoverable_procedures)
|
||||
end
|
||||
|
||||
it { is_expected.to have_http_status(:success) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #post_selection' do
|
||||
subject { post :post_selection, params: { procedure_ids: [1] } }
|
||||
|
||||
before { expect(RecoveryService).to receive(:recover_procedure!) }
|
||||
|
||||
it { is_expected.to redirect_to(terminee_recovery_path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue