mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-31 12:03:48 +00:00
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:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user