search admins by email
This commit is contained in:
parent
7db5c35850
commit
3539b00652
4 changed files with 36 additions and 7 deletions
|
@ -340,6 +340,7 @@ module Administrateurs
|
|||
def administrateurs
|
||||
@filter = ProceduresFilter.new(current_administrateur, params)
|
||||
@admins = Administrateur.includes(:user, :procedures).where(id: AdministrateursProcedure.where(procedure: filter_procedures(@filter)).select(:administrateur_id))
|
||||
@admins = @admins.where('unaccent(users.email) ILIKE unaccent(?)', "%#{@filter.email}%") if @filter.email.present?
|
||||
@admins = paginate(@admins, 'users.email')
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class ProceduresFilter
|
|||
|
||||
def initialize(admin, params)
|
||||
@admin = admin
|
||||
@params = params.permit(:page, :libelle, :from_publication_date, zone_ids: [], statuses: [])
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, zone_ids: [], statuses: [])
|
||||
end
|
||||
|
||||
def admin_zones
|
||||
|
@ -40,6 +40,10 @@ class ProceduresFilter
|
|||
ActiveRecord::Base.sanitize_sql_like(params[:libelle]) if params[:libelle].present?
|
||||
end
|
||||
|
||||
def email
|
||||
ActiveRecord::Base.sanitize_sql_like(params[:email]) if params[:email].present?
|
||||
end
|
||||
|
||||
def zone_filtered?(zone_id)
|
||||
zone_ids&.map(&:to_i)&.include?(zone_id)
|
||||
end
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
- content_for :results do
|
||||
.main-filter-header.fr-my-3w
|
||||
.search
|
||||
= link_to 'Voir la liste des démarches', all_admin_procedures_path(@filter.params), class: 'fr-btn fr-btn--secondary btn-admins'
|
||||
= form_with(url: administrateurs_admin_procedures_path, method: :get, html: {'data-autosubmit-target': 'form', role: 'search' }) do |f|
|
||||
- @filter.zone_ids&.each do |zone_id|
|
||||
= hidden_field_tag 'zone_ids[]', zone_id
|
||||
- @filter.statuses&.each do |status|
|
||||
= hidden_field_tag 'statuses[]', status
|
||||
= hidden_field_tag 'from_publication_date', @filter.from_publication_date if @filter.from_publication_date.present?
|
||||
|
||||
= f.label 'email', 'Recercher des administrateurs par email', class: 'fr-label'
|
||||
= f.search_field 'email', size: 40, class: 'fr-input'
|
||||
.switch= link_to 'Voir la liste des démarches', all_admin_procedures_path(@filter.params), class: 'fr-btn fr-btn--secondary'
|
||||
.fr-table.fr-table--bordered
|
||||
%table#all-admins
|
||||
%caption
|
||||
= "#{@admins.total_count} administrateurs"
|
||||
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
|
||||
- if @filter.email
|
||||
.selected-email.fr-mb-2w
|
||||
= link_to @filter.email, administrateurs_admin_procedures_path(@filter.without(:email)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||
- if @filter.selected_zones.present?
|
||||
.selected-zones.fr-mb-2w
|
||||
- @filter.selected_zones.each do |zone|
|
||||
|
|
|
@ -169,17 +169,30 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
describe 'GET #administrateurs' do
|
||||
let!(:draft_procedure) { create(:procedure, administrateur: admin3) }
|
||||
let!(:published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2, administrateur: admin1) }
|
||||
let!(:closed_procedure) { create(:procedure, :closed, administrateur: admin2) }
|
||||
let(:admin1) { create(:administrateur) }
|
||||
let(:admin2) { create(:administrateur) }
|
||||
let(:admin3) { create(:administrateur) }
|
||||
let!(:antoher_published_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2, administrateur: admin4) }
|
||||
let!(:closed_procedure) { create(:procedure, :closed, administrateur: admin2) }
|
||||
let(:admin1) { create(:administrateur, email: 'jesuis.surmene@education.gouv.fr') }
|
||||
let(:admin2) { create(:administrateur, email: 'jesuis.alecoute@social.gouv.fr') }
|
||||
let(:admin3) { create(:administrateur, email: 'gerard.lambert@interieur.gouv.fr') }
|
||||
let(:admin4) { create(:administrateur, email: 'jack.lang@culture.gouv.fr') }
|
||||
|
||||
it 'displays admins of the procedures' do
|
||||
get :administrateurs
|
||||
expect(assigns(:admins)).to include(admin1)
|
||||
expect(assigns(:admins)).to include(admin2)
|
||||
expect(assigns(:admins)).to include(admin4)
|
||||
expect(assigns(:admins)).not_to include(admin3)
|
||||
end
|
||||
|
||||
context 'with email search' do
|
||||
it 'returns procedures with specific terms in libelle' do
|
||||
get :administrateurs, params: { email: 'jesuis' }
|
||||
expect(assigns(:admins)).to include(admin1)
|
||||
expect(assigns(:admins)).to include(admin2)
|
||||
expect(assigns(:admins)).not_to include(admin3)
|
||||
expect(assigns(:admins)).not_to include(admin4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #search' do
|
||||
|
|
Loading…
Reference in a new issue