Merge pull request #9872 from demarches-simplifiees/add-badge-for-role-ldu

ETQ utilisateur avec plusieurs rôles, je m'y retrouve plus facilement
This commit is contained in:
Lisa Durand 2023-12-19 11:01:28 +00:00 committed by GitHub
commit f553f3c408
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 5 deletions

View file

@ -88,6 +88,7 @@ class ApplicationController < ActionController::Base
gestionnaire: current_gestionnaire,
administrateur: current_administrateur,
instructeur: current_instructeur,
expert: current_expert,
user: current_user
}.compact
end

View file

@ -16,6 +16,9 @@ class Users::SessionsController < Devise::SessionsController
end
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
def reset_link_sent

View file

@ -1,6 +1,12 @@
module ReleaseNotesHelper
def announce_category_badge(category)
color_class = case category.to_sym
color_class = color_by_role(category)
content_tag(:span, ReleaseNote.human_attribute_name("categories.#{category}"), class: "fr-badge #{color_class}")
end
def color_by_role(role)
case role.to_sym
when :administrateur
'fr-badge--blue-cumulus'
when :instructeur
@ -12,8 +18,6 @@ module ReleaseNotesHelper
when :api
'fr-badge--pink-macaron'
end
content_tag(:span, ReleaseNote.human_attribute_name("categories.#{category}"), class: "fr-badge #{color_class}")
end
def infer_default_announce_categories

View file

@ -1,8 +1,9 @@
%nav.fr-translate.fr-nav{ role: "navigation", "aria-label"=> t('menu_aria_label', scope: [:layouts]) }
.fr-nav__item
%button.account-btn.fr-translate__btn.fr-btn{ "aria-controls" => "account", "aria-expanded" => "false", :title => t('my_account', scope: [:layouts]) }
&nbsp;
= " #{current_email}"
%div{ class: "fr-badge fr-badge--sm fr-ml-1w #{color_by_role(nav_bar_profile)}" }
= t("layouts.#{nav_bar_profile}")
#account.fr-collapse.fr-menu
%ul.fr-menu__list.max-content
- if multiple_devise_profile_connect?

View file

@ -3,3 +3,5 @@ en:
passwords:
new:
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:
new:
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

@ -36,7 +36,7 @@ describe 'Inviting an expert:' do
visit new_user_session_path
sign_in_with avis.expert.email, password
expect(page).to have_content('Connecté(e).')
expect(page).to have_content('Vous pouvez à tout moment alterner entre vos différents profils : expert, usager.')
expect(page).to have_current_path(expert_all_avis_path)
end
end

View file

@ -12,6 +12,22 @@ describe 'Signin in:' do
sign_in_with user.email, password
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
scenario 'an existing user can lock its account' do