Skip to content

Commit

Permalink
Merge pull request #11308 from demarches-simplifiees/fix-confirm-email
Browse files Browse the repository at this point in the history
ETQ admin, quand je confirme/infirme l'email d'un instructeur, je peux ensuite également confirmer les autres emails avec une potentielle faute de frappe
  • Loading branch information
krichtof authored Feb 14, 2025
2 parents 65a8fba + c1c530e commit c9543d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
%p= @title
%ul#maybe_typos_errors
- @maybe_typos.each do |(actual_email, suggested_email)|
- emails_with_typos = (@maybe_typos.map(&:first) - [actual_email]).to_json
%li
= "Je confirme "
= button_to "#{actual_email}", @url, method: :POST, params: { final_email: actual_email }, class: 'fr-btn fr-btn--tertiary fr-btn--sm', form: {class: 'inline'}
= button_to "#{actual_email}", @url, method: :POST, params: { final_email: actual_email, emails_with_typos: }, class: 'fr-btn fr-btn--tertiary fr-btn--sm', form: {class: 'inline'}
= " ou "
= button_to "#{suggested_email}", @url, method: :POST, params: { final_email: suggested_email }, class: 'fr-btn fr-btn--tertiary fr-btn--sm', form: {class: 'inline'}
= button_to "#{suggested_email}", @url, method: :POST, params: { final_email: suggested_email, emails_with_typos: }, class: 'fr-btn fr-btn--tertiary fr-btn--sm', form: {class: 'inline'}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def index

@instructeurs = paginated_instructeurs
@available_instructeur_emails = available_instructeur_emails
@maybe_typos = JSON.parse(params[:maybe_typos]) if params[:maybe_typos]
end

def options
Expand Down Expand Up @@ -132,6 +133,7 @@ def show
@groupe_instructeur = groupe_instructeur
@instructeurs = paginated_instructeurs
@available_instructeur_emails = available_instructeur_emails
@maybe_typos = JSON.parse(params[:maybe_typos]) if params[:maybe_typos]
end

def create
Expand Down Expand Up @@ -236,7 +238,9 @@ def reaffecter_all_dossiers_to_defaut_groupe
end

def add_instructeur
emails_with_typos = JSON.parse(params[:emails_with_typos]) if params[:emails_with_typos]
emails = params['emails'].presence || []
emails.push(emails_with_typos).flatten! if emails_with_typos
emails = check_if_typo(emails)
errors = Array.wrap(generate_emails_suggestions_message(@maybe_typos))

Expand Down Expand Up @@ -279,12 +283,13 @@ def add_instructeur
@instructeurs = paginated_instructeurs
@available_instructeur_emails = available_instructeur_emails

query_param = { maybe_typos: @maybe_typos.to_json } if @maybe_typos.present?
if procedure.routing_enabled?
@groupe_instructeur = groupe_instructeur
redirect_to admin_procedure_groupe_instructeur_path(@procedure, @groupe_instructeur)
redirect_to admin_procedure_groupe_instructeur_path(@procedure, @groupe_instructeur, query_param)
else
@groupes_instructeurs = paginated_groupe_instructeurs
redirect_to admin_procedure_groupe_instructeurs_path(@procedure)
redirect_to admin_procedure_groupe_instructeurs_path(@procedure, query_param)
end
end

Expand Down
10 changes: 6 additions & 4 deletions app/controllers/instructeurs/groupe_instructeurs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ def show
@procedure = procedure
@groupe_instructeur = groupe_instructeur
@instructeurs = paginated_instructeurs
@maybe_typos = JSON.parse(params[:maybe_typos]) if params[:maybe_typos]
end

def add_instructeur
emails_with_typos = JSON.parse(params[:emails_with_typos]) if params[:emails_with_typos]
emails = params['emails'].presence || []
emails.push(emails_with_typos).flatten! if emails_with_typos
emails = check_if_typo(emails)
errors = Array.wrap(generate_emails_suggestions_message(@maybe_typos))

Expand Down Expand Up @@ -62,11 +65,10 @@ def add_instructeur
@groupe_instructeur = groupe_instructeur
@instructeurs = paginated_instructeurs

if !errors.empty?
flash.now[:alert] = errors.join(". ") if !errors.empty?
end
flash[:alert] = errors.join(". ") if !errors.empty?

render :show
query_param = { maybe_typos: @maybe_typos.to_json } if @maybe_typos.present?
redirect_to instructeur_groupe_path(@procedure, @groupe_instructeur, query_param)
end

def remove_instructeur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
it "works" do
expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email)
expect(flash.notice).to be_present
expect(response).to have_http_status(:success)
expect(subject).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(instance_of(Instructeur), gi_1_2, anything)
expect(GroupeInstructeurMailer).not_to have_received(:notify_added_instructeurs)
end
Expand All @@ -114,7 +114,7 @@
it "works" do
expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email)
expect(flash.notice).to be_present
expect(response).to have_http_status(:success)
expect(subject).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
expect(InstructeurMailer).not_to have_received(:confirm_and_notify_added_instructeur)
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs)
end
Expand All @@ -129,7 +129,7 @@
it "works" do
expect(gi_1_2.instructeurs.map(&:email)).to include(new_instructeur_email)
expect(flash.notice).to be_present
expect(response).to have_http_status(:success)
expect(subject).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur)
expect(GroupeInstructeurMailer).not_to have_received(:notify_added_instructeurs)
end
Expand All @@ -143,7 +143,7 @@
end

it "works" do
expect(response).to have_http_status(:success)
expect(subject).to redirect_to(instructeur_groupe_path(procedure, gi_1_2))
expect(InstructeurMailer).not_to have_received(:confirm_and_notify_added_instructeur)
expect(GroupeInstructeurMailer).not_to have_received(:notify_added_instructeurs)
end
Expand Down

0 comments on commit c9543d4

Please sign in to comment.