Cleanup application_controller and current_user
This commit is contained in:
parent
88842918f9
commit
adfa80142a
6 changed files with 26 additions and 39 deletions
|
@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :set_active_storage_host
|
before_action :set_active_storage_host
|
||||||
before_action :setup_tracking
|
before_action :setup_tracking
|
||||||
|
|
||||||
helper_method :logged_in?, :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur,
|
helper_method :multiple_devise_profile_connect?, :instructeur_signed_in?, :current_instructeur,
|
||||||
:administrateur_signed_in?, :current_administrateur
|
:administrateur_signed_in?, :current_administrateur
|
||||||
|
|
||||||
def staging_authenticate
|
def staging_authenticate
|
||||||
|
@ -41,10 +41,6 @@ class ApplicationController < ActionController::Base
|
||||||
@left_pannel_url = service.left_panel
|
@left_pannel_url = service.left_panel
|
||||||
end
|
end
|
||||||
|
|
||||||
def logged_in?
|
|
||||||
logged_user.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def multiple_devise_profile_connect?
|
def multiple_devise_profile_connect?
|
||||||
user_signed_in? && instructeur_signed_in? ||
|
user_signed_in? && instructeur_signed_in? ||
|
||||||
instructeur_signed_in? && administrateur_signed_in? ||
|
instructeur_signed_in? && administrateur_signed_in? ||
|
||||||
|
@ -128,22 +124,17 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def logged_users
|
def current_user_roles
|
||||||
@logged_users ||= [
|
@current_user_roles ||= begin
|
||||||
current_user,
|
roles = [
|
||||||
current_instructeur,
|
current_user,
|
||||||
current_administrateur,
|
current_instructeur,
|
||||||
current_administration
|
current_administrateur,
|
||||||
].compact
|
current_administration
|
||||||
end
|
].compact.map { |role| role.class.name }
|
||||||
|
|
||||||
def logged_user
|
roles.any? ? roles.join(', ') : 'Guest'
|
||||||
logged_users.first
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def logged_user_roles
|
|
||||||
roles = logged_users.map { |logged_user| logged_user.class.name }
|
|
||||||
roles.any? ? roles.join(', ') : 'Guest'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_raven_context
|
def set_raven_context
|
||||||
|
@ -152,13 +143,12 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def append_info_to_payload(payload)
|
def append_info_to_payload(payload)
|
||||||
super
|
super
|
||||||
user = logged_user
|
|
||||||
|
|
||||||
payload.merge!({
|
payload.merge!({
|
||||||
user_agent: request.user_agent,
|
user_agent: request.user_agent,
|
||||||
user_id: user&.id,
|
user_id: current_user&.id,
|
||||||
user_email: user&.email,
|
user_email: current_user&.email,
|
||||||
user_roles: logged_user_roles
|
user_roles: current_user_roles
|
||||||
}.compact)
|
}.compact)
|
||||||
|
|
||||||
if browser.known?
|
if browser.known?
|
||||||
|
@ -225,8 +215,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def sentry_user
|
def sentry_user
|
||||||
user = logged_user
|
{ id: user_signed_in? ? "User##{current_user.id}" : 'Guest' }
|
||||||
{ id: user ? "#{user.class.name}##{user.id}" : 'Guest' }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sentry_config
|
def sentry_config
|
||||||
|
@ -257,14 +246,14 @@ class ApplicationController < ActionController::Base
|
||||||
key: sendinblue[:client_key],
|
key: sendinblue[:client_key],
|
||||||
enabled: sendinblue[:enabled],
|
enabled: sendinblue[:enabled],
|
||||||
administrateur: {
|
administrateur: {
|
||||||
email: current_administrateur&.email,
|
email: current_user&.email,
|
||||||
payload: {
|
payload: {
|
||||||
DS_SIGN_IN_COUNT: current_administrateur&.sign_in_count,
|
DS_SIGN_IN_COUNT: current_user&.sign_in_count,
|
||||||
DS_CREATED_AT: current_administrateur&.created_at,
|
DS_CREATED_AT: current_administrateur&.created_at,
|
||||||
DS_ACTIVE: current_administrateur&.active,
|
DS_ACTIVE: current_administrateur&.active,
|
||||||
DS_ID: current_administrateur&.id,
|
DS_ID: current_administrateur&.id,
|
||||||
DS_GESTIONNAIRE_ID: current_instructeur&.id,
|
DS_GESTIONNAIRE_ID: current_instructeur&.id,
|
||||||
DS_ROLES: logged_user_roles
|
DS_ROLES: current_user_roles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,8 +266,8 @@ class ApplicationController < ActionController::Base
|
||||||
key: crisp[:client_key],
|
key: crisp[:client_key],
|
||||||
enabled: crisp[:enabled],
|
enabled: crisp[:enabled],
|
||||||
administrateur: {
|
administrateur: {
|
||||||
email: current_administrateur&.email,
|
email: current_user&.email,
|
||||||
DS_SIGN_IN_COUNT: current_administrateur&.sign_in_count,
|
DS_SIGN_IN_COUNT: current_user&.sign_in_count,
|
||||||
DS_CREATED_AT: current_administrateur&.created_at,
|
DS_CREATED_AT: current_administrateur&.created_at,
|
||||||
DS_ID: current_administrateur&.id,
|
DS_ID: current_administrateur&.id,
|
||||||
DS_NB_DEMARCHES_BROUILLONS: current_administrateur&.procedures&.brouillons&.count,
|
DS_NB_DEMARCHES_BROUILLONS: current_administrateur&.procedures&.brouillons&.count,
|
||||||
|
@ -290,8 +279,6 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_email
|
def current_email
|
||||||
current_user&.email ||
|
current_user&.email
|
||||||
current_instructeur&.email ||
|
|
||||||
current_administrateur&.email
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Champs::SiretController < ApplicationController
|
||||||
|
|
||||||
def find_etablisement
|
def find_etablisement
|
||||||
if params[:champ_id].present?
|
if params[:champ_id].present?
|
||||||
@champ = Champ.find_by(dossier_id: logged_user.dossiers, id: params[:champ_id])
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
@etablissement = @champ&.etablissement
|
@etablissement = @champ&.etablissement
|
||||||
end
|
end
|
||||||
@procedure_id = @champ&.dossier&.procedure_id || 'aperçu'
|
@procedure_id = @champ&.dossier&.procedure_id || 'aperçu'
|
||||||
|
|
|
@ -90,6 +90,6 @@ class SupportController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def email
|
def email
|
||||||
logged_user ? logged_user.email : params[:email]
|
current_user&.email || params[:email]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
\.
|
\.
|
||||||
|
|
||||||
= form_tag contact_path, method: :post, class: 'form' do |f|
|
= form_tag contact_path, method: :post, class: 'form' do |f|
|
||||||
- if !logged_in?
|
- if !user_signed_in?
|
||||||
.contact-champ
|
.contact-champ
|
||||||
= label_tag :email do
|
= label_tag :email do
|
||||||
Adresse email professionnelle
|
Adresse email professionnelle
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
Pensez bien à nous donner le plus d'informations possible pour que nous puissions vous aider au mieux
|
Pensez bien à nous donner le plus d'informations possible pour que nous puissions vous aider au mieux
|
||||||
|
|
||||||
= form_tag contact_path, method: :post, multipart: true, class: 'form' do |f|
|
= form_tag contact_path, method: :post, multipart: true, class: 'form' do |f|
|
||||||
- if !logged_in?
|
- if !user_signed_in?
|
||||||
.contact-champ
|
.contact-champ
|
||||||
= label_tag :email do
|
= label_tag :email do
|
||||||
Email
|
Email
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe ApplicationController, type: :controller do
|
||||||
let(:payload) { {} }
|
let(:payload) { {} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
expect(@controller).to receive(:current_user).and_return(current_user)
|
allow(@controller).to receive(:current_user).and_return(current_user)
|
||||||
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
|
expect(@controller).to receive(:current_instructeur).and_return(current_instructeur)
|
||||||
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
|
expect(@controller).to receive(:current_administrateur).and_return(current_administrateur)
|
||||||
expect(@controller).to receive(:current_administration).and_return(current_administration)
|
expect(@controller).to receive(:current_administration).and_return(current_administration)
|
||||||
|
|
Loading…
Reference in a new issue