Merge pull request #9477 from demarches-simplifiees/can-route-from-epci-champ

ETQ admin je peux router par département depuis le champ EPCI
This commit is contained in:
LeSim 2023-09-19 08:21:26 +00:00 committed by GitHub
commit e6f8400cfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 67 additions and 7 deletions

View file

@ -4,7 +4,7 @@ fr:
Le routage permet dacheminer les dossiers vers différents groupes dinstructeurs. Le routage permet dacheminer les dossiers vers différents groupes dinstructeurs.
routing_configuration_notice_2_html: | routing_configuration_notice_2_html: |
<p>Pour le configurer, votre formulaire doit comporter <p>Pour le configurer, votre formulaire doit comporter
au moins un champ de type « choix simple », « communes », « départements » ou « régions ».</p> au moins un champ de type « choix simple », « communes », « epci », « départements » ou « régions ».</p>
<p>Ajoutez ce champ dans la page <a href="%{path}">« Configuration des champs »</a>.</p> <p>Ajoutez ce champ dans la page <a href="%{path}">« Configuration des champs »</a>.</p>
delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche. delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche.
delete_confirmation: | delete_confirmation: |

View file

@ -79,7 +79,7 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
return [] if targeted_champ.is_a?(Logic::Empty) return [] if targeted_champ.is_a?(Logic::Empty)
case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements) when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:epci)
departements_for_select departements_for_select
when TypeDeChamp.type_champs.fetch(:regions) when TypeDeChamp.type_champs.fetch(:regions)
regions_for_select regions_for_select

View file

@ -41,7 +41,7 @@ module Administrateurs
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id } tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
case tdc.type_champ case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements) when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:epci)
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] } tdc_options = APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
create_groups_from_territorial_tdc(tdc_options, stable_id) create_groups_from_territorial_tdc(tdc_options, stable_id)
when TypeDeChamp.type_champs.fetch(:regions) when TypeDeChamp.type_champs.fetch(:regions)

View file

@ -105,7 +105,7 @@ class GroupeInstructeur < ApplicationRecord
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id) routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id)
options = case routing_tdc.type_champ options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements) when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:epci)
APIGeoService.departements.map { _1[:code] } APIGeoService.departements.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:regions) when TypeDeChamp.type_champs.fetch(:regions)
APIGeoService.regions.map { _1[:code] } APIGeoService.regions.map { _1[:code] }

View file

@ -46,7 +46,7 @@ class Logic::ChampValue < Logic::Term
targeted_champ.selected_options targeted_champ.selected_options
when "Champs::DepartementChamp", "Champs::RegionChamp" when "Champs::DepartementChamp", "Champs::RegionChamp"
targeted_champ.code targeted_champ.code
when "Champs::CommuneChamp" when "Champs::CommuneChamp", "Champs::EpciChamp"
targeted_champ.code_departement targeted_champ.code_departement
end end
end end

View file

@ -102,7 +102,8 @@ class TypeDeChamp < ApplicationRecord
type_champs.fetch(:drop_down_list), type_champs.fetch(:drop_down_list),
type_champs.fetch(:communes), type_champs.fetch(:communes),
type_champs.fetch(:departements), type_champs.fetch(:departements),
type_champs.fetch(:regions) type_champs.fetch(:regions),
type_champs.fetch(:epci)
] ]
store_accessor :options, store_accessor :options,

View file

@ -762,6 +762,26 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
end end
end end
context 'with a epci type de champ' do
let!(:procedure3) do
create(:procedure,
types_de_champ_public: [{ type: :epci }],
administrateurs: [admin])
end
let!(:epci_tdc) { procedure3.draft_revision.types_de_champ.first }
before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: epci_tdc.stable_id } } }
it do
expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure3))
expect(flash.notice).to eq 'Les groupes instructeurs ont été ajoutés'
expect(procedure3.groupe_instructeurs.pluck(:label)).to include("01 Ain")
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(epci_tdc.stable_id), constant('01')))
expect(procedure3.routing_enabled).to be_truthy
end
end
context 'with a departements type de champ' do context 'with a departements type de champ' do
let!(:procedure3) do let!(:procedure3) do
create(:procedure, create(:procedure,

View file

@ -82,6 +82,19 @@ describe Logic::ChampValue do
it { is_expected.to eq('92') } it { is_expected.to eq('92') }
end end
context 'epci tdc' do
let(:champ) { build(:champ_epci, code_departement: '43') }
before do
champ.save!
champ.update_columns(external_id: '244301016', value: 'CC des Sucs')
end
it do
is_expected.to eq('43')
end
end
context 'region tdc' do context 'region tdc' do
let(:champ) { create(:champ_regions, value: 'La Réunion') } let(:champ) { create(:champ_regions, value: 'La Réunion') }

View file

@ -950,9 +950,10 @@ describe ProcedureRevision do
p.draft_revision.add_type_de_champ(type_champ: :departements, libelle: 'l3') p.draft_revision.add_type_de_champ(type_champ: :departements, libelle: 'l3')
p.draft_revision.add_type_de_champ(type_champ: :regions, libelle: 'l4') p.draft_revision.add_type_de_champ(type_champ: :regions, libelle: 'l4')
p.draft_revision.add_type_de_champ(type_champ: :communes, libelle: 'l5') p.draft_revision.add_type_de_champ(type_champ: :communes, libelle: 'l5')
p.draft_revision.add_type_de_champ(type_champ: :epci, libelle: 'l6')
end end
end end
it { expect(draft.routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3', 'l4', 'l5']) } it { expect(draft.routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3', 'l4', 'l5', 'l6']) }
end end
end end

View file

@ -130,6 +130,31 @@ describe RoutingEngine, type: :model do
end end
end end
context 'with an epci type de champ' do
let(:procedure) do
create(:procedure, types_de_champ_public: [{ type: :epci }]).tap do |p|
p.groupe_instructeurs.create(label: 'a third group')
end
end
let(:epci_tdc) { procedure.draft_revision.types_de_champ.first }
context 'with a matching rule' do
before do
gi_2.update(routing_rule: ds_eq(champ_value(epci_tdc.stable_id), constant('42')))
dossier.champs.first.update_columns(
external_id: 244200895,
value: 'CC du Pilat Rhodanien',
value_json: { code_departement: '42' }
)
end
it do
is_expected.to eq(gi_2)
end
end
end
context 'routing rules priorities' do context 'routing rules priorities' do
let(:procedure) do let(:procedure) do
create(:procedure, create(:procedure,