diff --git a/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php b/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php index 2a6e0e223..26fc1b098 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/SignatureRequestController.php @@ -15,11 +15,13 @@ use Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner\RequestPdfSignMessa use Chill\DocStoreBundle\Service\Signature\PDFPage; use Chill\DocStoreBundle\Service\Signature\PDFSignatureZone; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; use Chill\MainBundle\Templating\Entity\ChillEntityRenderManagerInterface; use Chill\MainBundle\Workflow\EntityWorkflowManager; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Security; @@ -40,6 +42,11 @@ class SignatureRequestController public function processSignature(EntityWorkflowStepSignature $signature, Request $request): JsonResponse { $entityWorkflow = $signature->getStep()->getEntityWorkflow(); + + if (EntityWorkflowSignatureStateEnum::PENDING !== $signature->getState()) { + return new JsonResponse([], status: Response::HTTP_CONFLICT); + } + $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow); $content = $this->storedObjectManager->read($storedObject); diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowAddSignatureController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowAddSignatureController.php index 8ee8138fa..deb90119b 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowAddSignatureController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowAddSignatureController.php @@ -12,12 +12,15 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; use Chill\DocStoreBundle\Service\Signature\PDFSignatureZoneAvailable; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; use Chill\MainBundle\Workflow\EntityWorkflowManager; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Twig\Environment; @@ -28,6 +31,7 @@ final readonly class WorkflowAddSignatureController private PDFSignatureZoneAvailable $PDFSignatureZoneAvailable, private NormalizerInterface $normalizer, private Environment $twig, + private UrlGeneratorInterface $urlGenerator, ) {} #[Route(path: '/{_locale}/main/workflow/signature/{id}/sign', name: 'chill_main_workflow_signature_add', methods: 'GET')] @@ -35,6 +39,16 @@ final readonly class WorkflowAddSignatureController { $entityWorkflow = $signature->getStep()->getEntityWorkflow(); + if (EntityWorkflowSignatureStateEnum::PENDING !== $signature->getState()) { + if ($request->query->has('returnPath')) { + return new RedirectResponse($request->query->get('returnPath')); + } + + return new RedirectResponse( + $this->urlGenerator->generate('chill_main_workflow_show', ['id' => $entityWorkflow->getId()]) + ); + } + $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow); if (null === $storedObject) { throw new NotFoundHttpException('No stored object found'); diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowAddSignatureControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowAddSignatureControllerTest.php index 81c8d095e..4b6fd38e2 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowAddSignatureControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/WorkflowAddSignatureControllerTest.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; use Chill\PersonBundle\Entity\Person; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Twig\Environment; @@ -62,7 +63,9 @@ class WorkflowAddSignatureControllerTest extends TestCase $twig->method('render')->with('@ChillMain/Workflow/_signature_sign.html.twig', $this->isType('array')) ->willReturn('ok'); - $controller = new WorkflowAddSignatureController($entityWorkflowManager, $pdfSignatureZoneAvailable, $normalizer, $twig); + $urlGenerator = $this->createMock(UrlGeneratorInterface::class); + + $controller = new WorkflowAddSignatureController($entityWorkflowManager, $pdfSignatureZoneAvailable, $normalizer, $twig, $urlGenerator); $actual = $controller($signature, new Request());