Add duplicate workflow prevention in MetadataExtractor

Integrate DuplicateEntityWorkflowFinder to prevent creating workflows for entities with existing opened or positive final workflows. Updated EntityWorkflowVoter to implement the same check before allowing creation. Removed unnecessary blank workflow parameter from Twig template.
This commit is contained in:
2024-09-24 14:18:50 +02:00
parent 758a14366e
commit 5a5d259d18
4 changed files with 87 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Workflow\EntityWorkflowManager;
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;
@@ -27,7 +28,11 @@ class EntityWorkflowVoter extends Voter
final public const SHOW_ENTITY_LINK = 'CHILL_MAIN_WORKFLOW_LINK_SHOW';
public function __construct(private readonly EntityWorkflowManager $manager, private readonly Security $security) {}
public function __construct(
private readonly EntityWorkflowManager $manager,
private readonly Security $security,
private readonly DuplicateEntityWorkflowFinder $duplicateEntityWorkflowFinder,
) {}
protected function supports($attribute, $subject)
{
@@ -41,6 +46,15 @@ class EntityWorkflowVoter extends Voter
{
switch ($attribute) {
case self::CREATE:
if (false === $this->voteOnAttribute(self::SEE, $subject, $token)) {
return false;
}
if ($this->duplicateEntityWorkflowFinder->hasDuplicateOpenedOrFinalPositiveEntityWorkflow($subject)) {
return false;
}
return true;
case self::SEE:
$handler = $this->manager->getHandler($subject);