Merge pull request #4387 from betagouv/small_optims

Small optims
This commit is contained in:
LeSim 2019-10-08 10:06:47 +02:00 committed by GitHub
commit b1bc7a2642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -262,6 +262,12 @@ class ApplicationController < ActionController::Base
def crisp_config
crisp = Rails.application.secrets.crisp
nb_demarches_by_state = if current_administrateur.present?
current_administrateur.procedures.group(:aasm_state).count
else
{}
end
{
key: crisp[:client_key],
enabled: crisp[:enabled],
@ -270,10 +276,9 @@ class ApplicationController < ActionController::Base
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,
DS_NB_DEMARCHES_ACTIVES: current_administrateur&.procedures&.publiees&.count,
DS_NB_DEMARCHES_ARCHIVES: current_administrateur&.procedures&.archivees&.count
DS_NB_DEMARCHES_BROUILLONS: nb_demarches_by_state['brouillon'],
DS_NB_DEMARCHES_ACTIVES: nb_demarches_by_state['publiee'],
DS_NB_DEMARCHES_ARCHIVES: nb_demarches_by_state['archivee']
}
}
end

View file

@ -21,6 +21,8 @@ class User < ApplicationRecord
accepts_nested_attributes_for :france_connect_information
default_scope { eager_load(:instructeur, :administrateur) }
before_validation -> { sanitize_email(:email) }
# Callback provided by Devise