Merge pull request #11007 from demarches-simplifiees/can-condition-on-pays-champ
ETQ admin je peux conditionner / router depuis un champ pays
This commit is contained in:
commit
ddb238ccd0
6 changed files with 66 additions and 3 deletions
|
@ -60,6 +60,10 @@ module Administrateurs
|
||||||
rule_operator = :ds_eq
|
rule_operator = :ds_eq
|
||||||
tdc_options = APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
tdc_options = APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||||
|
when TypeDeChamp.type_champs.fetch(:pays)
|
||||||
|
rule_operator = :ds_eq
|
||||||
|
tdc_options = APIGeoService.countries.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
|
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
|
||||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||||
tdc_options = tdc.drop_down_options.reject(&:empty?)
|
tdc_options = tdc.drop_down_options.reject(&:empty?)
|
||||||
create_groups_from_drop_down_list_tdc(tdc_options, stable_id)
|
create_groups_from_drop_down_list_tdc(tdc_options, stable_id)
|
||||||
|
|
|
@ -12,7 +12,8 @@ class Logic::ChampValue < Logic::Term
|
||||||
:epci,
|
:epci,
|
||||||
:departements,
|
:departements,
|
||||||
:regions,
|
:regions,
|
||||||
:address
|
:address,
|
||||||
|
:pays
|
||||||
)
|
)
|
||||||
|
|
||||||
CHAMP_VALUE_TYPE = {
|
CHAMP_VALUE_TYPE = {
|
||||||
|
@ -56,7 +57,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
targeted_champ.selected
|
targeted_champ.selected
|
||||||
when "Champs::MultipleDropDownListChamp"
|
when "Champs::MultipleDropDownListChamp"
|
||||||
targeted_champ.selected_options
|
targeted_champ.selected_options
|
||||||
when "Champs::RegionChamp"
|
when "Champs::RegionChamp", "Champs::PaysChamp"
|
||||||
targeted_champ.code
|
targeted_champ.code
|
||||||
when "Champs::DepartementChamp"
|
when "Champs::DepartementChamp"
|
||||||
{
|
{
|
||||||
|
@ -81,7 +82,7 @@ class Logic::ChampValue < Logic::Term
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:integer_number), MANAGED_TYPE_DE_CHAMP.fetch(:decimal_number)
|
||||||
CHAMP_VALUE_TYPE.fetch(:number)
|
CHAMP_VALUE_TYPE.fetch(:number)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
|
when MANAGED_TYPE_DE_CHAMP.fetch(:drop_down_list),
|
||||||
MANAGED_TYPE_DE_CHAMP.fetch(:regions)
|
MANAGED_TYPE_DE_CHAMP.fetch(:regions), MANAGED_TYPE_DE_CHAMP.fetch(:pays)
|
||||||
CHAMP_VALUE_TYPE.fetch(:enum)
|
CHAMP_VALUE_TYPE.fetch(:enum)
|
||||||
when MANAGED_TYPE_DE_CHAMP.fetch(:communes)
|
when MANAGED_TYPE_DE_CHAMP.fetch(:communes)
|
||||||
CHAMP_VALUE_TYPE.fetch(:commune_enum)
|
CHAMP_VALUE_TYPE.fetch(:commune_enum)
|
||||||
|
@ -128,6 +129,8 @@ class Logic::ChampValue < Logic::Term
|
||||||
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
|
elsif operator_name.in?([Logic::InDepartementOperator.name, Logic::NotInDepartementOperator.name]) || tdc.type_champ.in?([MANAGED_TYPE_DE_CHAMP.fetch(:communes), MANAGED_TYPE_DE_CHAMP.fetch(:epci), MANAGED_TYPE_DE_CHAMP.fetch(:departements), MANAGED_TYPE_DE_CHAMP.fetch(:address)])
|
||||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
|
elsif tdc.type_champ == MANAGED_TYPE_DE_CHAMP.fetch(:pays)
|
||||||
|
APIGeoService.countries.map { ["#{_1[:name]} – #{_1[:code]}", _1[:code]] }
|
||||||
else
|
else
|
||||||
tdc.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }
|
tdc.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,6 +115,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
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(:pays),
|
||||||
type_champs.fetch(:epci),
|
type_champs.fetch(:epci),
|
||||||
type_champs.fetch(:address)
|
type_champs.fetch(:address)
|
||||||
]
|
]
|
||||||
|
|
|
@ -131,6 +131,18 @@ describe Conditions::ChampsConditionsComponent, type: :component do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'pays' do
|
||||||
|
let(:pays) { create(:type_de_champ_pays) }
|
||||||
|
let(:upper_tdcs) { [pays] }
|
||||||
|
let(:condition) { empty_operator(champ_value(pays.stable_id), constant(true)) }
|
||||||
|
let(:pays_options) { APIGeoService.countries.map { "#{_1[:name]} – #{_1[:code]}" } }
|
||||||
|
|
||||||
|
it do
|
||||||
|
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
|
||||||
|
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: (['Sélectionner'] + pays_options))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'address' do
|
context 'address' do
|
||||||
let(:address) { create(:type_de_champ_address) }
|
let(:address) { create(:type_de_champ_address) }
|
||||||
let(:upper_tdcs) { [address] }
|
let(:upper_tdcs) { [address] }
|
||||||
|
|
|
@ -959,6 +959,26 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a pays type de champ' do
|
||||||
|
let!(:procedure3) do
|
||||||
|
create(:procedure,
|
||||||
|
types_de_champ_public: [{ type: :pays }],
|
||||||
|
administrateurs: [admin])
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:pays_tdc) { procedure3.draft_revision.types_de_champ.first }
|
||||||
|
|
||||||
|
before { post :create_simple_routing, params: { procedure_id: procedure3.id, create_simple_routing: { stable_id: pays_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("AD – Andorre")
|
||||||
|
expect(procedure3.reload.defaut_groupe_instructeur.routing_rule).to eq(ds_eq(champ_value(pays_tdc.stable_id), constant('AD')))
|
||||||
|
expect(procedure3.routing_enabled).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a communes type de champ' do
|
context 'with a communes type de champ' do
|
||||||
let!(:procedure3) do
|
let!(:procedure3) do
|
||||||
create(:procedure,
|
create(:procedure,
|
||||||
|
|
|
@ -181,6 +181,29 @@ describe RoutingEngine, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a pays type de champ' do
|
||||||
|
let(:procedure) do
|
||||||
|
create(:procedure, types_de_champ_public: [{ type: :pays }]).tap do |p|
|
||||||
|
p.groupe_instructeurs.create(label: 'a third group')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:pays_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(pays_tdc.stable_id), constant('BE')))
|
||||||
|
dossier.champs.first.update_columns(
|
||||||
|
value: "Belgique"
|
||||||
|
)
|
||||||
|
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,
|
||||||
|
|
Loading…
Reference in a new issue