Merge remote-tracking branch 'origin/signature-app-master' into 286-storedobject-voter

This commit is contained in:
2024-07-16 13:34:36 +02:00
17 changed files with 326 additions and 41 deletions

View File

@@ -14,6 +14,9 @@ namespace Chill\MainBundle\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
/**
* @template T of object
*/
interface EntityWorkflowHandlerInterface
{
/**
@@ -25,6 +28,9 @@ interface EntityWorkflowHandlerInterface
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string;
/**
* @return T|null
*/
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?object;
public function getRelatedObjects(object $object): array;

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Workflow;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException;
use Symfony\Component\Workflow\Registry;
@@ -38,6 +39,17 @@ class EntityWorkflowManager
return $this->registry->all($entityWorkflow);
}
public function getAssociatedStoredObject(EntityWorkflow $entityWorkflow): ?StoredObject
{
foreach ($this->handlers as $handler) {
if ($handler instanceof EntityWorkflowWithStoredObjectHandlerInterface && $handler->supports($entityWorkflow)) {
return $handler->getAssociatedStoredObject($entityWorkflow);
}
}
return null;
}
/**
* @return list<EntityWorkflow>
*/

View File

@@ -40,10 +40,14 @@ final readonly class EntityWorkflowMarkingStore implements MarkingStoreInterface
$next = array_keys($places)[0];
$transitionDTO = $context['context'] ?? null;
$transition = $context['transition'];
$byUser = $context['byUser'] ?? null;
$at = $context['transitionAt'];
if (!$transitionDTO instanceof WorkflowTransitionContextDTO) {
throw new \UnexpectedValueException(sprintf('Expected instance of %s', WorkflowTransitionContextDTO::class));
}
$subject->setStep($next, $transitionDTO);
$subject->setStep($next, $transitionDTO, $transition, $at, $byUser);
}
}

View File

@@ -0,0 +1,27 @@
<?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\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
/**
* Add methods to handle workflows associated with @see{StoredObject}.
*
* @template T of object
*
* @template-extends EntityWorkflowHandlerInterface<T>
*/
interface EntityWorkflowWithStoredObjectHandlerInterface extends EntityWorkflowHandlerInterface
{
public function getAssociatedStoredObject(EntityWorkflow $entityWorkflow): ?StoredObject;
}

View File

@@ -108,12 +108,6 @@ final readonly class EntityWorkflowTransitionEventSubscriber implements EventSub
/** @var EntityWorkflow $entityWorkflow */
$entityWorkflow = $event->getSubject();
$step = $entityWorkflow->getCurrentStep();
$step
->setTransitionAfter($event->getTransition()->getName())
->setTransitionAt(new \DateTimeImmutable('now'))
->setTransitionBy($this->security->getUser());
$this->chillLogger->info('[workflow] apply transition on entityWorkflow', [
'relatedEntityClass' => $entityWorkflow->getRelatedEntityClass(),

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;
@@ -51,6 +52,18 @@ class WorkflowTransitionContextDTO
*/
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 = '';