admin: replace calls to Administrateur.find_by(email: ...)
This commit is contained in:
parent
e72233fced
commit
055918aabc
7 changed files with 11 additions and 8 deletions
|
@ -79,7 +79,7 @@ class Admin::ProceduresController < AdminController
|
|||
end
|
||||
|
||||
def transfer
|
||||
admin = Administrateur.find_by(email: params[:email_admin].downcase)
|
||||
admin = Administrateur.by_email(params[:email_admin].downcase)
|
||||
|
||||
if admin.nil?
|
||||
render '/admin/procedures/transfer', formats: 'js', status: 404
|
||||
|
|
|
@ -48,8 +48,8 @@ module Manager
|
|||
end
|
||||
|
||||
def pending_demandes
|
||||
already_approved_emails = Administrateur
|
||||
.where(email: demandes.map { |d| d[:email] })
|
||||
already_approved_emails = Administrateur.eager(:user)
|
||||
.where(users: { email: demandes.map { |d| d[:email] } })
|
||||
.pluck(:email)
|
||||
|
||||
demandes.reject { |demande| already_approved_emails.include?(demande[:email]) }
|
||||
|
|
|
@ -29,7 +29,7 @@ module Manager
|
|||
end
|
||||
|
||||
def add_administrateur
|
||||
administrateur = Administrateur.find_by(email: params[:email])
|
||||
administrateur = Administrateur.by_email(params[:email])
|
||||
if administrateur
|
||||
procedure.administrateurs << administrateur
|
||||
flash[:notice] = "L'administrateur \"#{params[:email]}\" est ajouté à la démarche."
|
||||
|
|
|
@ -9,7 +9,7 @@ module NewAdministrateur
|
|||
email = params.require(:administrateur)[:email]&.strip&.downcase
|
||||
|
||||
# Find the admin
|
||||
administrateur = Administrateur.find_by(email: email)
|
||||
administrateur = Administrateur.by_email(email)
|
||||
if administrateur.nil?
|
||||
flash.alert = "L’administrateur « #{email} » n’existe pas. Invitez-le à demander un compte administrateur à l’addresse <a href=#{new_demande_url}>#{new_demande_url}</a>."
|
||||
return
|
||||
|
|
|
@ -11,7 +11,7 @@ class Users::PasswordsController < Devise::PasswordsController
|
|||
def create
|
||||
# Check the credentials associated to the mail to generate a correct reset link
|
||||
email = params[:user][:email]
|
||||
if Administrateur.find_by(email: email)
|
||||
if Administrateur.by_email(email)
|
||||
@devise_mapping = Devise.mappings[:administrateur]
|
||||
params[:administrateur] = params[:user]
|
||||
# uncomment to check password complexity for Instructeur
|
||||
|
@ -56,7 +56,7 @@ class Users::PasswordsController < Devise::PasswordsController
|
|||
|
||||
def try_to_authenticate_administrateur
|
||||
if user_signed_in?
|
||||
administrateur = Administrateur.find_by(email: current_user.email)
|
||||
administrateur = Administrateur.by_email(current_user.email)
|
||||
|
||||
if administrateur
|
||||
sign_in(administrateur.user)
|
||||
|
|
|
@ -15,6 +15,9 @@ class Administrateur < ApplicationRecord
|
|||
scope :inactive, -> { joins(:user).where(users: { last_sign_in_at: nil }) }
|
||||
scope :with_publiees_ou_closes, -> { joins(:procedures).where(procedures: { aasm_state: [:publiee, :close, :depubliee] }) }
|
||||
|
||||
def self.by_email(email)
|
||||
Administrateur.eager_load(:user).find_by(users: { email: email })
|
||||
end
|
||||
# validate :password_complexity, if: Proc.new { |a| Devise.password_length.include?(a.password.try(:size)) }
|
||||
|
||||
def password_complexity
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
feature 'As an administrateur', js: true do
|
||||
let(:administration) { create(:administration) }
|
||||
let(:admin_email) { 'new_admin@gouv.fr' }
|
||||
let(:new_admin) { Administrateur.find_by(email: admin_email) }
|
||||
let(:new_admin) { Administrateur.by_email(admin_email) }
|
||||
|
||||
before do
|
||||
perform_enqueued_jobs do
|
||||
|
|
Loading…
Reference in a new issue