Dynamic switch button (User, Gestionnaire, Administrateur)
This commit is contained in:
parent
e228f20684
commit
414a701b03
3 changed files with 51 additions and 17 deletions
25
app/services/switch_devise_profile_service.rb
Normal file
25
app/services/switch_devise_profile_service.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
class SwitchDeviseProfileService
|
||||
def initialize warden
|
||||
@warden = warden
|
||||
end
|
||||
|
||||
def multiple_devise_profile_connect?
|
||||
user_signed_in? && gestionnaire_signed_in? ||
|
||||
gestionnaire_signed_in? && administrateur_signed_in? ||
|
||||
user_signed_in? && administrateur_signed_in?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_signed_in?
|
||||
!@warden.authenticate(:scope => :user).nil?
|
||||
end
|
||||
|
||||
def gestionnaire_signed_in?
|
||||
!@warden.authenticate(:scope => :gestionnaire).nil?
|
||||
end
|
||||
|
||||
def administrateur_signed_in?
|
||||
!@warden.authenticate(:scope => :administrateur).nil?
|
||||
end
|
||||
end
|
|
@ -1,15 +1,25 @@
|
|||
#switch_menu.dropdown.dropup
|
||||
%button.btn.btn-default.dropdown-toggle{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false}
|
||||
%i.fa.fa-toggle-on
|
||||
%span.caret
|
||||
%ul.dropdown-menu.dropdown-menu-left
|
||||
%li
|
||||
= link_to(users_dossiers_path, id: :menu_item_procedure) do
|
||||
%i.fa.fa-user
|
||||
|
||||
Utilisateur
|
||||
%li
|
||||
= link_to(backoffice_dossiers_path) do
|
||||
%i.fa.fa-user
|
||||
|
||||
Accompagnateur
|
||||
- if SwitchDeviseProfileService.new(warden).multiple_devise_profile_connect?
|
||||
#switch_menu.dropdown.dropup
|
||||
%button.btn.btn-default.dropdown-toggle{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false}
|
||||
%i.fa.fa-toggle-on
|
||||
%span.caret
|
||||
%ul.dropdown-menu.dropdown-menu-left
|
||||
- if user_signed_in?
|
||||
%li
|
||||
= link_to(users_dossiers_path, id: :menu_item_procedure) do
|
||||
%i.fa.fa-user
|
||||
|
||||
Utilisateur
|
||||
- if gestionnaire_signed_in?
|
||||
%li
|
||||
= link_to(backoffice_dossiers_path) do
|
||||
%i.fa.fa-user
|
||||
|
||||
Accompagnateur
|
||||
|
||||
- if administrateur_signed_in?
|
||||
%li
|
||||
= link_to(admin_procedures_path) do
|
||||
%i.fa.fa-user
|
||||
|
||||
Administrateur
|
|
@ -48,8 +48,7 @@
|
|||
%h1
|
||||
%i.fa.fa-times{style:'position: fixed; top: 10; right: 30; color: white;'}
|
||||
|
||||
- if user_signed_in? && gestionnaire_signed_in?
|
||||
= render partial: 'layouts/switch_devise_profile_module'
|
||||
= render partial: 'layouts/switch_devise_profile_module'
|
||||
|
||||
= render partial: 'layouts/footer', locals: {main_container_size: main_container_size}
|
||||
= render partial: 'layouts/google_analytics'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue