fix(groupe_instructeur): always use assign_to_groupe_instructeur method
This commit is contained in:
parent
08a2a2c9aa
commit
71cfe094aa
6 changed files with 19 additions and 20 deletions
|
@ -174,6 +174,7 @@ module Users
|
|||
errors = submit_dossier_and_compute_errors
|
||||
|
||||
if errors.blank?
|
||||
RoutingEngine.compute(@dossier)
|
||||
@dossier.passer_en_construction!
|
||||
@dossier.process_declarative!
|
||||
NotificationMailer.send_en_construction_notification(@dossier).deliver_later
|
||||
|
@ -210,6 +211,8 @@ module Users
|
|||
if errors.blank?
|
||||
editing_fork_origin = @dossier.editing_fork_origin
|
||||
editing_fork_origin.merge_fork(@dossier)
|
||||
RoutingEngine.compute(editing_fork_origin)
|
||||
|
||||
redirect_to dossier_path(editing_fork_origin)
|
||||
else
|
||||
flash.now.alert = errors
|
||||
|
@ -493,10 +496,6 @@ module Users
|
|||
@dossier.assign_to_groupe_instructeur(groupe_instructeur_from_params)
|
||||
end
|
||||
|
||||
if @dossier.procedure.feature_enabled?(:routing_rules)
|
||||
RoutingEngine.compute(@dossier)
|
||||
end
|
||||
|
||||
errors
|
||||
end
|
||||
|
||||
|
@ -511,7 +510,7 @@ module Users
|
|||
@dossier.assign_to_groupe_instructeur(defaut_groupe_instructeur)
|
||||
end
|
||||
|
||||
if @dossier.groupe_instructeur.nil?
|
||||
if !@dossier.procedure.feature_enabled?(:routing_rules) && @dossier.groupe_instructeur.nil?
|
||||
errors += format_errors(errors: ["Le champ « #{@dossier.procedure.routing_criteria_name} » doit être rempli"])
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Mutations
|
|||
field :errors, [Types::ValidationErrorType], null: true
|
||||
|
||||
def resolve(dossier:, groupe_instructeur:)
|
||||
dossier.update!(groupe_instructeur:)
|
||||
dossier.assign_to_groupe_instructeur(groupe_instructeur)
|
||||
|
||||
{ dossier: }
|
||||
end
|
||||
|
|
|
@ -680,20 +680,16 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def assign_to_groupe_instructeur(groupe_instructeur, author = nil)
|
||||
if (groupe_instructeur.nil? || groupe_instructeur.procedure == procedure) && self.groupe_instructeur != groupe_instructeur
|
||||
if update(groupe_instructeur:, groupe_instructeur_updated_at: Time.zone.now)
|
||||
if !brouillon?
|
||||
unfollow_stale_instructeurs
|
||||
return if groupe_instructeur.present? && groupe_instructeur.procedure != procedure
|
||||
return if self.groupe_instructeur == groupe_instructeur
|
||||
|
||||
if author.present?
|
||||
log_dossier_operation(author, :changer_groupe_instructeur, self)
|
||||
end
|
||||
end
|
||||
update!(groupe_instructeur:, groupe_instructeur_updated_at: Time.zone.now)
|
||||
|
||||
true
|
||||
if !brouillon?
|
||||
unfollow_stale_instructeurs
|
||||
if author.present?
|
||||
log_dossier_operation(author, :changer_groupe_instructeur, self)
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
module RoutingEngine
|
||||
def self.compute(dossier)
|
||||
return if !dossier.procedure.feature_enabled?(:routing_rules)
|
||||
|
||||
matching_groupe = dossier.procedure.groupe_instructeurs.active.find do |gi|
|
||||
gi.routing_rule&.compute(dossier.champs)
|
||||
end
|
||||
matching_groupe ||= dossier.procedure.defaut_groupe_instructeur
|
||||
dossier.update!(groupe_instructeur: matching_groupe)
|
||||
dossier.assign_to_groupe_instructeur(matching_groupe)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -612,12 +612,12 @@ describe Dossier do
|
|||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
|
||||
it "can change groupe instructeur" do
|
||||
expect(dossier.assign_to_groupe_instructeur(new_groupe_instructeur_new_procedure)).to be_falsey
|
||||
dossier.assign_to_groupe_instructeur(new_groupe_instructeur_new_procedure)
|
||||
expect(dossier.groupe_instructeur).not_to eq(new_groupe_instructeur_new_procedure)
|
||||
end
|
||||
|
||||
it "can not change groupe instructeur if new groupe is from another procedure" do
|
||||
expect(dossier.assign_to_groupe_instructeur(new_groupe_instructeur)).to be_truthy
|
||||
dossier.assign_to_groupe_instructeur(new_groupe_instructeur)
|
||||
expect(dossier.groupe_instructeur).to eq(new_groupe_instructeur)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
describe RoutingEngine, type: :model do
|
||||
include Logic
|
||||
|
||||
before { Flipper.enable(:routing_rules, procedure) }
|
||||
|
||||
describe '.compute' do
|
||||
let(:procedure) do
|
||||
create(:procedure).tap do |p|
|
||||
|
|
Loading…
Add table
Reference in a new issue