diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowSignatureCancelController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowSignatureCancelController.php index 20fce559a..95cd1b779 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowSignatureCancelController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowSignatureCancelController.php @@ -40,7 +40,36 @@ final readonly class WorkflowSignatureCancelController #[Route('/{_locale}/main/workflow/signature/{id}/cancel', name: 'chill_main_workflow_signature_cancel')] public function cancelSignature(EntityWorkflowStepSignature $signature, Request $request): Response { - if (!$this->security->isGranted(EntityWorkflowStepSignatureVoter::CANCEL, $signature)) { + return $this->markSignatureAction( + $signature, + $request, + EntityWorkflowStepSignatureVoter::CANCEL, + function (EntityWorkflowStepSignature $signature) {$this->signatureStepStateChanger->markSignatureAsCanceled($signature); }, + '@ChillMain/WorkflowSignature/cancel.html.twig', + ); + } + + #[Route('/{_locale}/main/workflow/signature/{id}/reject', name: 'chill_main_workflow_signature_reject')] + public function rejectSignature(EntityWorkflowStepSignature $signature, Request $request): Response + { + return $this->markSignatureAction( + $signature, + $request, + EntityWorkflowStepSignatureVoter::REJECT, + function (EntityWorkflowStepSignature $signature) {$this->signatureStepStateChanger->markSignatureAsRejected($signature); }, + '@ChillMain/WorkflowSignature/reject.html.twig', + ); + } + + private function markSignatureAction( + EntityWorkflowStepSignature $signature, + Request $request, + string $permissionAttribute, + callable $markSignature, + string $template, + ): Response { + + if (!$this->security->isGranted($permissionAttribute, $signature)) { throw new AccessDeniedHttpException('not allowed to cancel this signature'); } @@ -50,7 +79,7 @@ final readonly class WorkflowSignatureCancelController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->signatureStepStateChanger->markSignatureAsCanceled($signature); + $markSignature($signature); $this->entityManager->flush(); return new RedirectResponse( @@ -61,7 +90,7 @@ final readonly class WorkflowSignatureCancelController return new Response( $this->twig->render( - '@ChillMain/WorkflowSignature/cancel.html.twig', + $template, ['form' => $form->createView(), 'signature' => $signature] ) ); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig index 3cefd2a41..42a3b68d8 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_signature.html.twig @@ -29,6 +29,11 @@ {% else %} {% if (is_granted('CHILL_MAIN_ENTITY_WORKFLOW_SIGNATURE_CANCEL', s) or is_granted('CHILL_MAIN_ENTITY_WORKFLOW_SIGNATURE_SIGN', s)) %}
{{ 'workflow.signature.are_you_sure'|trans({'%signer%': signature.signer|chill_entity_render_string}) }}
+{{ 'workflow.signature.cancel_are_you_sure'|trans({'%signer%': signature.signer|chill_entity_render_string}) }}
{{ form_start(form) }}