diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea0e2c0a..2ed9cdebf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to * [homepage_widget]: null error on tasks widget fixed * [person-thirdparty]: fix quick-add of names that consist of multiple parts (eg. De Vlieger) within onthefly modal person/thirdparty * [search]: Order of birthdate fields changed in advanced search to avoid confusion. +* [workflow]: Constraint added to workflow (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/675) ## Test releases diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index 9a2fd1b6c..3eba23b37 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -109,6 +109,7 @@ class WorkflowStepType extends AbstractType 'multiple' => false, 'expanded' => true, 'choices' => $choices, + 'constraints' => [new NotNull()], 'choice_label' => function (Transition $transition) use ($workflow) { $meta = $workflow->getMetadataStore()->getTransitionMetadata($transition); @@ -208,24 +209,28 @@ class WorkflowStepType extends AbstractType $transition = $form['transition']->getData(); $toFinal = true; - foreach ($transition->getTos() as $to) { - $meta = $workflow->getMetadataStore()->getPlaceMetadata($to); - - if ( - !array_key_exists('isFinal', $meta) || false === $meta['isFinal'] - ) { - $toFinal = false; - } - } - - $destUsers = $form['future_dest_users']->getData(); - $destEmails = $form['future_dest_emails']->getData(); - - if (!$toFinal && [] === $destUsers && [] === $destEmails) { + if (null === $transition) { $context - ->buildViolation('workflow.You must add at least one dest user or email') - ->atPath('future_dest_users') - ->addViolation(); + ->buildViolation('workflow.You must select a next step, pick another decision if no next steps are available'); + } else { + foreach ($transition->getTos() as $to) { + $meta = $workflow->getMetadataStore()->getPlaceMetadata($to); + + if ( + !array_key_exists('isFinal', $meta) || false === $meta['isFinal'] + ) { + $toFinal = false; + } + } + $destUsers = $form['future_dest_users']->getData(); + $destEmails = $form['future_dest_emails']->getData(); + + if (!$toFinal && [] === $destUsers && [] === $destEmails) { + $context + ->buildViolation('workflow.You must add at least one dest user or email') + ->atPath('future_dest_users') + ->addViolation(); + } } } ), diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index c5ab02d6b..376806292 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -463,6 +463,7 @@ workflow: Previous transitionned: Anciens workflows Previous workflow transitionned help: Workflows où vous avez exécuté une action. For: Pour + You must select a next step, pick another decision if no next steps are available: Il faut une prochaine étape. Choissisez une autre décision si nécessaire. Subscribe final: Recevoir une notification à l'étape finale