Add reject functionality for workflow signatures

Implemented the ability to reject workflow signatures by adding necessary templates, routes, and authorization checks. Updated the `WorkflowSignatureCancelController` to handle rejection and modified existing templates and translations to support the new feature.
This commit is contained in:
2024-09-25 11:31:27 +02:00
parent 83121c2a83
commit cfce531754
7 changed files with 86 additions and 17 deletions

View File

@@ -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]
)
);