feat(france_connect/particulier#callback): in case the FC email exists as an DC account which is an instructor or and administrator, returns early to new_session_path so he can connect with this existing account

This commit is contained in:
Martin 2021-11-23 10:44:38 +01:00
parent ff073f8884
commit 21894d0a0a
2 changed files with 13 additions and 0 deletions

View file

@ -19,6 +19,9 @@ class FranceConnect::ParticulierController < ApplicationController
if preexisting_unlinked_user.nil? if preexisting_unlinked_user.nil?
fci.associate_user!(fci.email_france_connect) fci.associate_user!(fci.email_france_connect)
connect_france_connect_particulier(fci.user) connect_france_connect_particulier(fci.user)
elsif !preexisting_unlinked_user.can_france_connect?
fci.destroy
redirect_to new_user_session_path, alert: t('errors.messages.france_connect.forbidden_html', reset_link: new_user_password_path)
else else
merge_token = fci.create_merge_token! merge_token = fci.create_merge_token!
redirect_to france_connect_particulier_merge_path(merge_token) redirect_to france_connect_particulier_merge_path(merge_token)

View file

@ -106,6 +106,16 @@ describe FranceConnect::ParticulierController, type: :controller do
expect(response).to redirect_to(france_connect_particulier_merge_path(fci.reload.merge_token)) expect(response).to redirect_to(france_connect_particulier_merge_path(fci.reload.merge_token))
end end
end end
context 'and an instructeur with the same email exists' do
let!(:preexisting_user) { create(:instructeur, email: email) }
it 'redirects to the merge process' do
expect { subject }.not_to change { User.count }
expect(response).to redirect_to(new_user_session_path)
expect(flash[:alert]).to eq(I18n.t('errors.messages.france_connect.forbidden_html', reset_link: new_user_password_path))
end
end
end end
end end