diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index ac8a5a7e0..09a830cfc 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -22,6 +22,8 @@ use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\Validator\StepDestValid; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -104,6 +106,35 @@ class WorkflowController extends AbstractController return $this->redirectToRoute('chill_main_workflow_show', ['id' => $entityWorkflow->getId()]); } + /** + * @Route("/{_locale}/main/workflow/{id}/delete", name="chill_main_workflow_delete") + */ + public function delete(EntityWorkflow $entityWorkflow, Request $request): Response + { + $this->denyAccessUnlessGranted(EntityWorkflowVoter::DELETE, $entityWorkflow); + + $form = $this->createForm(FormType::class); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->remove($entityWorkflow);; + $this->entityManager->flush(); + + $this->addFlash('success', $this->translator->trans('workflow.Workflow deleted with success')); + + if ($request->query->has('returnPath')) { + return new RedirectResponse($request->query->get('returnPath')); + } + + return $this->redirectToRoute('homepage'); + } + + return $this->render('@ChillMain/Workflow/delete.html.twig', [ + 'entityWorkflow' => $entityWorkflow, + 'delete_form' => $form->createView(), + ]); + } + /** * @Route("/{_locale}/main/workflow/list/dest", name="chill_main_workflow_list_dest") */ diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig new file mode 100644 index 000000000..cf51378f6 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/delete.html.twig @@ -0,0 +1,18 @@ +{% extends '@ChillMain/layout.html.twig' %} + +{% block title 'workflow.Delete workflow ?'|trans %} + +{% block content %} + +
+ {{ include('@ChillMain/Util/confirmation_template.html.twig', + { + 'title' : 'workflow.Delete workflow ?'|trans, + 'confirm_question' : 'workflow.Are you sure you want to delete this workflow ?'|trans, + 'cancel_route' : 'chill_main_workflow_show', + 'cancel_parameters' : {'id' : entityWorkflow.id}, + 'form' : delete_form + } ) }} +
+ +{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig index 210d552e0..043570874 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/index.html.twig @@ -24,7 +24,7 @@ {% block content %}

{{ block('title') }}

- + {# handler_template: - src/Bundle/ChillPersonBundle/Resources/views/Workflow/_evaluation.html.twig - src/Bundle/ChillPersonBundle/Resources/views/Workflow/_accompanying_period_work.html.twig @@ -35,8 +35,18 @@ {% include handler_template_title with handler_template_data|merge({'breadcrumb': true }) %}
{% include handler_template with handler_template_data|merge({'display_action': true }) %} + + {% if is_granted('CHILL_MAIN_WORKFLOW_DELETE', entity_workflow) %} + + {% endif %} - +
{% include '@ChillMain/Workflow/_follow.html.twig' %}
{% include '@ChillMain/Workflow/_decision.html.twig' %}
{#
{% include '@ChillMain/Workflow/_comment.html.twig' %}
#} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig index 6da68e390..a3890fa97 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig @@ -8,9 +8,9 @@ {% block content %}
- +

{{ block('title') }}

- +
- + {% endfor %} diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php index 9542d3acb..ee425b084 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/EntityWorkflowVoter.php @@ -25,6 +25,8 @@ class EntityWorkflowVoter extends Voter public const SEE = 'CHILL_MAIN_WORKFLOW_SEE'; + public const DELETE = 'CHILL_MAIN_WORKFLOW_DELETE'; + private EntityWorkflowManager $manager; private Security $security; @@ -40,7 +42,10 @@ class EntityWorkflowVoter extends Voter return $subject instanceof EntityWorkflow && in_array($attribute, self::getRoles(), true); } - protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + /** + * @param EntityWorkflow $subject + */ + protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { switch ($attribute) { case self::CREATE: @@ -55,6 +60,9 @@ class EntityWorkflowVoter extends Voter return $this->security->isGranted($entityAttribute, $handler->getRelatedEntity($subject)); + case self::DELETE: + return $subject->getStep() === 'initial'; + default: throw new UnexpectedValueException("attribute {$attribute} not supported"); } @@ -65,6 +73,7 @@ class EntityWorkflowVoter extends Voter return [ self::SEE, self::CREATE, + self::DELETE, ]; } } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index d3173bd7c..f0c97e0d2 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -396,6 +396,9 @@ workflow: Current step: Étape actuelle Comment on last change: Commentaire à la transition précédente Users allowed to apply transition: Utilisateurs pouvant valider cette étape + Workflow deleted with success: Le workflow a été supprimé + Delete workflow ?: Supprimer le workflow ? + Are you sure you want to delete this workflow ?: Êtes-vous sûr·e de vouloir supprimer ce workflow ? Subscribe final: Recevoir une notification à l'étape finale Subscribe all steps: Recevoir une notification à chaque étape