feat: sync non-privileged BusPro roles on every login

This commit is contained in:
Björn Fromme
2026-08-12 17:47:15 +02:00
parent 490acc2e8b
commit 7a82127494
4 changed files with 116 additions and 11 deletions
+34 -3
View File
@@ -42,7 +42,7 @@ class BpnAuthenticatorTest extends TestCase
self::assertSame(['SSL'], $user->getHotelCodes());
}
public function testExistingAccountKeepsTheRolesAnAdministratorAssigned(): void
public function testExistingAccountKeepsThePrivilegedRolesAnAdministratorAssigned(): void
{
$existing = (new User('[email protected]'))
->setRoles([Role::TEAMER, Role::GROUPS_MANAGER])
@@ -59,11 +59,42 @@ class BpnAuthenticatorTest extends TestCase
$user = $this->loadUser($authenticator);
self::assertNull($persisted, 'an existing account must not be persisted again');
self::assertSame(['ROLE_USER', Role::TEAMER, Role::GROUPS_MANAGER], $user->getRoles());
self::assertSame(['DKS'], $user->getHotelCodes());
// ROLE_TEAMER is gone with its CRM selection, ROLE_ADMIN is still not honoured, and the
// administrator-granted ROLE_GROUPS_MANAGER survives.
self::assertSame(['ROLE_USER', Role::CUSTOMER, Role::GROUPS_MANAGER], $user->getRoles());
self::assertSame(['DKS'], $user->getHotelCodes(), 'hotel codes stay administrator-managed');
self::assertNotNull($user->getLastLoginAt(), 'the rest of the profile is still synced');
}
public function testRoleGainedInBusProIsGrantedOnLogin(): void
{
$existing = (new User('[email protected]'))->setRoles([Role::CUSTOMER]);
$persisted = null;
$authenticator = $this->authenticator(
$this->crmAttributes([Role::TEAMER], []),
$existing,
$persisted,
);
// The case myep-team depends on: somebody becomes a Teamer after their account exists.
self::assertSame(['ROLE_USER', Role::TEAMER], $this->loadUser($authenticator)->getRoles());
}
public function testAccountWithoutAnyRoleIsHealedOnLogin(): void
{
$existing = new User('[email protected]');
$persisted = null;
$authenticator = $this->authenticator(
$this->crmAttributes([Role::TEAMER], []),
$existing,
$persisted,
);
self::assertSame(['ROLE_USER', Role::TEAMER], $this->loadUser($authenticator)->getRoles());
}
/**
* @param string[] $roles
* @param string[] $hotelCodes