mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fixed: [workflow] validation of users in cc and dest
The validation is processed at the form step, so before the transition is processed
This commit is contained in:
parent
63759a940f
commit
a21637331f
@ -333,7 +333,11 @@ class WorkflowController extends AbstractController
|
|||||||
$transitionForm = $this->createForm(
|
$transitionForm = $this->createForm(
|
||||||
WorkflowStepType::class,
|
WorkflowStepType::class,
|
||||||
$entityWorkflow->getCurrentStep(),
|
$entityWorkflow->getCurrentStep(),
|
||||||
['transition' => true, 'entity_workflow' => $entityWorkflow, 'suggested_users' => $usersInvolved]
|
[
|
||||||
|
'transition' => true,
|
||||||
|
'entity_workflow' => $entityWorkflow,
|
||||||
|
'suggested_users' => $usersInvolved
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$transitionForm->handleRequest($request);
|
$transitionForm->handleRequest($request);
|
||||||
|
@ -16,6 +16,7 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
|||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Validator\Constraints\Entity\WorkflowStepUsersOnTransition;
|
||||||
use Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation;
|
use Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -24,6 +25,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use Iterator;
|
use Iterator;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use function count;
|
use function count;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
|
|
||||||
@ -97,7 +99,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
/**
|
/**
|
||||||
* @ORM\OneToMany(targetEntity=EntityWorkflowStep::class, mappedBy="entityWorkflow", orphanRemoval=true, cascade={"persist"})
|
* @ORM\OneToMany(targetEntity=EntityWorkflowStep::class, mappedBy="entityWorkflow", orphanRemoval=true, cascade={"persist"})
|
||||||
* @ORM\OrderBy({"transitionAt": "ASC", "id": "ASC"})
|
* @ORM\OrderBy({"transitionAt": "ASC", "id": "ASC"})
|
||||||
*
|
* @Assert\Valid(traverse=true)
|
||||||
* @var Collection|EntityWorkflowStep[]
|
* @var Collection|EntityWorkflowStep[]
|
||||||
*/
|
*/
|
||||||
private Collection $steps;
|
private Collection $steps;
|
||||||
|
@ -12,7 +12,6 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Entity\Workflow;
|
namespace Chill\MainBundle\Entity\Workflow;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Validator\Constraints\Entity\WorkflowStepUsers;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -25,7 +24,6 @@ use function in_array;
|
|||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table("chill_main_workflow_entity_step")
|
* @ORM\Table("chill_main_workflow_entity_step")
|
||||||
* @WorkflowStepUsers()
|
|
||||||
*/
|
*/
|
||||||
class EntityWorkflowStep
|
class EntityWorkflowStep
|
||||||
{
|
{
|
||||||
|
@ -243,6 +243,20 @@ class WorkflowStepType extends AbstractType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
new Callback(
|
||||||
|
function ($step, ExecutionContextInterface $context, $payload) {
|
||||||
|
$form = $context->getObject();
|
||||||
|
|
||||||
|
foreach($form->get('future_dest_users')->getData() as $u) {
|
||||||
|
if (in_array($u, $form->get('future_cc_users')->getData(), true)) {
|
||||||
|
$context
|
||||||
|
->buildViolation('workflow.The user in cc cannot be a dest user in the same workflow step')
|
||||||
|
->atPath('ccUsers')
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Validator\Constraints\Entity;
|
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Annotation
|
|
||||||
*/
|
|
||||||
class WorkflowStepUsers extends Constraint
|
|
||||||
{
|
|
||||||
public string $message = 'The user in cc cannot be a dest user in the same workflow step';
|
|
||||||
|
|
||||||
public function getTargets()
|
|
||||||
{
|
|
||||||
return [self::CLASS_CONSTRAINT];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Validator\Constraints\Entity;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Annotation
|
|
||||||
*/
|
|
||||||
class WorkflowStepUsersValidator extends ConstraintValidator
|
|
||||||
{
|
|
||||||
public function validate($value, Constraint $constraint)
|
|
||||||
{
|
|
||||||
if (!$value instanceof EntityWorkflowStep) {
|
|
||||||
throw new UnexpectedTypeException($value, EntityWorkflowStep::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$constraint instanceof WorkflowStepUsers) {
|
|
||||||
throw new UnexpectedTypeException($constraint, WorkflowStepUsers::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($value->getDestUser() as $u) {
|
|
||||||
if ($value->getCcUser()->contains($u)) {
|
|
||||||
$this->context
|
|
||||||
->buildViolation($constraint->message)
|
|
||||||
->atPath('ccUsers')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,6 +33,7 @@ notification:
|
|||||||
|
|
||||||
workflow:
|
workflow:
|
||||||
You must add at least one dest user or email: Indiquez au moins un destinataire ou une adresse email
|
You must add at least one dest user or email: Indiquez au moins un destinataire ou une adresse email
|
||||||
|
The user in cc cannot be a dest user in the same workflow step: L'utilisateur en copie ne peut pas être présent dans les utilisateurs qui valideront la prochaine étape
|
||||||
|
|
||||||
rolling_date:
|
rolling_date:
|
||||||
When fixed date is selected, you must provide a date: Indiquez la date fixe choisie
|
When fixed date is selected, you must provide a date: Indiquez la date fixe choisie
|
Loading…
x
Reference in New Issue
Block a user