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

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Tests\Workflow\EventSubscriber;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Security\Authorization\EntityWorkflowTransitionVoter;
use Chill\MainBundle\Templating\Entity\UserRender;
@@ -145,6 +146,11 @@ class EntityWorkflowGuardTransitionTest extends TestCase
yield [self::buildEntityWorkflow([new User()]), 'transition1', null, false, 'd9e39a18-704c-11ef-b235-8fe0619caee7'];
yield [self::buildEntityWorkflow([$user = new User()]), 'transition3', $user, false, '5b6b95e0-704d-11ef-a5a9-4b6fc11a8eeb'];
yield [self::buildEntityWorkflow([$user = new User()]), 'transition3', $user, true, '5b6b95e0-704d-11ef-a5a9-4b6fc11a8eeb'];
$userGroup = new UserGroup();
$userGroup->addUser(new User());
yield [self::buildEntityWorkflow([$userGroup]), 'transition1', new User(), false, 'f3eeb57c-7532-11ec-9495-e7942a2ac7bc'];
}
public static function provideValidTransition(): iterable
@@ -159,6 +165,10 @@ class EntityWorkflowGuardTransitionTest extends TestCase
// transition allowed thanks to permission "apply all transitions"
yield [self::buildEntityWorkflow([new User()]), 'transition1', new User(), true, 'step1'];
yield [self::buildEntityWorkflow([new User()]), 'transition2', new User(), true, 'step2'];
$userGroup = new UserGroup();
$userGroup->addUser($u = new User());
yield [self::buildEntityWorkflow([$userGroup]), 'transition1', $u, false, 'step1'];
}
public static function buildEntityWorkflow(array $futureDestUsers): EntityWorkflow