Do not block transition in EntityWorkflow when the user is member of a dest user group

- refactor EntityWorkflowGuardTransition + tests
- allow to find easily user within userGroup by adding a dedicated method to UserGroup::contains
This commit is contained in:
2024-09-26 16:04:53 +02:00
parent 17f4c85fa5
commit 86ec6f82da
4 changed files with 44 additions and 1 deletions

View File

@@ -87,6 +87,17 @@ class EntityWorkflowGuardTransition implements EventSubscriberInterface
return;
}
if (!$user instanceof User) {
$event->addTransitionBlocker(
new TransitionBlocker(
'workflow.Only regular user can apply a transition',
'04fb4f76-7c0e-11ef-afc3-877bad7b0fe7'
)
);
return;
}
// for users
if (!in_array('only-dest', $systemTransitions, true)) {
$event->addTransitionBlocker(
@@ -108,6 +119,13 @@ class EntityWorkflowGuardTransition implements EventSubscriberInterface
return;
}
// we give a second chance, searching for the presence of the user within userGroups
foreach ($entityWorkflow->getCurrentStep()->getDestUserGroups() as $userGroup) {
if ($userGroup->contains($user)) {
return;
}
}
$event->addTransitionBlocker(new TransitionBlocker(
'workflow.You are not allowed to apply a transition on this workflow. Only those users are allowed: %users%',
'f3eeb57c-7532-11ec-9495-e7942a2ac7bc',