add profiles in flash after sign-in if multiple profile

This commit is contained in:
Lisa Durand 2023-12-19 10:25:10 +01:00
parent dfc09648d8
commit 0286d2b6fb
5 changed files with 24 additions and 1 deletions

View file

@ -16,6 +16,9 @@ class Users::SessionsController < Devise::SessionsController
end end
super super
if current_account.count > 1
flash[:notice] = t("devise.sessions.signed_in_multiple_profile", roles: current_account.keys.map { |role| t("layouts.#{role}") }.join(', '))
end
end end
def reset_link_sent def reset_link_sent

View file

@ -3,3 +3,5 @@ en:
passwords: passwords:
new: new:
request_new_password: Request new password request_new_password: Request new password
sessions:
signed_in_multiple_profile: "You are connected ! You can switch between your multiple profiles : %{roles}."

View file

@ -3,3 +3,5 @@ fr:
passwords: passwords:
new: new:
request_new_password: Demander un nouveau mot de passe request_new_password: Demander un nouveau mot de passe
sessions:
signed_in_multiple_profile: "Vous êtes connecté(e) ! Vous pouvez à tout moment alterner entre vos différents profils : %{roles}."

View file

@ -12,6 +12,22 @@ describe 'Signin in:' do
sign_in_with user.email, password sign_in_with user.email, password
expect(page).to have_current_path dossiers_path expect(page).to have_current_path dossiers_path
expect(page).to have_content('Connecté(e).')
expect(page).not_to have_content('Vous pouvez à tout moment alterner')
end
context 'user has multiple profiles' do
let!(:instructeur) { create(:instructeur, user: user) }
let!(:admin) { create(:administrateur, user: user, instructeur: instructeur) }
scenario 'he can sign-in and he is notified in flash' do
visit root_path
click_on 'Se connecter', match: :first
sign_in_with user.email, password
expect(page).to have_current_path admin_procedures_path
expect(page).to have_content('Vous êtes connecté(e) ! Vous pouvez à tout moment alterner entre vos différents profils : administrateur, instructeur, usager.')
end
end end
scenario 'an existing user can lock its account' do scenario 'an existing user can lock its account' do