feat(procedure): hide as template
This commit is contained in:
parent
a4b8ad8f3c
commit
0d2cd0fe5d
14 changed files with 120 additions and 8 deletions
|
@ -79,6 +79,7 @@ module Administrateurs
|
|||
|
||||
significant_procedure_ids = Procedure
|
||||
.publiees_ou_closes
|
||||
.where(hidden_at_as_template: nil)
|
||||
.where('unaccent(libelle) ILIKE unaccent(?)', "%#{query}%")
|
||||
.joins(:dossiers)
|
||||
.group("procedures.id")
|
||||
|
@ -384,6 +385,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def all
|
||||
params[:hidden_at_as_template] = nil
|
||||
@filter = ProceduresFilter.new(current_administrateur, params)
|
||||
all_procedures = filter_procedures(@filter).map { |p| ProcedureDetail.new(p) }
|
||||
|
||||
|
@ -400,9 +402,10 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def administrateurs
|
||||
params[:hidden_at_as_template] = nil
|
||||
@filter = ProceduresFilter.new(current_administrateur, params)
|
||||
pids = AdministrateursProcedure.select(:administrateur_id).where(procedure: filter_procedures(@filter).map { |p| p["id"] })
|
||||
@admins = Administrateur.includes(:user, :procedures).where(id: pids)
|
||||
@admins = Administrateur.includes(:user, :procedures).where(id: pids, procedures: { hidden_at_as_template: nil })
|
||||
@admins = @admins.where('unaccent(users.email) ILIKE unaccent(?)', "%#{@filter.email}%") if @filter.email.present?
|
||||
@admins = paginate(@admins, 'users.email')
|
||||
end
|
||||
|
@ -417,6 +420,7 @@ module Administrateurs
|
|||
|
||||
procedures_result = Procedure.select(:id).left_joins(:procedures_zones).distinct.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(hidden_at_as_template: nil) if filter.only_not_hidden_as_template?
|
||||
procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present?
|
||||
procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.present?
|
||||
procedures_result = procedures_result.where('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present?
|
||||
|
|
|
@ -27,6 +27,18 @@ module Manager
|
|||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def hide_as_template
|
||||
procedure.hide_as_template!
|
||||
flash[:notice] = "Démarche non visible dans les modèles."
|
||||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def unhide_as_template
|
||||
procedure.unhide_as_template!
|
||||
flash[:notice] = "Démarche visible dans les modèles."
|
||||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
|
||||
def discard
|
||||
procedure.discard_and_keep_track!(current_super_admin)
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@ class DubiousProcedureDashboard < Administrate::BaseDashboard
|
|||
id: Field::Number,
|
||||
libelle: Field::String,
|
||||
dubious_champs: Field::String,
|
||||
aasm_state: Field::String
|
||||
aasm_state: Field::String,
|
||||
hidden_at_as_template: Field::DateTime.with_options(format: "%d/%m/%Y")
|
||||
}.freeze
|
||||
COLLECTION_ATTRIBUTES = [:id, :libelle, :dubious_champs, :aasm_state].freeze
|
||||
COLLECTION_ATTRIBUTES = [:id, :libelle, :dubious_champs, :aasm_state, :hidden_at_as_template].freeze
|
||||
COLLECTION_FILTERS = {}.freeze
|
||||
end
|
||||
|
|
|
@ -29,6 +29,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
|
|||
hidden_at: Field::DateTime,
|
||||
closed_at: Field::DateTime,
|
||||
whitelisted_at: Field::DateTime,
|
||||
hidden_at_as_template: Field::DateTime,
|
||||
service: Field::BelongsTo,
|
||||
initiated_mail_template: MailTemplateField,
|
||||
received_mail_template: MailTemplateField,
|
||||
|
@ -80,6 +81,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
|
|||
:published_at,
|
||||
:whitelisted_at,
|
||||
:hidden_at,
|
||||
:hidden_at_as_template,
|
||||
:closed_at,
|
||||
:unpublished_at,
|
||||
:published_types_de_champ_public,
|
||||
|
|
|
@ -2,7 +2,7 @@ class DubiousProcedure
|
|||
extend ActiveModel::Naming
|
||||
extend ActiveModel::Translation
|
||||
|
||||
attr_accessor :id, :libelle, :dubious_champs, :aasm_state
|
||||
attr_accessor :id, :libelle, :dubious_champs, :aasm_state, :hidden_at_as_template
|
||||
|
||||
FORBIDDEN_KEYWORDS = [
|
||||
'NIR', 'RNIPP', 'race', 'religion', 'RIB',
|
||||
|
@ -19,7 +19,7 @@ class DubiousProcedure
|
|||
def self.all
|
||||
procedures_with_forbidden_tdcs_sql = TypeDeChamp
|
||||
.joins(:procedure)
|
||||
.select("string_agg(types_de_champ.libelle, ' - ') as dubious_champs, procedures.id as procedure_id, procedures.libelle as procedure_libelle, procedures.aasm_state as procedure_aasm_state")
|
||||
.select("string_agg(types_de_champ.libelle, ' - ') as dubious_champs, procedures.id as procedure_id, procedures.libelle as procedure_libelle, procedures.aasm_state as procedure_aasm_state, procedures.hidden_at_as_template as procedure_hidden_at_as_template")
|
||||
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", forbidden_regexp)
|
||||
.where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)])
|
||||
.where(procedures: { closed_at: nil, whitelisted_at: nil })
|
||||
|
@ -33,6 +33,7 @@ class DubiousProcedure
|
|||
p.dubious_champs = procedure["dubious_champs"]
|
||||
p.libelle = procedure["procedure_libelle"]
|
||||
p.aasm_state = procedure["procedure_aasm_state"]
|
||||
p.hidden_at_as_template = procedure["procedure_hidden_at_as_template"]
|
||||
p
|
||||
end
|
||||
end
|
||||
|
|
|
@ -604,6 +604,19 @@ class Procedure < ApplicationRecord
|
|||
whitelisted_at.present?
|
||||
end
|
||||
|
||||
def hidden_as_template?
|
||||
hidden_at_as_template.present?
|
||||
end
|
||||
|
||||
def hide_as_template!
|
||||
touch(:hidden_at_as_template)
|
||||
end
|
||||
|
||||
def unhide_as_template!
|
||||
self.hidden_at_as_template = nil
|
||||
save
|
||||
end
|
||||
|
||||
def total_dossier
|
||||
self.dossiers.state_not_brouillon.size
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class ProceduresFilter
|
|||
|
||||
def initialize(admin, params)
|
||||
@admin = admin
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, tags: [], zone_ids: [], statuses: [])
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :hidden_at_as_template, :service_siret, tags: [], zone_ids: [], statuses: [])
|
||||
end
|
||||
|
||||
def admin_zones
|
||||
|
@ -36,6 +36,10 @@ class ProceduresFilter
|
|||
params[:service_siret].presence
|
||||
end
|
||||
|
||||
def only_not_hidden_as_template?
|
||||
params.key?(:hidden_at_as_template) && params[:hidden_at_as_template].nil?
|
||||
end
|
||||
|
||||
def from_publication_date
|
||||
return if params[:from_publication_date].blank?
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
%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= admin.procedures.size
|
||||
%td= l(admin.created_at, format: :message_date_without_time)
|
||||
%tr.hidden{ 'data-expand-target': 'content' }
|
||||
%td.fr-highlight--beige-gris-galet{ colspan: '6' }
|
||||
|
|
|
@ -41,6 +41,12 @@ as well as a link to its edit page.
|
|||
<%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %>
|
||||
<% end %>
|
||||
|
||||
<% if procedure.hidden_as_template? %>
|
||||
<%= link_to 'autoriser l\'affichage dans les modèles', unhide_as_template_manager_procedure_path(procedure), method: :post, class: 'button' %>
|
||||
<% else %>
|
||||
<%= link_to 'masquer l\'affichage dans les modèles', hide_as_template_manager_procedure_path(procedure), method: :post, class: 'button' %>
|
||||
<% end %>
|
||||
|
||||
<% if procedure.can_be_deleted_by_manager? %>
|
||||
<%= link_to 'Supprimer la démarche', discard_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
|
||||
<% elsif procedure.discarded? %>
|
||||
|
|
|
@ -12,6 +12,8 @@ Rails.application.routes.draw do
|
|||
namespace :manager do
|
||||
resources :procedures, only: [:index, :show, :edit, :update] do
|
||||
post 'whitelist', on: :member
|
||||
post 'hide_as_template', on: :member
|
||||
post 'unhide_as_template', on: :member
|
||||
post 'draft', on: :member
|
||||
post 'discard', on: :member
|
||||
post 'restore', on: :member
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddHiddenAtAsTemplateToProcedure < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :procedures, :hidden_at_as_template, :datetime
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_07_18_113920) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_08_14_091648) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -754,6 +754,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_18_113920) do
|
|||
t.boolean "experts_require_administrateur_invitation", default: false
|
||||
t.boolean "for_individual", default: false
|
||||
t.datetime "hidden_at", precision: 6
|
||||
t.datetime "hidden_at_as_template", precision: 6
|
||||
t.boolean "instructeurs_self_management_enabled"
|
||||
t.boolean "juridique_required", default: true
|
||||
t.string "libelle"
|
||||
|
|
|
@ -172,6 +172,19 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'only_not_hidden_as_template' do
|
||||
let!(:procedure1) { create(:procedure, :published) }
|
||||
let!(:procedure2) { create(:procedure, :published, hidden_at_as_template: Time.zone.now) }
|
||||
let!(:procedure3) { create(:procedure, :published) }
|
||||
|
||||
it 'display only procedures which are not hidden as template' do
|
||||
get :all
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure1.id }).to be_truthy
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_falsey
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure3.id }).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'with specific service' do
|
||||
let(:requested_siret) { '13001501900024' }
|
||||
let(:another_siret) { '11000004900012' }
|
||||
|
@ -233,6 +246,7 @@ 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!(:antoher_published_procedure_for_admin1) { create(:procedure_with_dossiers, :published, dossiers_count: 2, administrateur: admin1) }
|
||||
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') }
|
||||
|
@ -257,6 +271,24 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
expect(assigns(:admins)).not_to include(admin4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'only_not_hidden_as_template' do
|
||||
before do
|
||||
published_procedure.update(hidden_at_as_template: Time.zone.now)
|
||||
closed_procedure.update(hidden_at_as_template: Time.zone.now)
|
||||
antoher_published_procedure.update(hidden_at_as_template: Time.zone.now)
|
||||
end
|
||||
|
||||
it 'displays admins of the procedures' do
|
||||
get :administrateurs
|
||||
expect(assigns(:admins)).to include(admin1)
|
||||
expect(assigns(:admins)).not_to include(admin2)
|
||||
expect(assigns(:admins)).not_to include(admin4)
|
||||
expect(assigns(:admins)).not_to include(admin3)
|
||||
expect(assigns(:admins)[0].procedures).not_to include(published_procedure)
|
||||
expect(assigns(:admins)[0].procedures).to include(antoher_published_procedure_for_admin1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #search' do
|
||||
|
@ -306,6 +338,7 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
|
||||
describe 'searching' do
|
||||
let!(:matching_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2, libelle: 'éléctriCITE') }
|
||||
let!(:unmatching_procedure_cause_hidden_as_template) { create(:procedure_with_dossiers, :published, dossiers_count: 2, libelle: 'éléctriCITE', hidden_at_as_template: Time.zone.now) }
|
||||
let!(:unmatching_procedure) { create(:procedure_with_dossiers, :published, dossiers_count: 2, libelle: 'temoin') }
|
||||
|
||||
let(:query) { 'ELECTRIcité' }
|
||||
|
@ -314,6 +347,11 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
expect(response_procedures).to include(matching_procedure)
|
||||
expect(response_procedures).not_to include(unmatching_procedure)
|
||||
end
|
||||
|
||||
it 'hide procedure if it is hidden as template' do
|
||||
expect(response_procedures).to include(matching_procedure)
|
||||
expect(response_procedures).not_to include(unmatching_procedure_cause_hidden_as_template)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,6 +15,28 @@ describe Manager::ProceduresController, type: :controller do
|
|||
it { expect(procedure.whitelisted?).to be_truthy }
|
||||
end
|
||||
|
||||
describe '#hide_as_template' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
post :hide_as_template, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.hidden_as_template?).to be_truthy }
|
||||
end
|
||||
|
||||
describe '#unhide_as_template' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
post :unhide_as_template, params: { id: procedure.id }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.hidden_as_template?).to be_falsey }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
render_views
|
||||
|
||||
|
@ -25,6 +47,7 @@ describe Manager::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
it { expect(response.body).to include('sub type de champ') }
|
||||
it { expect(response.body).to include('Hidden At As Template') }
|
||||
end
|
||||
|
||||
describe '#discard' do
|
||||
|
|
Loading…
Reference in a new issue