Merge branch 'signature-app/signatur-for-user' into 'signature-app-master'

Add support for user signatures in workflow transitions

See merge request Chill-Projet/chill-bundles!712
This commit is contained in:
Julien Fastré 2024-07-10 10:52:48 +00:00
commit 0474b25859
3 changed files with 55 additions and 5 deletions

View File

@ -413,8 +413,13 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
*
* @return $this
*/
public function setStep(string $step, WorkflowTransitionContextDTO $transitionContextDTO, string $transition, \DateTimeImmutable $transitionAt, ?User $byUser = null): self
{
public function setStep(
string $step,
WorkflowTransitionContextDTO $transitionContextDTO,
string $transition,
\DateTimeImmutable $transitionAt,
?User $byUser = null
): self {
$previousStep = $this->getCurrentStep();
$previousStep
@ -437,8 +442,12 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
$newStep->addDestEmail($email);
}
foreach ($transitionContextDTO->futurePersonSignatures as $personSignature) {
new EntityWorkflowStepSignature($newStep, $personSignature);
if (null !== $transitionContextDTO->futureUserSignature) {
new EntityWorkflowStepSignature($newStep, $transitionContextDTO->futureUserSignature);
} else {
foreach ($transitionContextDTO->futurePersonSignatures as $personSignature) {
new EntityWorkflowStepSignature($newStep, $personSignature);
}
}
// copy the freeze

View File

@ -13,7 +13,9 @@ namespace Chill\MainBundle\Tests\Entity\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
use Chill\PersonBundle\Entity\Person;
use PHPUnit\Framework\TestCase;
/**
@ -105,4 +107,35 @@ final class EntityWorkflowTest extends TestCase
self::assertEquals('2024-01-02', $previous->getTransitionAt()?->format('Y-m-d'));
self::assertEquals('to_step_two', $previous->getTransitionAfter());
}
public function testSetStepSignatureForUserIsCreated()
{
$entityWorkflow = new EntityWorkflow();
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
$dto->futureUserSignature = $user = new User();
$entityWorkflow->setStep('new', $dto, 'to_new', new \DateTimeImmutable());
$actual = $entityWorkflow->getCurrentStep();
self::assertCount(1, $actual->getSignatures());
self::assertSame($user, $actual->getSignatures()->first()->getSigner());
}
public function testSetStepSignatureForPersonIsCreated()
{
$entityWorkflow = new EntityWorkflow();
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
$dto->futurePersonSignatures[] = $person1 = new Person();
$dto->futurePersonSignatures[] = $person2 = new Person();
$entityWorkflow->setStep('new', $dto, 'to_new', new \DateTimeImmutable());
$actual = $entityWorkflow->getCurrentStep();
$persons = $actual->getSignatures()->map(fn (EntityWorkflowStepSignature $signature) => $signature->getSigner());
self::assertCount(2, $actual->getSignatures());
self::assertContains($person1, $persons);
self::assertContains($person2, $persons);
}
}

View File

@ -13,6 +13,7 @@ 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;
@ -52,10 +53,17 @@ class WorkflowTransitionContextDTO
public array $futureDestEmails = [];
/**
* a list of future @see{Person} with will sign the next step.
* 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 = '';