commit
9f3c546dc6
19 changed files with 49 additions and 64 deletions
|
@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base
|
|||
before_action :set_active_storage_host
|
||||
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
|
||||
|
||||
def staging_authenticate
|
||||
|
@ -41,10 +41,6 @@ class ApplicationController < ActionController::Base
|
|||
@left_pannel_url = service.left_panel
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
logged_user.present?
|
||||
end
|
||||
|
||||
def multiple_devise_profile_connect?
|
||||
user_signed_in? && instructeur_signed_in? ||
|
||||
instructeur_signed_in? && administrateur_signed_in? ||
|
||||
|
@ -128,23 +124,18 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def logged_users
|
||||
@logged_users ||= [
|
||||
def current_user_roles
|
||||
@current_user_roles ||= begin
|
||||
roles = [
|
||||
current_user,
|
||||
current_instructeur,
|
||||
current_administrateur,
|
||||
current_administration
|
||||
].compact
|
||||
end
|
||||
].compact.map { |role| role.class.name }
|
||||
|
||||
def logged_user
|
||||
logged_users.first
|
||||
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
|
||||
Raven.user_context(sentry_user)
|
||||
|
@ -152,13 +143,12 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def append_info_to_payload(payload)
|
||||
super
|
||||
user = logged_user
|
||||
|
||||
payload.merge!({
|
||||
user_agent: request.user_agent,
|
||||
user_id: user&.id,
|
||||
user_email: user&.email,
|
||||
user_roles: logged_user_roles
|
||||
user_id: current_user&.id,
|
||||
user_email: current_user&.email,
|
||||
user_roles: current_user_roles
|
||||
}.compact)
|
||||
|
||||
if browser.known?
|
||||
|
@ -225,8 +215,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def sentry_user
|
||||
user = logged_user
|
||||
{ id: user ? "#{user.class.name}##{user.id}" : 'Guest' }
|
||||
{ id: user_signed_in? ? "User##{current_user.id}" : 'Guest' }
|
||||
end
|
||||
|
||||
def sentry_config
|
||||
|
@ -257,14 +246,14 @@ class ApplicationController < ActionController::Base
|
|||
key: sendinblue[:client_key],
|
||||
enabled: sendinblue[:enabled],
|
||||
administrateur: {
|
||||
email: current_administrateur&.email,
|
||||
email: current_user&.email,
|
||||
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_ACTIVE: current_administrateur&.active,
|
||||
DS_ID: current_administrateur&.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],
|
||||
enabled: crisp[:enabled],
|
||||
administrateur: {
|
||||
email: current_administrateur&.email,
|
||||
DS_SIGN_IN_COUNT: current_administrateur&.sign_in_count,
|
||||
email: current_user&.email,
|
||||
DS_SIGN_IN_COUNT: current_user&.sign_in_count,
|
||||
DS_CREATED_AT: current_administrateur&.created_at,
|
||||
DS_ID: current_administrateur&.id,
|
||||
DS_NB_DEMARCHES_BROUILLONS: current_administrateur&.procedures&.brouillons&.count,
|
||||
|
@ -290,8 +279,6 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def current_email
|
||||
current_user&.email ||
|
||||
current_instructeur&.email ||
|
||||
current_administrateur&.email
|
||||
current_user&.email
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class Champs::SiretController < ApplicationController
|
|||
|
||||
def find_etablisement
|
||||
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
|
||||
end
|
||||
@procedure_id = @champ&.dossier&.procedure_id || 'aperçu'
|
||||
|
|
|
@ -6,7 +6,11 @@ module Instructeurs
|
|||
ITEMS_PER_PAGE = 25
|
||||
|
||||
def index
|
||||
@procedures = current_instructeur.visible_procedures.order(archived_at: :desc, published_at: :desc, created_at: :desc)
|
||||
@procedures = current_instructeur
|
||||
.visible_procedures
|
||||
.with_attached_logo
|
||||
.includes(:defaut_groupe_instructeur)
|
||||
.order(archived_at: :desc, published_at: :desc, created_at: :desc)
|
||||
|
||||
groupe_instructeurs = current_instructeur.groupe_instructeurs.where(procedure: @procedures)
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ module NewAdministrateur
|
|||
private
|
||||
|
||||
def service_params
|
||||
params.require(:service).permit(:nom, :organisme, :siret, :type_organisme, :email, :telephone, :horaires, :adresse)
|
||||
params.require(:service).permit(:nom, :organisme, :type_organisme, :email, :telephone, :horaires, :adresse)
|
||||
end
|
||||
|
||||
def service
|
||||
|
|
|
@ -90,6 +90,6 @@ class SupportController < ApplicationController
|
|||
end
|
||||
|
||||
def email
|
||||
logged_user ? logged_user.email : params[:email]
|
||||
current_user&.email || params[:email]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
class Administrateur < ApplicationRecord
|
||||
self.ignored_columns = ['features']
|
||||
|
||||
self.ignored_columns = ['features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
||||
include EmailSanitizableConcern
|
||||
include ActiveRecord::SecureToken
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Attestation < ApplicationRecord
|
||||
self.ignored_columns = ['pdf']
|
||||
self.ignored_columns = ['pdf', 'content_secure_token']
|
||||
|
||||
belongs_to :dossier
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AttestationTemplate < ApplicationRecord
|
||||
self.ignored_columns = ['logo', 'signature']
|
||||
self.ignored_columns = ['logo', 'signature', 'logo_secure_token', 'signature_secure_token']
|
||||
|
||||
include ActionView::Helpers::NumberHelper
|
||||
include TagsSubstitutionConcern
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Commentaire < ApplicationRecord
|
||||
self.ignored_columns = ['file']
|
||||
self.ignored_columns = ['file', 'piece_justificative_id']
|
||||
|
||||
belongs_to :dossier, inverse_of: :commentaires, touch: true
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Dossier < ApplicationRecord
|
||||
self.ignored_columns = ['json_latlngs']
|
||||
include DossierFilteringConcern
|
||||
|
||||
enum state: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Instructeur < ApplicationRecord
|
||||
self.ignored_columns = ['features']
|
||||
self.ignored_columns = ['features', 'encrypted_password', 'reset_password_token', 'reset_password_sent_at', 'remember_created_at', 'sign_in_count', 'current_sign_in_at', 'last_sign_in_at', 'current_sign_in_ip', 'last_sign_in_ip', 'failed_attempts', 'unlock_token', 'locked_at']
|
||||
include EmailSanitizableConcern
|
||||
|
||||
has_and_belongs_to_many :administrateurs
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require Rails.root.join('lib', 'percentile')
|
||||
|
||||
class Procedure < ApplicationRecord
|
||||
self.ignored_columns = ['logo']
|
||||
self.ignored_columns = ['logo', 'logo_secure_token']
|
||||
|
||||
MAX_DUREE_CONSERVATION = 36
|
||||
|
||||
|
@ -27,6 +27,8 @@ class Procedure < ApplicationRecord
|
|||
has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy
|
||||
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy
|
||||
|
||||
has_one :defaut_groupe_instructeur, -> { where(label: GroupeInstructeur::DEFAULT_LABEL) }, class_name: 'GroupeInstructeur', inverse_of: :procedure
|
||||
|
||||
has_one_attached :logo
|
||||
has_one_attached :logo_active_storage
|
||||
has_one_attached :notice
|
||||
|
@ -477,10 +479,6 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def defaut_groupe_instructeur
|
||||
groupe_instructeurs.find_by(label: GroupeInstructeur::DEFAULT_LABEL)
|
||||
end
|
||||
|
||||
def missing_instructeurs?
|
||||
!AssignTo.exists?(groupe_instructeur: groupe_instructeurs)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Service < ApplicationRecord
|
||||
self.ignored_columns = ['siret']
|
||||
has_many :procedures
|
||||
belongs_to :administrateur
|
||||
|
||||
|
@ -17,7 +18,6 @@ class Service < ApplicationRecord
|
|||
validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false
|
||||
validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' }
|
||||
validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
||||
validates :siret, length: { is: 14, message: 'doit être une suite de 14 chiffres' }, allow_nil: true
|
||||
validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
||||
validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false
|
||||
validates :telephone, presence: { message: 'doit être renseigné' }, allow_nil: false
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# - For all other dossiers, the synthetic_state and the state are the same
|
||||
class AdministrateurUsageStatisticsService
|
||||
def update_administrateurs
|
||||
Administrateur.find_each do |administrateur|
|
||||
Administrateur.includes(:user).find_each do |administrateur|
|
||||
stats = administrateur_stats(administrateur)
|
||||
api.identify(administrateur.email, stats)
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ class AdministrateurUsageStatisticsService
|
|||
nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
|
||||
|
||||
result = {
|
||||
ds_sign_in_count: administrateur.sign_in_count,
|
||||
ds_sign_in_count: administrateur.user.sign_in_count,
|
||||
ds_created_at: administrateur.created_at,
|
||||
ds_active: administrateur.active,
|
||||
ds_id: administrateur.id,
|
||||
|
@ -62,12 +62,12 @@ class AdministrateurUsageStatisticsService
|
|||
admin_roi_high: nb_dossiers_roi * 17
|
||||
}
|
||||
|
||||
if administrateur.current_sign_in_at.present?
|
||||
result[:ds_current_sign_in_at] = administrateur.current_sign_in_at
|
||||
if administrateur.user.current_sign_in_at.present?
|
||||
result[:ds_current_sign_in_at] = administrateur.user.current_sign_in_at
|
||||
end
|
||||
|
||||
if administrateur.last_sign_in_at.present?
|
||||
result[:ds_last_sign_in_at] = administrateur.last_sign_in_at
|
||||
if administrateur.user.last_sign_in_at.present?
|
||||
result[:ds_last_sign_in_at] = administrateur.user.last_sign_in_at
|
||||
end
|
||||
|
||||
result
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
\.
|
||||
|
||||
= form_tag contact_path, method: :post, class: 'form' do |f|
|
||||
- if !logged_in?
|
||||
- if !user_signed_in?
|
||||
.contact-champ
|
||||
= label_tag :email do
|
||||
Adresse email professionnelle
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
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|
|
||||
- if !logged_in?
|
||||
- if !user_signed_in?
|
||||
.contact-champ
|
||||
= label_tag :email do
|
||||
Email
|
||||
|
|
|
@ -21,7 +21,7 @@ describe ApplicationController, type: :controller do
|
|||
let(:payload) { {} }
|
||||
|
||||
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_administrateur).and_return(current_administrateur)
|
||||
expect(@controller).to receive(:current_administration).and_return(current_administration)
|
||||
|
|
|
@ -14,7 +14,6 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
service: {
|
||||
nom: 'super service',
|
||||
organisme: 'organisme',
|
||||
siret: '01234567891234',
|
||||
type_organisme: 'association',
|
||||
email: 'email@toto.com',
|
||||
telephone: '1234',
|
||||
|
@ -29,7 +28,6 @@ describe NewAdministrateur::ServicesController, type: :controller do
|
|||
it { expect(flash.notice).to eq('super service créé') }
|
||||
it { expect(Service.last.nom).to eq('super service') }
|
||||
it { expect(Service.last.organisme).to eq('organisme') }
|
||||
it { expect(Service.last.siret).to eq('01234567891234') }
|
||||
it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:association)) }
|
||||
it { expect(Service.last.email).to eq('email@toto.com') }
|
||||
it { expect(Service.last.telephone).to eq('1234') }
|
||||
|
|
|
@ -38,9 +38,7 @@ describe AdministrateurUsageStatisticsService do
|
|||
context 'for an administrateur that has plenty of things' do
|
||||
let(:administrateur) do
|
||||
create(:administrateur,
|
||||
sign_in_count: 17,
|
||||
current_sign_in_at: Time.zone.local(2019, 3, 7),
|
||||
last_sign_in_at: Time.zone.local(2019, 2, 27),
|
||||
user: create(:user, sign_in_count: 17, current_sign_in_at: Time.zone.local(2019, 3, 7), last_sign_in_at: Time.zone.local(2019, 2, 27)),
|
||||
active: true,
|
||||
services: [create(:service)],
|
||||
instructeurs: [create(:instructeur)])
|
||||
|
|
Loading…
Reference in a new issue