Merge pull request #11059 from colinux/navbar-procedure-context
ETQ instructeur ou admin je garde le contexte de la démarche en passant d'un profil à l'autre
This commit is contained in:
commit
b426e51d87
15 changed files with 183 additions and 64 deletions
42
app/components/account_dropdown_component.rb
Normal file
42
app/components/account_dropdown_component.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountDropdownComponent < ViewComponent::Base
|
||||
attr_reader :dossier
|
||||
attr_reader :nav_bar_profile
|
||||
|
||||
delegate :current_email, :color_by_role, :multiple_devise_profile_connect?,
|
||||
:user_signed_in?, :instructeur_signed_in?, :expert_signed_in?,
|
||||
:administrateur_signed_in?, :gestionnaire_signed_in?, :super_admin_signed_in?,
|
||||
to: :helpers
|
||||
|
||||
def initialize(dossier:, nav_bar_profile:)
|
||||
@dossier = dossier
|
||||
@nav_bar_profile = nav_bar_profile
|
||||
end
|
||||
|
||||
def france_connected?
|
||||
dossier&.france_connected_with_one_identity?
|
||||
end
|
||||
|
||||
def show_profile_badge?
|
||||
nav_bar_profile != :guest
|
||||
end
|
||||
|
||||
def instructeur_path
|
||||
if controller_name == "procedures" && params[:id].present?
|
||||
instructeur_procedure_path(params[:id])
|
||||
elsif params[:procedure_id].present?
|
||||
instructeur_procedure_path(params[:procedure_id])
|
||||
else
|
||||
instructeur_procedures_path
|
||||
end
|
||||
end
|
||||
|
||||
def admin_path
|
||||
if params[:procedure_id].present?
|
||||
admin_procedure_path(params[:procedure_id])
|
||||
else
|
||||
admin_procedures_path
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
en:
|
||||
go_superadmin: 'Switch to super-admin'
|
||||
go_user: 'Switch to user'
|
||||
go_instructor: 'Switch to instructor'
|
||||
go_expert: 'Switch to expert'
|
||||
go_admin: 'Switch to administrator'
|
||||
go_gestionnaire: 'Switch to admins group manager'
|
||||
profile: 'See my profile'
|
||||
logout: 'Log out'
|
||||
my_account: 'My profile'
|
||||
connected_as: 'connected as %{profile}'
|
|
@ -0,0 +1,11 @@
|
|||
fr:
|
||||
go_superadmin: 'Passer en super-admin'
|
||||
go_user: 'Passer en usager'
|
||||
go_instructor: 'Passer en instructeur'
|
||||
go_expert: 'Passer en expert'
|
||||
go_admin: 'Passer en administrateur'
|
||||
go_gestionnaire: 'Passer en gestionnaire'
|
||||
profile: 'Voir mon profil'
|
||||
logout: 'Se déconnecter'
|
||||
my_account: 'Mon profil'
|
||||
connected_as: 'connecté en tant qu’%{profile}'
|
|
@ -1,57 +1,58 @@
|
|||
%nav.fr-translate.fr-nav{ role: "navigation", "aria-label"=> t('my_account', scope: [:layouts]) }
|
||||
%nav.fr-translate.fr-nav{ role: "navigation", "aria-label" => t('.my_account') }
|
||||
.fr-nav__item
|
||||
%button.account-btn.fr-translate__btn.fr-btn{ "aria-controls" => "account", "aria-expanded" => "false", :title => t('my_account', scope: [:layouts]) }
|
||||
%button.account-btn.fr-translate__btn.fr-btn{ "aria-controls" => "account", "aria-expanded" => "false", title: t('.my_account') }
|
||||
%span.fr-mr-1w= current_email
|
||||
- if dossier.present? && dossier&.france_connected_with_one_identity?
|
||||
%span
|
||||
via FranceConnect
|
||||
- if nav_bar_profile != :guest # don't confuse user with unknown profile
|
||||
- if france_connected?
|
||||
%span via FranceConnect
|
||||
|
||||
- if show_profile_badge?
|
||||
%span{ class: "fr-badge fr-badge--sm #{color_by_role(nav_bar_profile)}" }
|
||||
= t("layouts.#{nav_bar_profile}")
|
||||
= t(nav_bar_profile, scope: :layouts)
|
||||
|
||||
#account.fr-collapse.fr-menu
|
||||
%ul.fr-menu__list.max-content
|
||||
- if multiple_devise_profile_connect?
|
||||
%li
|
||||
= link_to "#", class: "fr-nav__link", "aria-current" => "true" do
|
||||
= t('layouts.connected_as', profile: t("layouts.#{nav_bar_profile}"))
|
||||
= t('.connected_as', profile: t(nav_bar_profile, scope: :layouts))
|
||||
|
||||
- if user_signed_in? && nav_bar_profile != :user
|
||||
%li
|
||||
= link_to dossiers_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('go_user', scope: [:layouts])
|
||||
= t('.go_user')
|
||||
- if instructeur_signed_in? && nav_bar_profile != :instructeur
|
||||
%li
|
||||
= link_to instructeur_procedures_path, class: "fr-nav__link" do
|
||||
= link_to instructeur_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('go_instructor', scope: [:layouts])
|
||||
= t('.go_instructor')
|
||||
- if expert_signed_in? && nav_bar_profile != :expert
|
||||
%li
|
||||
= link_to expert_all_avis_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('go_expert', scope: [:layouts])
|
||||
= t('.go_expert')
|
||||
- if administrateur_signed_in? && nav_bar_profile != :administrateur
|
||||
%li
|
||||
= link_to admin_procedures_path, class: "fr-nav__link" do
|
||||
= link_to admin_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('go_admin', scope: [:layouts])
|
||||
= t('.go_admin')
|
||||
- if gestionnaire_signed_in? && nav_bar_profile != :gestionnaire
|
||||
%li
|
||||
= link_to gestionnaire_groupe_gestionnaires_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('go_gestionnaire', scope: [:layouts])
|
||||
= t('.go_gestionnaire')
|
||||
|
||||
- if super_admin_signed_in? && nav_bar_profile != :superadmin
|
||||
%li
|
||||
= link_to manager_root_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-shield-line.fr-icon--sm
|
||||
= t('go_superadmin', scope: [:layouts])
|
||||
= t('.go_superadmin')
|
||||
|
||||
%li
|
||||
= link_to profil_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-user-line.fr-icon--sm
|
||||
= t('profile', scope: [:layouts])
|
||||
= t('.profile')
|
||||
%li
|
||||
= link_to destroy_user_session_path, method: :delete, class: "fr-nav__link" do
|
||||
%span.fr-icon-logout-box-r-line.fr-icon--sm
|
||||
= t('logout', scope: [:layouts])
|
||||
= t('.logout')
|
|
@ -20,7 +20,7 @@ class Users::SessionsController < Devise::SessionsController
|
|||
|
||||
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(', '))
|
||||
flash[:notice] = t("devise.sessions.signed_in_multiple_profile", roles: current_account.keys.map { |role| t("layouts.#{role}") }.to_sentence)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
%ul.fr-btns-group.flex.align-center
|
||||
- if instructeur_signed_in? || user_signed_in?
|
||||
%li
|
||||
= render partial: 'layouts/account_dropdown', locals: { nav_bar_profile: nav_bar_profile, dossier: dossier }
|
||||
= render AccountDropdownComponent.new(dossier: @dossier, nav_bar_profile:)
|
||||
- elsif (request.path != new_user_session_path && request.path !=agent_connect_path)
|
||||
- if request.path == new_user_registration_path
|
||||
%li.fr-hidden-sm.fr-unhidden-lg.fr-link--sm.fr-mb-2w.fr-mr-1v= t('views.shared.account.already_user_question')
|
||||
|
|
|
@ -84,6 +84,7 @@ en:
|
|||
back: "Back"
|
||||
back_title: "Back to my administration's website"
|
||||
main_menu: "Main menu"
|
||||
files: "My files"
|
||||
locale_dropdown:
|
||||
select_locale: "Choose a language"
|
||||
locale_name: "English"
|
||||
|
|
|
@ -75,6 +75,7 @@ fr:
|
|||
back: "Revenir en arrière"
|
||||
back_title: "Revenir en arrière, sur le site de mon administration"
|
||||
main_menu: "Menu principal"
|
||||
files: "Mes dossiers"
|
||||
locale_dropdown:
|
||||
select_locale: "Sélectionner une langue"
|
||||
locale_name: "Français"
|
||||
|
|
9
config/locales/layouts.en.yml
Normal file
9
config/locales/layouts.en.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
en:
|
||||
layouts:
|
||||
instructeur: instructor
|
||||
administrateur: admin
|
||||
gestionnaire: admins group manager
|
||||
superadmin: super-admin
|
||||
expert: expert
|
||||
user: user
|
||||
guest: guest
|
9
config/locales/layouts.fr.yml
Normal file
9
config/locales/layouts.fr.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
fr:
|
||||
layouts:
|
||||
instructeur: instructeur
|
||||
administrateur: administrateur
|
||||
gestionnaire: gestionnaire
|
||||
superadmin: super-admin
|
||||
expert: expert
|
||||
user: usager
|
||||
guest: invité
|
|
@ -1,21 +0,0 @@
|
|||
en:
|
||||
layouts:
|
||||
header:
|
||||
files: My files
|
||||
go_superadmin: "Switch to super-admin"
|
||||
go_user: "Switch to user"
|
||||
go_instructor: "Switch to instructor"
|
||||
go_expert: "Switch to expert"
|
||||
go_admin: "Switch to administrator"
|
||||
go_gestionnaire: "Switch to admins group manager"
|
||||
profile: "See my profile"
|
||||
logout: "Log out"
|
||||
my_account: "My profile"
|
||||
connected_as: "connected as %{profile}"
|
||||
instructeur: instructor
|
||||
administrateur: admin
|
||||
gestionnaire: admins group manager
|
||||
superadmin: super-admin
|
||||
expert: expert
|
||||
user: user
|
||||
guest: guest
|
|
@ -1,21 +0,0 @@
|
|||
fr:
|
||||
layouts:
|
||||
header:
|
||||
files: Mes dossiers
|
||||
go_superadmin: "Passer en super-admin"
|
||||
go_user: "Passer en usager"
|
||||
go_instructor: "Passer en instructeur"
|
||||
go_expert: "Passer en expert"
|
||||
go_admin: "Passer en administrateur"
|
||||
go_gestionnaire: "Passer en gestionnaire"
|
||||
profile: "Voir mon profil"
|
||||
logout: "Se déconnecter"
|
||||
my_account: "Mon profil"
|
||||
connected_as: "connecté en tant qu’%{profile}"
|
||||
instructeur: instructeur
|
||||
administrateur: administrateur
|
||||
gestionnaire: gestionnaire
|
||||
superadmin: super-admin
|
||||
expert: expert
|
||||
user: usager
|
||||
guest: invité
|
76
spec/components/account_dropdown_component_spec.rb
Normal file
76
spec/components/account_dropdown_component_spec.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe AccountDropdownComponent, type: :component do
|
||||
let(:component) { described_class.new(dossier:, nav_bar_profile:) }
|
||||
let(:dossier) { nil }
|
||||
let(:nav_bar_profile) { :user }
|
||||
let(:user) { build(:user) }
|
||||
|
||||
subject { render_inline(component) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user)
|
||||
allow_any_instance_of(ApplicationController).to receive(:super_admin_signed_in?).and_return(false)
|
||||
end
|
||||
|
||||
describe 'basic display' do
|
||||
it 'shows user email' do
|
||||
expect(subject).to have_text(user.email)
|
||||
end
|
||||
|
||||
context 'when guest profile' do
|
||||
let(:nav_bar_profile) { :guest }
|
||||
let(:user) { nil }
|
||||
|
||||
it 'does not show profile badge' do
|
||||
expect(subject).not_to have_css('.fr-badge')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'profile switching' do
|
||||
context 'when user profile' do
|
||||
let(:nav_bar_profile) { :user }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ApplicationController).to receive(:instructeur_signed_in?).and_return(true)
|
||||
end
|
||||
|
||||
it 'shows instructor switch option' do
|
||||
expect(subject).to have_link('Passer en instructeur')
|
||||
expect(subject).not_to have_link('Passer en usager')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when instructor profile' do
|
||||
let(:nav_bar_profile) { :instructeur }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(ApplicationController).to receive(:instructeur_signed_in?).and_return(true)
|
||||
end
|
||||
|
||||
it 'shows user switch option' do
|
||||
expect(subject).to have_link('Passer en usager')
|
||||
expect(subject).not_to have_link('Passer en instructeur')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when in procedures controller' do
|
||||
before do
|
||||
allow_any_instance_of(ApplicationController).to receive(:instructeur_signed_in?).and_return(true)
|
||||
allow_any_instance_of(ApplicationController).to receive(:controller_name).and_return('procedures')
|
||||
end
|
||||
|
||||
context 'with procedure id' do
|
||||
before do
|
||||
allow_any_instance_of(ApplicationController).to receive(:params)
|
||||
.and_return({ id: '123' })
|
||||
end
|
||||
|
||||
it 'links to specific procedure for instructor' do
|
||||
expect(subject.to_html).to include('/procedures/123')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -40,7 +40,7 @@ describe 'Inviting an expert:', js: true do
|
|||
visit new_user_session_path
|
||||
sign_in_with avis.expert.email, password
|
||||
|
||||
expect(page).to have_content('Vous pouvez à tout moment alterner entre vos différents profils : expert, usager.')
|
||||
expect(page).to have_content('Vous pouvez à tout moment alterner entre vos différents profils : expert et usager.')
|
||||
expect(page).to have_current_path(expert_all_avis_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ describe 'Signin in:' do
|
|||
|
||||
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.')
|
||||
expect(page).to have_content('Vous êtes connecté(e) ! Vous pouvez à tout moment alterner entre vos différents profils : administrateur, instructeur et usager.')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue