diff --git a/src/Controller/Administrative/Assignment/TimelineController.php b/src/Controller/Administrative/Assignment/TimelineController.php index f124bbb..5e3d7a3 100644 --- a/src/Controller/Administrative/Assignment/TimelineController.php +++ b/src/Controller/Administrative/Assignment/TimelineController.php @@ -33,8 +33,12 @@ class TimelineController extends AbstractController $filterDto = $this->filterHandler->getFilterSettings(); + // Only a house manager without a staff role is kept to their own houses. BusPro also lists + // admins and managers as house managers; they see everything like any staff member. + $houseManagerOnly = $this->isGranted('ROLE_HOUSE_MANAGER') && false === $this->isGranted('ROLE_ADMINISTRATIVE'); + $hotelCodes = null; - if ($this->isGranted('ROLE_HOUSE_MANAGER')) { + if ($houseManagerOnly) { $filterDto->setHotels([]); $hotelCodes = $user->getHotelCodes(); } @@ -50,6 +54,7 @@ class TimelineController extends AbstractController 'houses' => $this->timelineService->preprocess($assignments, $period), 'calendar' => $this->timelineService->getCalendar($period), 'filterDto' => $filterDto, + 'houseManagerOnly' => $houseManagerOnly, ]); } } diff --git a/src/Controller/Common/TimelineFilterController.php b/src/Controller/Common/TimelineFilterController.php index e34d271..e9bf8ed 100644 --- a/src/Controller/Common/TimelineFilterController.php +++ b/src/Controller/Common/TimelineFilterController.php @@ -31,7 +31,8 @@ class TimelineFilterController extends AbstractController public function index(Request $request): Response { $formData = $this->filterHandler->getFilterSettings(); - if ($this->isGranted('ROLE_HOUSE_MANAGER')) { + // a house manager without a staff role sees only their own houses, see TimelineController + if ($this->isGranted('ROLE_HOUSE_MANAGER') && false === $this->isGranted('ROLE_ADMINISTRATIVE')) { $formData->setHotels([]); } diff --git a/src/Form/TimelineFilterType.php b/src/Form/TimelineFilterType.php index 064a221..8a34199 100644 --- a/src/Form/TimelineFilterType.php +++ b/src/Form/TimelineFilterType.php @@ -53,7 +53,8 @@ class TimelineFilterType extends AbstractType ]) ; - if (false === $this->security->isGranted('ROLE_HOUSE_MANAGER')) { + // the house filter is for staff; a house manager without a staff role sees only their own houses + if ($this->security->isGranted('ROLE_ADMINISTRATIVE') || false === $this->security->isGranted('ROLE_HOUSE_MANAGER')) { $builder ->add('hotels', MultiselectType::class, [ 'label' => 'Haus/Destination', diff --git a/templates/administrative/assignment/timeline.html.twig b/templates/administrative/assignment/timeline.html.twig index ffcee80..f67bc91 100644 --- a/templates/administrative/assignment/timeline.html.twig +++ b/templates/administrative/assignment/timeline.html.twig @@ -4,7 +4,7 @@ {% set state_labels = { open: 'offen', pending: 'in Bewerbung', staffed: 'besetzt' } %} -{% macro bar(item, row, state_labels) %} +{% macro bar(item, row, state_labels, house_manager_only) %} {% set is_disposition = item.type == 'disposition' %}
offen {% endif %} - {% if is_granted('ROLE_HOUSE_MANAGER') %} + {% if house_manager_only %} {{ item.jobProfile }} {% else %} diff --git a/tests/Controller/Administrative/Assignment/TimelineControllerTest.php b/tests/Controller/Administrative/Assignment/TimelineControllerTest.php new file mode 100644 index 0000000..ce2d69c --- /dev/null +++ b/tests/Controller/Administrative/Assignment/TimelineControllerTest.php @@ -0,0 +1,121 @@ +client = static::createClient(server: ['HTTPS' => true]); + $this->entityManager = self::getContainer()->get(EntityManagerInterface::class); + + $this->entityManager->createQuery(sprintf('DELETE FROM %s', Assignment::class))->execute(); + $this->entityManager->createQuery(sprintf('DELETE FROM %s', Destination::class))->execute(); + $this->entityManager->createQuery(sprintf("DELETE FROM %s jobProfile WHERE jobProfile.name = 'Timeline Probe'", JobProfile::class))->execute(); + $this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute(); + + $jobProfile = (new JobProfile())->setName('Timeline Probe'); + $this->entityManager->persist($jobProfile); + foreach ([1 => ['AGR01', 'Rotbach'], 2 => ['DGS01', 'Spinabad']] as $busProId => [$hotelCode, $hotel]) { + $destination = (new Destination()) + ->setBusProId($busProId) + ->setCode($hotelCode) + ->setDateFrom(new \DateTimeImmutable('+10 days')) + ->setDateTo(new \DateTimeImmutable('+17 days')) + ->setProduct('Probe '.$hotel) + ->setHotel($hotel) + ->setHotelCode($hotelCode) + ->setHotelBusProId(1) + ->setPickups([]) + ; + $this->entityManager->persist($destination); + $this->entityManager->persist( + (new Assignment())->setDestination($destination)->setJobProfile($jobProfile)->setAvailableDispositions(1) + ); + } + $this->entityManager->flush(); + } + + public function testStaffWhoAreAlsoHouseManagersSeeEveryHouse(): void + { + $crawler = $this->request(['ROLE_TEAM_ADMIN', 'ROLE_HOUSE_MANAGER']); + + $this->assertSame(['Rotbach', 'Spinabad'], $this->houses($crawler)); + $this->assertCount(2, $crawler->filter('.timeline-bar a[href*="/administrative/assignment/detail/"]')); + } + + public function testAHouseManagerSeesOnlyTheirOwnHousesWithoutLinks(): void + { + $crawler = $this->request(['ROLE_HOUSE_MANAGER']); + + $this->assertSame(['Rotbach'], $this->houses($crawler)); + $this->assertCount(0, $crawler->filter('.timeline-bar a')); + } + + public function testOnlyStaffGetTheHouseFilter(): void + { + $this->request(['ROLE_MANAGER', 'ROLE_HOUSE_MANAGER']); + $this->client->request('GET', '/common/timeline/filter'); + $this->assertStringContainsString('Haus/Destination', (string) $this->client->getResponse()->getContent()); + + $this->request(['ROLE_HOUSE_MANAGER']); + $this->client->request('GET', '/common/timeline/filter'); + $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); + $this->assertStringNotContainsString('Haus/Destination', (string) $this->client->getResponse()->getContent()); + } + + /** + * @param list $roles + */ + private function request(array $roles): Crawler + { + $this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute(); + + $user = (new User()) + ->setFirstName('Erika') + ->setLastName('Muster') + ->setEmail('erika@example.com') + ->setRoles($roles) + ->setHotelCodes(['AGR']) + ->setBusProAddressId(1) + ->setBusProPersonId(1) + ; + $this->entityManager->persist($user); + $this->entityManager->flush(); + + $this->client->loginUser($user); + $crawler = $this->client->request('GET', '/administrative/timeline'); + + $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); + + return $crawler; + } + + /** + * @return list + */ + private function houses(Crawler $crawler): array + { + return $crawler->filter('.timeline-house-label > span:first-child')->each(fn (Crawler $label) => trim($label->text())); + } +}