Merge pull request #8031 from demarches-simplifiees/list-all-admins

ETQ admin, je peux lister tous les administrateurs de l'ensemble des démarches filtrées.
This commit is contained in:
krichtof 2022-11-10 18:09:51 +01:00 committed by GitHub
commit 68e0abc15f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 241 additions and 161 deletions

View file

@ -1,3 +1,31 @@
#all-demarches .procedure {
cursor: pointer;
.sidebar-filter {
ul {
list-style: none;
padding-inline-start: 0;
border-top: 1px solid var(--border-plain-grey);
}
li {
border-bottom: 1px solid var(--border-plain-grey);
}
button {
font-size: 1rem;
line-height: 1.5rem;
}
legend {
width: 100%;
display: flex;
justify-content: space-between;
}
.reinit a {
background-image: none;
}
}
.main-filter-header {
display: flex;
justify-content: space-between;
}

View file

@ -1,26 +0,0 @@
.sidebar-filter {
ul {
list-style: none;
padding-inline-start: 0;
border-top: 1px solid var(--border-plain-grey);
}
li {
border-bottom: 1px solid var(--border-plain-grey);
}
button {
font-size: 1rem;
line-height: 1.5rem;
}
legend {
width: 100%;
display: flex;
justify-content: space-between;
}
.reinit a {
background-image: none;
}
}

View file

@ -1,5 +1,7 @@
module Administrateurs
class ProceduresController < AdministrateurController
layout 'all', only: [:all, :administrateurs]
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
before_action :procedure_revisable?, only: [:champs, :annotations, :modifications, :reset_draft]
before_action :draft_valid?, only: [:apercu]
@ -332,10 +334,29 @@ module Administrateurs
def all
@filter = ProceduresFilter.new(current_administrateur, params)
@procedures = paginate(filter_procedures(@filter), published_at: :desc)
end
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 = paginate(@admins, 'users.email')
end
private
def filter_procedures(filter)
procedures_result = Procedure.joins(:procedures_zones).publiees_ou_closes
procedures_result = procedures_result.where(procedures_zones: { zone_id: filter.zone_ids }) if filter.zone_ids.present?
procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present?
procedures_result = procedures_result.where('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present?
procedures_result
end
def paginate(result, ordered_by)
result.page(params[:page]).per(ITEMS_PER_PAGE).order(ordered_by)
end
def draft_valid?
if procedure_without_control.draft_revision.invalid?
flash.alert = t('preview_unavailable', scope: 'administrateurs.procedures')

View file

@ -52,13 +52,4 @@ class ProceduresFilter
params.to_h.merge(filter => new_filter)
end
end
def procedures_result
return @procedures_result if @procedures_result
@procedures_result = Procedure.joins(:procedures_zones).publiees_ou_closes
@procedures_result = @procedures_result.where(procedures_zones: { zone_id: zone_ids }) if zone_ids.present?
@procedures_result = @procedures_result.where(aasm_state: statuses) if statuses.present?
@procedures_result = @procedures_result.where('published_at >= ?', from_publication_date) if from_publication_date.present?
@procedures_result = @procedures_result.page(params[:page]).per(ITEMS_PER_PAGE).order(published_at: :desc)
end
end

View file

@ -0,0 +1,43 @@
- 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'
.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.selected_zones.present?
.selected-zones.fr-mb-2w
- @filter.selected_zones.each do |zone|
= link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.statuses.present?
.selected-statuses.fr-mb-2w
- @filter.statuses.each do |status|
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.from_publication_date.present?
.selected-from-publication-date.fr-mb-2w
= link_to "Depuis le #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
= paginate @admins, views_prefix: 'administrateurs'
%thead
%tr
%th{ scope: 'col' }
%th{ scope: 'col' } Administrateurs
%th{ scope: 'col' } Nb démarches
%th{ scope: 'col' } Inscrit le
- @admins.each do |admin|
%tbody{ 'data-controller': 'expand' }
%tr.procedure{ 'data-action': 'click->expand#toggle' }
%td
%button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
%td= admin.email
%td= admin.procedures.count
%td= l(admin.created_at, format: :message_date_without_time)
%tr.hidden{ 'data-expand-target': 'content' }
%td.fr-highlight--beige-gris-galet{ colspan: '6' }
.fr-container
.fr-col-12.fr-mr-1w
%ul
- admin.procedures.each do |procedure|
%li= procedure.libelle
.fr-mt-2w= paginate @admins, views_prefix: 'administrateurs'

View file

@ -1,112 +1,50 @@
= render 'main_menu'
.fr-container
%h1.fr-my-4w Toutes les démarches
.fr-container--fluid
.fr-grid-row.fr-grid-row--gutters
.fr-col-8
.fr-highlight.fr-mb-4w
%p Ce tableau de bord permet de consulter les informations sur les démarches simplifiées pour toutes les zones. Filtrez par zone et statut. Consultez la liste des démarches et cliquez sur une démarche pour voir la zone et quels sont les administrateurs.
.fr-container--fluid{ 'data-turbo': 'true', 'data-controller': 'autosubmit' }
.fr-grid-row.fr-grid-row--gutters
.fr-col-3
= form_with(url: all_admin_procedures_path, method: :get, html: {'data-autosubmit-target': 'form'}) do |f|
%fieldset.sidebar-filter
%legend
.title.font-weight-bold.fr-pl-2w
%span.fr-icon-filter-fill.fr-icon--sm.fr-mr-1w{ 'aria-hidden': 'true' }
Filtrer
.reinit
= link_to all_admin_procedures_path(zone_ids: current_administrateur.zones) do
%span.fr-icon-arrow-go-back-line Réinitialiser
%ul
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Mes zones
.fr-ml-1w{ 'data-expand-target': 'content' }
= f.collection_check_boxes :zone_ids, @filter.admin_zones, :id, :current_label, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.zone_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { b.text }
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Autres zones
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
= f.collection_check_boxes :zone_ids, @filter.other_zones, :id, :current_label, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.zone_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { b.text }
%li.fr-py-2w{ 'data-controller': "expand" }
.fr-mb-1w.fr-pl-2w
%button{ 'data-action': 'click->expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Date de publication
.fr-input-group.hidden{ 'data-expand-target': 'content' }
= f.label 'from_publication_date', 'Depuis', class: 'fr-label'
.fr-input-wrap.fr-fi-calendar-line
= f.date_field 'from_publication_date', value: @filter.from_publication_date, class: 'fr-input', 'data-action': 'blur->autosubmit#submit change->autosubmit#debouncedSubmit'
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Statut
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
= f.collection_check_boxes :statuses, ['publiee', 'close'], :to_s, :to_s, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.status_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' }
.fr-col-9
.fr-table.fr-table--bordered
%table#all-demarches
%caption
= "#{@filter.procedures_result.total_count} démarches"
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
- if @filter.selected_zones.present?
.selected-zones.fr-mb-2w
- @filter.selected_zones.each do |zone|
= link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.statuses.present?
.selected-statuses.fr-mb-2w
- @filter.statuses.each do |status|
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.from_publication_date.present?
.selected-from-publication-date.fr-mb-2w
= link_to "Depuis le #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
= paginate @filter.procedures_result, views_prefix: 'administrateurs'
%thead
%tr
%th{ scope: 'col' }
%th{ scope: 'col' } Démarche
%th{ scope: 'col' } N°
%th{ scope: 'col' } Administrateurs
%th{ scope: 'col' } Statut
%th{ scope: 'col' } Date
- @filter.procedures_result.each do |procedure|
%tbody{ 'data-controller': 'expand' }
%tr.procedure{ 'data-action': 'click->expand#toggle' }
%td
%button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
%td= procedure.libelle
%td= procedure.id
%td= procedure.administrateurs.count
%td= t procedure.aasm_state, scope: 'activerecord.attributes.procedure.aasm_state'
%td= l(procedure.published_at, format: :message_date_without_time)
%tr.hidden{ 'data-expand-target': 'content' }
%td.fr-highlight--beige-gris-galet{ colspan: '6' }
.fr-container
.fr-grid-row
.fr-col-6
- procedure.zones.uniq.each do |zone|
= zone.label_at(procedure.published_or_created_at)
.fr-col-6
- procedure.administrateurs.uniq.each do |admin|
= admin.email
.fr-mt-2w= paginate @filter.procedures_result, views_prefix: 'administrateurs'
- content_for :results do
.main-filter-header.fr-my-3w
.search
= link_to 'Voir la liste des administrateurs', administrateurs_admin_procedures_path(@filter.params), class: 'fr-btn fr-btn--secondary btn-admins'
.fr-table.fr-table--bordered
%table#all-demarches
%caption
= "#{@procedures.total_count} démarches"
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
- if @filter.selected_zones.present?
.selected-zones.fr-mb-2w
- @filter.selected_zones.each do |zone|
= link_to zone.current_label, all_admin_procedures_path(@filter.without(:zone_ids, zone.id)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.statuses.present?
.selected-statuses.fr-mb-2w
- @filter.statuses.each do |status|
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.from_publication_date.present?
.selected-from-publication-date.fr-mb-2w
= link_to "Depuis #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
= paginate @procedures, views_prefix: 'administrateurs'
%thead
%tr
%th{ scope: 'col' }
%th{ scope: 'col' } Démarche
%th{ scope: 'col' } N°
%th{ scope: 'col' } Administrateurs
%th{ scope: 'col' } Statut
%th{ scope: 'col' } Date
- @procedures.each do |procedure|
%tbody{ 'data-controller': 'expand' }
%tr.procedure{ 'data-action': 'click->expand#toggle' }
%td
%button.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-mb-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
%td= procedure.libelle
%td= procedure.id
%td= procedure.administrateurs.count
%td= t procedure.aasm_state, scope: 'activerecord.attributes.procedure.aasm_state'
%td= l(procedure.published_at, format: :message_date_without_time)
%tr.hidden{ 'data-expand-target': 'content' }
%td.fr-highlight--beige-gris-galet{ colspan: '6' }
.fr-container
.fr-grid-row
.fr-col-6
- procedure.zones.uniq.each do |zone|
= zone.label_at(procedure.published_or_created_at)
.fr-col-6
- procedure.administrateurs.uniq.each do |admin|
= admin.email
.fr-mt-2w= paginate @procedures, views_prefix: 'administrateurs'

View file

@ -0,0 +1,68 @@
= render 'main_menu'
.fr-container
%h1.fr-my-4w Toutes les démarches
.fr-container--fluid
.fr-grid-row.fr-grid-row--gutters
.fr-col-8
.fr-highlight.fr-mb-4w
%p Ce tableau de bord permet de consulter les informations sur les démarches simplifiées pour toutes les zones. Filtrez par zone et statut. Consultez la liste des démarches et cliquez sur une démarche pour voir la zone et quels sont les administrateurs.
.fr-container--fluid{ 'data-turbo': 'true', 'data-controller': 'autosubmit' }
.fr-grid-row.fr-grid-row--gutters
.fr-col-3
= form_with(url: all_admin_procedures_path, method: :get, html: {'data-autosubmit-target': 'form'}) do |f|
%fieldset.sidebar-filter
%legend
.title.font-weight-bold.fr-pl-2w
%span.fr-icon-filter-fill.fr-icon--sm.fr-mr-1w{ 'aria-hidden': 'true' }
Filtrer
.reinit
= link_to all_admin_procedures_path(zone_ids: current_administrateur.zones) do
%span.fr-icon-arrow-go-back-line Réinitialiser
%ul
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Mes zones
.fr-ml-1w{ 'data-expand-target': 'content' }
= f.collection_check_boxes :zone_ids, @filter.admin_zones, :id, :current_label, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.zone_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { b.text }
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Autres zones
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
= f.collection_check_boxes :zone_ids, @filter.other_zones, :id, :current_label, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.zone_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { b.text }
%li.fr-py-2w{ 'data-controller': "expand" }
.fr-mb-1w.fr-pl-2w
%button{ 'data-action': 'click->expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Date de publication
.fr-input-group.hidden{ 'data-expand-target': 'content' }
= f.label 'from_publication_date', 'Depuis', class: 'fr-label'
.fr-input-wrap.fr-fi-calendar-line
= f.date_field 'from_publication_date', value: @filter.from_publication_date, class: 'fr-input', 'data-action': 'blur->autosubmit#submit change->autosubmit#debouncedSubmit'
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
.fr-mb-1w
%button{ 'data-action': 'expand#toggle' }
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
Statut
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
= f.collection_check_boxes :statuses, ['publiee', 'close'], :to_s, :to_s, include_hidden: false do |b|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= b.check_box(checked: @filter.status_filtered?(b.value), 'data-action': 'autosubmit#submit')
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' }
.fr-col-9
= yield(:results)
= render template: 'layouts/application'

View file

@ -434,6 +434,7 @@ Rails.application.routes.draw do
get 'new_from_existing'
post 'search'
get 'all'
get 'administrateurs'
end
member do

View file

@ -97,13 +97,13 @@ describe Administrateurs::ProceduresController, type: :controller do
it 'display published or closed procedures' do
subject
expect(assigns(:filter).procedures_result).to include(published_procedure)
expect(assigns(:filter).procedures_result).to include(closed_procedure)
expect(assigns(:procedures)).to include(published_procedure)
expect(assigns(:procedures)).to include(closed_procedure)
end
it 'doesnt display draft procedures' do
subject
expect(assigns(:filter).procedures_result).not_to include(draft_procedure)
expect(assigns(:procedures)).not_to include(draft_procedure)
end
context "for specific zones" do
@ -116,8 +116,8 @@ describe Administrateurs::ProceduresController, type: :controller do
it 'display only procedures for specified zones' do
subject
expect(assigns(:filter).procedures_result).to include(procedure2)
expect(assigns(:filter).procedures_result).not_to include(procedure1)
expect(assigns(:procedures)).to include(procedure2)
expect(assigns(:procedures)).not_to include(procedure1)
end
end
@ -127,14 +127,14 @@ describe Administrateurs::ProceduresController, type: :controller do
it 'display only published procedures' do
get :all, params: { statuses: ['publiee'] }
expect(assigns(:filter).procedures_result).to include(procedure1)
expect(assigns(:filter).procedures_result).not_to include(procedure2)
expect(assigns(:procedures)).to include(procedure1)
expect(assigns(:procedures)).not_to include(procedure2)
end
it 'display only closed procedures' do
get :all, params: { statuses: ['close'] }
expect(assigns(:filter).procedures_result).to include(procedure2)
expect(assigns(:filter).procedures_result).not_to include(procedure1)
expect(assigns(:procedures)).to include(procedure2)
expect(assigns(:procedures)).not_to include(procedure1)
end
end
@ -146,13 +146,29 @@ describe Administrateurs::ProceduresController, type: :controller do
it 'display only procedures published after specific date' do
get :all, params: { from_publication_date: after }
expect(assigns(:filter).procedures_result).to include(procedure1)
expect(assigns(:filter).procedures_result).to include(procedure2)
expect(assigns(:filter).procedures_result).not_to include(procedure3)
expect(assigns(:procedures)).to include(procedure1)
expect(assigns(:procedures)).to include(procedure2)
expect(assigns(:procedures)).not_to include(procedure3)
end
end
end
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) }
it 'displays admins of the procedures' do
get :administrateurs
expect(assigns(:admins)).to include(admin1)
expect(assigns(:admins)).to include(admin2)
expect(assigns(:admins)).not_to include(admin3)
end
end
describe 'POST #search' do
before do
stub_const("Administrateurs::ProceduresController::SIGNIFICANT_DOSSIERS_THRESHOLD", 2)