add delete feature for entityWorkflow (wip)

This commit is contained in:
2022-02-23 10:08:11 +01:00
parent 8f597eb254
commit ffe4dd4a98
6 changed files with 88 additions and 10 deletions

View File

@@ -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,
];
}
}