Merge pull request #9366 from demarches-simplifiees/fix-routage-with-other

Corrige le routage si option "autre" sélectionnée
This commit is contained in:
krichtof 2023-07-31 10:06:45 +00:00 committed by GitHub
commit b78611d36a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 7 deletions

View file

@ -60,6 +60,6 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
return [] if targeted_champ.is_a?(Logic::Empty) return [] if targeted_champ.is_a?(Logic::Empty)
targeted_champ targeted_champ
.options(@revision.types_de_champ_public) .options(@revision.types_de_champ_public)
.map { |tdc| [tdc.first, constant(tdc.first).to_json] } .map { |(label, value)| [label, constant(value).to_json] }
end end
end end

View file

@ -40,12 +40,22 @@ 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 }
tdc_options = tdc.options["drop_down_options"].reject(&:empty?) tdc_options = tdc.drop_down_options.reject(&:empty?)
tdc_options.each do |option_label| tdc_options.each do |option_label|
gi = @procedure.groupe_instructeurs.find_by({ label: option_label }) || @procedure.groupe_instructeurs routing_rule = ds_eq(champ_value(stable_id), constant(option_label))
.create({ label: option_label, instructeurs: [current_administrateur.instructeur] }) @procedure
gi.update(routing_rule: ds_eq(champ_value(stable_id), constant(gi.label))) .groupe_instructeurs
.find_or_create_by(label: option_label)
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
end
if tdc.drop_down_other?
routing_rule = ds_eq(champ_value(stable_id), constant(Champs::DropDownListChamp::OTHER))
@procedure
.groupe_instructeurs
.find_or_create_by(label: 'Autre')
.update(instructeurs: [current_administrateur.instructeur], routing_rule:)
end end
@procedure.toggle_routing @procedure.toggle_routing

View file

@ -117,7 +117,8 @@ class GroupeInstructeur < ApplicationRecord
def routing_rule_matches_tdc? def routing_rule_matches_tdc?
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)
routing_rule.right.value.in?(routing_tdc.options['drop_down_options']) options = routing_tdc.options_with_drop_down_other
routing_rule.right.value.in?(options)
end end
serialize :routing_rule, LogicSerializer serialize :routing_rule, LogicSerializer

View file

@ -31,7 +31,7 @@ class Logic::ChampValue < Logic::Term
targeted_champ = champ(champs) targeted_champ = champ(champs)
return nil if !targeted_champ.visible? return nil if !targeted_champ.visible?
return nil if targeted_champ.blank? return nil if targeted_champ.blank? & !targeted_champ.drop_down_other?
# on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type # on dépense 22ms ici, à cause du map, mais on doit pouvoir passer par un champ type
case targeted_champ.type case targeted_champ.type

View file

@ -17,6 +17,8 @@ class Logic::Constant < Logic::Term
I18n.t('utils.yes') I18n.t('utils.yes')
when FalseClass when FalseClass
I18n.t('utils.no') I18n.t('utils.no')
when Champs::DropDownListChamp::OTHER
'Autre'
else else
@value.to_s @value.to_s
end end

View file

@ -517,6 +517,14 @@ class TypeDeChamp < ApplicationRecord
(drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?) (drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?)
end end
def options_with_drop_down_other
if drop_down_other?
drop_down_options + [Champs::DropDownListChamp::OTHER]
else
drop_down_options
end
end
def layer_enabled?(layer) def layer_enabled?(layer)
options && options[layer] && options[layer] != '0' options && options[layer] && options[layer] != '0'
end end

View file

@ -0,0 +1,23 @@
namespace :after_party do
desc 'Deployment task: update_routing_rule_for_groups_routing_from_drop_down_other'
task update_routing_rule_for_groups_routing_from_drop_down_other: :environment do
puts "Running deploy task 'update_routing_rule_for_groups_routing_from_drop_down_other'"
# Put your task implementation HERE.
include Logic
GroupeInstructeur
.joins(:procedure)
.where(procedures: { routing_enabled: true })
.in_batches do |groupe_instructeurs|
groupe_instructeurs
.filter { |gi| gi.routing_rule.present? && gi.routing_rule.right.value == 'Autre' }
.each { |gi| gi.update(routing_rule: ds_eq(gi.routing_rule.left, constant('__other__'))) }
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end