mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-31 12:03:48 +00:00
Allow to remove the canceled workflow to be deleted, if canceled
- OP#812 - https://champs-libres.openproject.com/work_packages/812
This commit is contained in:
@@ -17,6 +17,7 @@ use Chill\MainBundle\Workflow\Helper\DuplicateEntityWorkflowFinder;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
class EntityWorkflowVoter extends Voter
|
||||
{
|
||||
@@ -32,6 +33,7 @@ class EntityWorkflowVoter extends Voter
|
||||
private readonly EntityWorkflowManager $manager,
|
||||
private readonly Security $security,
|
||||
private readonly DuplicateEntityWorkflowFinder $duplicateEntityWorkflowFinder,
|
||||
private readonly Registry $registry,
|
||||
) {}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
@@ -83,7 +85,25 @@ class EntityWorkflowVoter extends Voter
|
||||
return false;
|
||||
|
||||
case self::DELETE:
|
||||
return 'initial' === $subject->getStep();
|
||||
if ('initial' === $subject->getStep()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$subject->isFinal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// the entity workflow is finalized. We check if the final is not positive. If yes, we can
|
||||
// delete the entity
|
||||
$workflow = $this->registry->get($subject, $subject->getWorkflowName());
|
||||
foreach ($workflow->getMarking($subject)->getPlaces() as $place => $key) {
|
||||
$metadata = $workflow->getMetadataStore()->getPlaceMetadata($place);
|
||||
if (false === ($metadata['isFinalPositive'] ?? true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
case self::SHOW_ENTITY_LINK:
|
||||
if ('initial' === $subject->getStep()) {
|
||||
|
Reference in New Issue
Block a user