mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
This update introduces the ability to specify user signatures in workflow transitions. It allows a nullable user to be declared that may be requested to apply a signature. The code now handles the use-case of signing a transition by a user in addition to previous functionality of having it signed by a "Person" entity. Corresponding tests are also updated to validate this new feature.
88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?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\Workflow;
|
|
|
|
use Chill\MainBundle\Entity\User;
|
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
use Symfony\Component\Workflow\Transition;
|
|
|
|
/**
|
|
* Context for a transition on an workflow entity.
|
|
*/
|
|
class WorkflowTransitionContextDTO
|
|
{
|
|
/**
|
|
* a list of future dest users for the next steps.
|
|
*
|
|
* This is in used in order to let controller inform who will be the future users which will validate
|
|
* the next step. This is necessary to perform some computation about the next users, before they are
|
|
* associated to the entity EntityWorkflowStep.
|
|
*
|
|
* @var array|User[]
|
|
*/
|
|
public array $futureDestUsers = [];
|
|
|
|
/**
|
|
* a list of future cc users for the next steps.
|
|
*
|
|
* @var array|User[]
|
|
*/
|
|
public array $futureCcUsers = [];
|
|
|
|
/**
|
|
* a list of future dest emails for the next steps.
|
|
*
|
|
* This is in used in order to let controller inform who will be the future emails which will validate
|
|
* the next step. This is necessary to perform some computation about the next emails, before they are
|
|
* associated to the entity EntityWorkflowStep.
|
|
*
|
|
* @var array|string[]
|
|
*/
|
|
public array $futureDestEmails = [];
|
|
|
|
/**
|
|
* A list of future @see{Person} with will sign the next step.
|
|
*
|
|
* @var list<Person>
|
|
*/
|
|
public array $futurePersonSignatures = [];
|
|
|
|
/**
|
|
* An eventual user which is requested to apply a signature.
|
|
*/
|
|
public ?User $futureUserSignature = null;
|
|
|
|
public ?Transition $transition = null;
|
|
|
|
public string $comment = '';
|
|
|
|
public function __construct(
|
|
public EntityWorkflow $entityWorkflow
|
|
) {}
|
|
|
|
#[Assert\Callback()]
|
|
public function validateCCUserIsNotInDest(ExecutionContextInterface $context, $payload): void
|
|
{
|
|
foreach ($this->futureDestUsers as $u) {
|
|
if (in_array($u, $this->futureCcUsers, true)) {
|
|
$context
|
|
->buildViolation('workflow.The user in cc cannot be a dest user in the same workflow step')
|
|
->atPath('ccUsers')
|
|
->addViolation();
|
|
}
|
|
}
|
|
}
|
|
}
|