From e3fd1cc33ab33632f51d1d82c969183e10eafd98 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 8 Aug 2019 17:44:33 +0200 Subject: [PATCH] Remove weird switch_devise_profile_service --- app/controllers/application_controller.rb | 8 ++++++ app/services/switch_devise_profile_service.rb | 25 ------------------- app/views/layouts/_account_dropdown.haml | 2 +- .../_switch_devise_profile_module.html.haml | 2 +- spec/views/layouts/_new_header_spec.rb | 1 + 5 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 app/services/switch_devise_profile_service.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b5c955cbb..d71ab7b37 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -44,6 +44,14 @@ class ApplicationController < ActionController::Base helper_method :logged_in? + def multiple_devise_profile_connect? + user_signed_in? && instructeur_signed_in? || + instructeur_signed_in? && administrateur_signed_in? || + user_signed_in? && administrateur_signed_in? + end + + helper_method :multiple_devise_profile_connect? + def pundit_user { administrateur: current_administrateur, diff --git a/app/services/switch_devise_profile_service.rb b/app/services/switch_devise_profile_service.rb deleted file mode 100644 index 6c024863c..000000000 --- a/app/services/switch_devise_profile_service.rb +++ /dev/null @@ -1,25 +0,0 @@ -class SwitchDeviseProfileService - def initialize(warden) - @warden = warden - end - - def multiple_devise_profile_connect? - user_signed_in? && instructeur_signed_in? || - instructeur_signed_in? && administrateur_signed_in? || - user_signed_in? && administrateur_signed_in? - end - - private - - def user_signed_in? - @warden.authenticate(:scope => :user).present? - end - - def instructeur_signed_in? - @warden.authenticate(:scope => :instructeur).present? - end - - def administrateur_signed_in? - @warden.authenticate(:scope => :administrateur).present? - end -end diff --git a/app/views/layouts/_account_dropdown.haml b/app/views/layouts/_account_dropdown.haml index db7440911..9f896c390 100644 --- a/app/views/layouts/_account_dropdown.haml +++ b/app/views/layouts/_account_dropdown.haml @@ -10,7 +10,7 @@ = link_to manager_root_path, class: "menu-item menu-link" do = image_tag "icons/super-admin.svg" Passer en super-admin - - if SwitchDeviseProfileService.new(warden).multiple_devise_profile_connect? + - if multiple_devise_profile_connect? - if user_signed_in? && nav_bar_profile != :user %li = link_to dossiers_path, class: "menu-item menu-link" do diff --git a/app/views/layouts/_switch_devise_profile_module.html.haml b/app/views/layouts/_switch_devise_profile_module.html.haml index 766f795b0..3c40e6bb3 100644 --- a/app/views/layouts/_switch_devise_profile_module.html.haml +++ b/app/views/layouts/_switch_devise_profile_module.html.haml @@ -1,4 +1,4 @@ -- if SwitchDeviseProfileService.new(warden).multiple_devise_profile_connect? +- if multiple_devise_profile_connect? %ul#switch-menu %li Changer de rĂ´le diff --git a/spec/views/layouts/_new_header_spec.rb b/spec/views/layouts/_new_header_spec.rb index 90a6c32ca..e447828d5 100644 --- a/spec/views/layouts/_new_header_spec.rb +++ b/spec/views/layouts/_new_header_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe 'layouts/_new_header.html.haml', type: :view do before do + allow(view).to receive(:multiple_devise_profile_connect?).and_return(false) if user sign_in user allow(controller).to receive(:nav_bar_profile).and_return(profile)