diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 9bcaf62..30dbd9f 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -126,6 +126,9 @@ class UserRepository extends ServiceEntityRepository * to them (a blocked account cannot log in to do what it is reminded of) and an assignment * mailing puts them in CC. Hotel codes and muted notifications are the caller's to check. * + * Left out is a house manager who is also a team admin or travel manager: staff hold the role + * and hotel codes for testing, and BusPro syncs both on every login, so they cannot be removed. + * * @return User[] */ public function findActiveHouseManagers(): array @@ -134,9 +137,13 @@ class UserRepository extends ServiceEntityRepository return $qb ->where('JSON_CONTAINS(user.roles, :role) = 1') + ->andWhere('JSON_CONTAINS(user.roles, :teamAdmin) = 0') + ->andWhere('JSON_CONTAINS(user.roles, :manager) = 0') ->andWhere($qb->expr()->isNull('user.deletedAt')) ->andWhere($qb->expr()->isNull('user.disabledAt')) ->setParameter('role', json_encode('ROLE_HOUSE_MANAGER')) + ->setParameter('teamAdmin', json_encode('ROLE_TEAM_ADMIN')) + ->setParameter('manager', json_encode('ROLE_MANAGER')) ->orderBy('user.id') ->getQuery() ->getResult() diff --git a/src/Service/Teamer/AssignmentMailingService.php b/src/Service/Teamer/AssignmentMailingService.php index 4f857b9..d4dd959 100644 --- a/src/Service/Teamer/AssignmentMailingService.php +++ b/src/Service/Teamer/AssignmentMailingService.php @@ -44,7 +44,8 @@ class AssignmentMailingService * rule that gives them access to the house's teamers) is in CC on exactly one mail: that of * the first recipient confirmed on an assignment of their house, in the recipients' order. * Muted notifications do not count, this is no notification. Left out is a house manager who - * gets the mailing anyway, as one of the teamers or under one of their addresses. + * gets the mailing anyway, as one of the teamers or under one of their addresses, and a test + * account, see UserRepository::findActiveHouseManagers(). * * @return array teamer id => house managers */ diff --git a/tests/Repository/HouseManagerReminderQueryTest.php b/tests/Repository/HouseManagerReminderQueryTest.php index 0adb6b2..bdfcc80 100644 --- a/tests/Repository/HouseManagerReminderQueryTest.php +++ b/tests/Repository/HouseManagerReminderQueryTest.php @@ -80,6 +80,26 @@ class HouseManagerReminderQueryTest extends KernelTestCase $this->assertNotContains($deleted, $reminded); } + /** + * Staff hold the house manager role and hotel codes for testing; a teamer who also runs a + * house is a real house manager. + */ + public function testHouseManagersWhoAreAlsoAdminsOrManagersAreLeftOut(): void + { + $teamer = $this->houseManager('teamer@example.org')->setRoles(['ROLE_HOUSE_MANAGER', 'ROLE_TEAMER']); + $admin = $this->houseManager('admin@example.org')->setRoles(['ROLE_HOUSE_MANAGER', 'ROLE_TEAM_ADMIN']); + $manager = $this->houseManager('manager@example.org')->setRoles(['ROLE_MANAGER', 'ROLE_HOUSE_MANAGER']); + $this->entityManager->flush(); + + /** @var UserRepository $repository */ + $repository = $this->entityManager->getRepository(User::class); + $houseManagers = $repository->findActiveHouseManagers(); + + $this->assertContains($teamer, $houseManagers); + $this->assertNotContains($admin, $houseManagers); + $this->assertNotContains($manager, $houseManagers); + } + private function houseManager(string $email): User { $teamer = (new Teamer())->setFirstName('Hanna')->setLastName('Haus')->setGender('d');