feat: restrict admin role assignment to the privileged roles
This commit is contained in:
@@ -13,29 +13,37 @@ use Symfony\Component\Form\Forms;
|
||||
|
||||
class UserTypeTest extends TestCase
|
||||
{
|
||||
public function testStoredRolesArePreselectedWithoutTheImplicitRoleUser(): void
|
||||
public function testOnlyThePrivilegedRolesArePreselected(): void
|
||||
{
|
||||
$user = (new User('[email protected]'))->setRoles([Role::TEAMER]);
|
||||
$user = (new User('[email protected]'))->setRoles([Role::TEAMER, Role::GROUPS_MANAGER]);
|
||||
|
||||
self::assertSame([Role::TEAMER], $this->createForm($user)->get('roles')->getData());
|
||||
self::assertSame([Role::GROUPS_MANAGER], $this->createForm($user)->get('roles')->getData());
|
||||
}
|
||||
|
||||
public function testSubmittingRolesDoesNotStoreTheImplicitRoleUser(): void
|
||||
public function testOnlyPrivilegedRolesAreOffered(): void
|
||||
{
|
||||
$choices = $this->createForm(new User('[email protected]'))->get('roles')->getConfig()->getOption('choices');
|
||||
|
||||
// The rest is synced from BusPro on every login and would be overwritten right away.
|
||||
self::assertSame(Role::PRIVILEGED, array_values($choices));
|
||||
}
|
||||
|
||||
public function testSubmittingRolesKeepsTheSyncedOnesAndNotTheImplicitRoleUser(): void
|
||||
{
|
||||
$user = (new User('[email protected]'))->setRoles([Role::TEAMER]);
|
||||
|
||||
$form = $this->createForm($user);
|
||||
$form->submit(['roles' => [Role::TEAMER, Role::GROUPS_MANAGER], 'hotelCodes' => []]);
|
||||
$form->submit(['roles' => [Role::GROUPS_MANAGER], 'hotelCodes' => []]);
|
||||
|
||||
self::assertTrue($form->isSynchronized());
|
||||
// getRoles() prepends ROLE_USER; it must not have been persisted a second time.
|
||||
self::assertSame(['ROLE_USER', Role::TEAMER, Role::GROUPS_MANAGER], $user->getRoles());
|
||||
}
|
||||
|
||||
public function testClearingEveryCheckboxEmptiesTheAssignment(): void
|
||||
public function testClearingEveryCheckboxKeepsTheSyncedRoles(): void
|
||||
{
|
||||
$user = (new User('[email protected]'))
|
||||
->setRoles([Role::TEAMER])
|
||||
->setRoles([Role::TEAMER, Role::GROUPS_MANAGER])
|
||||
->setHotelCodes(['SSL'])
|
||||
;
|
||||
|
||||
@@ -43,7 +51,7 @@ class UserTypeTest extends TestCase
|
||||
$form->submit([]);
|
||||
|
||||
self::assertTrue($form->isSynchronized());
|
||||
self::assertSame(['ROLE_USER'], $user->getRoles());
|
||||
self::assertSame(['ROLE_USER', Role::TEAMER], $user->getRoles());
|
||||
self::assertSame([], $user->getHotelCodes());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user