mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 06:26:15 +00:00
add delete feature for entityWorkflow (wip)
This commit is contained in:
parent
8f597eb254
commit
ffe4dd4a98
@ -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")
|
||||
*/
|
||||
|
@ -0,0 +1,18 @@
|
||||
{% extends '@ChillMain/layout.html.twig' %}
|
||||
|
||||
{% block title 'workflow.Delete workflow ?'|trans %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container chill-md-10">
|
||||
{{ 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
|
||||
} ) }}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -35,6 +35,16 @@
|
||||
{% include handler_template_title with handler_template_data|merge({'breadcrumb': true }) %}
|
||||
</div>
|
||||
{% include handler_template with handler_template_data|merge({'display_action': true }) %}
|
||||
|
||||
{% if is_granted('CHILL_MAIN_WORKFLOW_DELETE', entity_workflow) %}
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a class="btn btn-delete"
|
||||
href="{{ chill_path_add_return_path('chill_main_workflow_delete', {'id': entity_workflow.id}) }}"
|
||||
></a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<section class="step my-4">{% include '@ChillMain/Workflow/_follow.html.twig' %}</section>
|
||||
|
@ -78,6 +78,13 @@
|
||||
</div>
|
||||
<div class="item-col">
|
||||
<ul class="record_actions">
|
||||
{% if is_granted('CHILL_MAIN_WORKFLOW_DELETE', l.entity_workflow) %}
|
||||
<li>
|
||||
<a class="btn btn-delete"
|
||||
href="{{ chill_path_add_return_path('chill_main_workflow_delete', {'id': l.entity_workflow.id}) }}"
|
||||
></a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="{{ path('chill_main_workflow_show', {'id': l.entity_workflow.id}) }}"
|
||||
class="btn btn-show">
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user