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:
2024-11-06 17:10:48 +01:00
parent 43b70fd773
commit 7aca08c89e
4 changed files with 218 additions and 4 deletions

View File

@@ -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()) {