mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
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:
@@ -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',
|
||||
|
Reference in New Issue
Block a user