Merge pull request #4333 from betagouv/dev

2019-09-17-01
This commit is contained in:
Paul Chavard 2019-09-17 13:44:24 +02:00 committed by GitHub
commit 9f3c546dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 49 additions and 64 deletions

View file

@ -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,23 +124,18 @@ class ApplicationController < ActionController::Base
end end
end end
def logged_users def current_user_roles
@logged_users ||= [ @current_user_roles ||= begin
roles = [
current_user, current_user,
current_instructeur, current_instructeur,
current_administrateur, current_administrateur,
current_administration current_administration
].compact ].compact.map { |role| role.class.name }
end
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' roles.any? ? roles.join(', ') : 'Guest'
end end
end
def set_raven_context def set_raven_context
Raven.user_context(sentry_user) Raven.user_context(sentry_user)
@ -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

View file

@ -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'

View file

@ -6,7 +6,11 @@ module Instructeurs
ITEMS_PER_PAGE = 25 ITEMS_PER_PAGE = 25
def index 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) groupe_instructeurs = current_instructeur.groupe_instructeurs.where(procedure: @procedures)

View file

@ -73,7 +73,7 @@ module NewAdministrateur
private private
def service_params 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 end
def service def service

View file

@ -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

View file

@ -1,6 +1,5 @@
class Administrateur < ApplicationRecord 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 EmailSanitizableConcern
include ActiveRecord::SecureToken include ActiveRecord::SecureToken

View file

@ -1,5 +1,5 @@
class Attestation < ApplicationRecord class Attestation < ApplicationRecord
self.ignored_columns = ['pdf'] self.ignored_columns = ['pdf', 'content_secure_token']
belongs_to :dossier belongs_to :dossier

View file

@ -1,5 +1,5 @@
class AttestationTemplate < ApplicationRecord class AttestationTemplate < ApplicationRecord
self.ignored_columns = ['logo', 'signature'] self.ignored_columns = ['logo', 'signature', 'logo_secure_token', 'signature_secure_token']
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
include TagsSubstitutionConcern include TagsSubstitutionConcern

View file

@ -1,5 +1,5 @@
class Commentaire < ApplicationRecord class Commentaire < ApplicationRecord
self.ignored_columns = ['file'] self.ignored_columns = ['file', 'piece_justificative_id']
belongs_to :dossier, inverse_of: :commentaires, touch: true belongs_to :dossier, inverse_of: :commentaires, touch: true

View file

@ -1,4 +1,5 @@
class Dossier < ApplicationRecord class Dossier < ApplicationRecord
self.ignored_columns = ['json_latlngs']
include DossierFilteringConcern include DossierFilteringConcern
enum state: { enum state: {

View file

@ -1,5 +1,5 @@
class Instructeur < ApplicationRecord 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 include EmailSanitizableConcern
has_and_belongs_to_many :administrateurs has_and_belongs_to_many :administrateurs

View file

@ -1,7 +1,7 @@
require Rails.root.join('lib', 'percentile') require Rails.root.join('lib', 'percentile')
class Procedure < ApplicationRecord class Procedure < ApplicationRecord
self.ignored_columns = ['logo'] self.ignored_columns = ['logo', 'logo_secure_token']
MAX_DUREE_CONSERVATION = 36 MAX_DUREE_CONSERVATION = 36
@ -27,6 +27,8 @@ class Procedure < ApplicationRecord
has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", 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
has_one_attached :logo_active_storage has_one_attached :logo_active_storage
has_one_attached :notice has_one_attached :notice
@ -477,10 +479,6 @@ class Procedure < ApplicationRecord
end end
end end
def defaut_groupe_instructeur
groupe_instructeurs.find_by(label: GroupeInstructeur::DEFAULT_LABEL)
end
def missing_instructeurs? def missing_instructeurs?
!AssignTo.exists?(groupe_instructeur: groupe_instructeurs) !AssignTo.exists?(groupe_instructeur: groupe_instructeurs)
end end

View file

@ -1,4 +1,5 @@
class Service < ApplicationRecord class Service < ApplicationRecord
self.ignored_columns = ['siret']
has_many :procedures has_many :procedures
belongs_to :administrateur belongs_to :administrateur
@ -17,7 +18,6 @@ class Service < ApplicationRecord
validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' } validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' }
validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false 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 :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
validates :email, 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 validates :telephone, presence: { message: 'doit être renseigné' }, allow_nil: false

View file

@ -8,7 +8,7 @@
# - For all other dossiers, the synthetic_state and the state are the same # - For all other dossiers, the synthetic_state and the state are the same
class AdministrateurUsageStatisticsService class AdministrateurUsageStatisticsService
def update_administrateurs def update_administrateurs
Administrateur.find_each do |administrateur| Administrateur.includes(:user).find_each do |administrateur|
stats = administrateur_stats(administrateur) stats = administrateur_stats(administrateur)
api.identify(administrateur.email, stats) api.identify(administrateur.email, stats)
end 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 nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
result = { 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_created_at: administrateur.created_at,
ds_active: administrateur.active, ds_active: administrateur.active,
ds_id: administrateur.id, ds_id: administrateur.id,
@ -62,12 +62,12 @@ class AdministrateurUsageStatisticsService
admin_roi_high: nb_dossiers_roi * 17 admin_roi_high: nb_dossiers_roi * 17
} }
if administrateur.current_sign_in_at.present? if administrateur.user.current_sign_in_at.present?
result[:ds_current_sign_in_at] = administrateur.current_sign_in_at result[:ds_current_sign_in_at] = administrateur.user.current_sign_in_at
end end
if administrateur.last_sign_in_at.present? if administrateur.user.last_sign_in_at.present?
result[:ds_last_sign_in_at] = administrateur.last_sign_in_at result[:ds_last_sign_in_at] = administrateur.user.last_sign_in_at
end end
result result

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -14,7 +14,6 @@ describe NewAdministrateur::ServicesController, type: :controller do
service: { service: {
nom: 'super service', nom: 'super service',
organisme: 'organisme', organisme: 'organisme',
siret: '01234567891234',
type_organisme: 'association', type_organisme: 'association',
email: 'email@toto.com', email: 'email@toto.com',
telephone: '1234', telephone: '1234',
@ -29,7 +28,6 @@ describe NewAdministrateur::ServicesController, type: :controller do
it { expect(flash.notice).to eq('super service créé') } it { expect(flash.notice).to eq('super service créé') }
it { expect(Service.last.nom).to eq('super service') } it { expect(Service.last.nom).to eq('super service') }
it { expect(Service.last.organisme).to eq('organisme') } 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.type_organisme).to eq(Service.type_organismes.fetch(:association)) }
it { expect(Service.last.email).to eq('email@toto.com') } it { expect(Service.last.email).to eq('email@toto.com') }
it { expect(Service.last.telephone).to eq('1234') } it { expect(Service.last.telephone).to eq('1234') }

View file

@ -38,9 +38,7 @@ describe AdministrateurUsageStatisticsService do
context 'for an administrateur that has plenty of things' do context 'for an administrateur that has plenty of things' do
let(:administrateur) do let(:administrateur) do
create(:administrateur, create(:administrateur,
sign_in_count: 17, 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)),
current_sign_in_at: Time.zone.local(2019, 3, 7),
last_sign_in_at: Time.zone.local(2019, 2, 27),
active: true, active: true,
services: [create(:service)], services: [create(:service)],
instructeurs: [create(:instructeur)]) instructeurs: [create(:instructeur)])