fix(dossier): avoir final state if etablissement is still in degraded mode

Maintenant qu'on autorise un dossier pour entreprise a être créé en mode "dégradé",
(avec établissement incomplet suite à API Entreprise/INSEE down…),
on empêche de l'accepter/refuser/classer sans suite tant qu'on a pas
vérifié son SIRET.

Fix 2839832517/?project=1429550&query=is%3Aunresolved
This commit is contained in:
Colin Darie 2022-09-21 15:05:11 +02:00
parent 864b1f0c3c
commit e7de19b24d
3 changed files with 58 additions and 7 deletions

View file

@ -170,19 +170,19 @@ class Dossier < ApplicationRecord
end
event :accepter, after: :after_accepter do
transitions from: :en_instruction, to: :accepte
transitions from: :en_instruction, to: :accepte, guard: :can_terminer?
end
event :accepter_automatiquement, after: :after_accepter_automatiquement do
transitions from: :en_construction, to: :accepte
transitions from: :en_construction, to: :accepte, guard: :can_terminer?
end
event :refuser, after: :after_refuser do
transitions from: :en_instruction, to: :refuse
transitions from: :en_instruction, to: :refuse, guard: :can_terminer?
end
event :classer_sans_suite, after: :after_classer_sans_suite do
transitions from: :en_instruction, to: :sans_suite
transitions from: :en_instruction, to: :sans_suite, guard: :can_terminer?
end
event :repasser_en_instruction, after: :after_repasser_en_instruction do
@ -515,6 +515,12 @@ class Dossier < ApplicationRecord
brouillon? && procedure.dossier_can_transition_to_en_construction? && !for_procedure_preview?
end
def can_terminer?
return false if etablissement&.as_degraded_mode?
true
end
def can_repasser_en_instruction?
termine? && !user_deleted?
end