Implement logic to put workflow on hold and resume it

This commit is contained in:
Julie Lenaerts 2024-08-07 16:48:59 +02:00 committed by Julien Fastré
parent 9475a708c3
commit 42471269db
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 24 additions and 7 deletions

View File

@ -19,11 +19,13 @@ use Chill\MainBundle\Form\WorkflowStepType;
use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository; use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepHoldRepository;
use Chill\MainBundle\Security\Authorization\EntityWorkflowVoter; use Chill\MainBundle\Security\Authorization\EntityWorkflowVoter;
use Chill\MainBundle\Security\ChillSecurity; use Chill\MainBundle\Security\ChillSecurity;
use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\EntityWorkflowManager;
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Clock\ClockInterface; use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\FormType;
@ -52,6 +54,7 @@ class WorkflowController extends AbstractController
private readonly ChillSecurity $security, private readonly ChillSecurity $security,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
private readonly ClockInterface $clock, private readonly ClockInterface $clock,
private readonly EntityWorkflowStepHoldRepository $entityWorkflowStepHoldRepository,
private readonly EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository, private readonly EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
) {} ) {}
@ -283,6 +286,9 @@ class WorkflowController extends AbstractController
); );
} }
/**
* @throws NonUniqueResultException
*/
#[Route(path: '/{_locale}/main/workflow/{id}/show', name: 'chill_main_workflow_show')] #[Route(path: '/{_locale}/main/workflow/{id}/show', name: 'chill_main_workflow_show')]
public function show(EntityWorkflow $entityWorkflow, Request $request): Response public function show(EntityWorkflow $entityWorkflow, Request $request): Response
{ {
@ -292,6 +298,7 @@ class WorkflowController extends AbstractController
$workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName());
$errors = []; $errors = [];
$signatures = $entityWorkflow->getCurrentStep()->getSignatures(); $signatures = $entityWorkflow->getCurrentStep()->getSignatures();
$holdOnStepByUser = $this->entityWorkflowStepHoldRepository->findOneByStepAndUser($entityWorkflow->getCurrentStep(), $this->security->getUser());
if (\count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { if (\count($workflow->getEnabledTransitions($entityWorkflow)) > 0) {
// possible transition // possible transition
@ -354,6 +361,7 @@ class WorkflowController extends AbstractController
'entity_workflow' => $entityWorkflow, 'entity_workflow' => $entityWorkflow,
'transition_form_errors' => $errors, 'transition_form_errors' => $errors,
'signatures' => $signatures, 'signatures' => $signatures,
'holdOnStepByUser' => $holdOnStepByUser,
] ]
); );
} }

View File

@ -64,14 +64,21 @@
<section class="step my-4">{% include '@ChillMain/Workflow/_comment.html.twig' %}</section> #} <section class="step my-4">{% include '@ChillMain/Workflow/_comment.html.twig' %}</section> #}
<section class="step my-4">{% include '@ChillMain/Workflow/_history.html.twig' %}</section> <section class="step my-4">{% include '@ChillMain/Workflow/_history.html.twig' %}</section>
{# useful ?
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">
<li class="cancel"> {% if holdOnStepByUser|length > 0 %}
<a class="btn btn-cancel" href="{{ path('chill_main_workflow_list_dest') }}"> <li>
{{ 'Back to the list'|trans }} <a class="btn btn-misc" href="{{ path('chill_main_workflow_remove_hold', {'holdId': holdOnStepByUser.id}) }}"><i class="fa fa-hourglass"></i>
</a> {{ 'workflow.Remove hold'|trans }}
</li> </a>
</li>
{% else %}
<li>
<a class="btn btn-misc" href="{{ path('chill_main_workflow_on_hold', {'id': entity_workflow.id}) }}"><i class="fa fa-hourglass"></i>
{{ 'workflow.Put on hold'|trans }}
</a>
</li>
{% endif %}
</ul> </ul>
#}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -527,6 +527,8 @@ workflow:
Access link copied: Lien d'accès copié Access link copied: Lien d'accès copié
This link grant any user to apply a transition: Le lien d'accès suivant permet d'appliquer une transition This link grant any user to apply a transition: Le lien d'accès suivant permet d'appliquer une transition
The workflow may be accssed through this link: Une transition peut être appliquée sur ce workflow grâce au lien d'accès suivant The workflow may be accssed through this link: Une transition peut être appliquée sur ce workflow grâce au lien d'accès suivant
Put on hold: Mettre en attente
Remove hold: Enlever la mise en attente
signature_zone: signature_zone:
title: Appliquer les signatures électroniques title: Appliquer les signatures électroniques