fix: show the whole timeline to staff who are also house managers
This commit is contained in:
1 parent
8f4c4d8267
commit
74080b0488
5 files changed
+134
-6
No files matched your search
@@ -33,8 +33,12 @@ class TimelineController extends AbstractController
|
|||||||
|
|
||||||
$filterDto = $this->filterHandler->getFilterSettings();
|
$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;
|
$hotelCodes = null;
|
||||||
if ($this->isGranted('ROLE_HOUSE_MANAGER')) {
|
if ($houseManagerOnly) {
|
||||||
$filterDto->setHotels([]);
|
$filterDto->setHotels([]);
|
||||||
$hotelCodes = $user->getHotelCodes();
|
$hotelCodes = $user->getHotelCodes();
|
||||||
}
|
}
|
||||||
@@ -50,6 +54,7 @@ class TimelineController extends AbstractController
|
|||||||
'houses' => $this->timelineService->preprocess($assignments, $period),
|
'houses' => $this->timelineService->preprocess($assignments, $period),
|
||||||
'calendar' => $this->timelineService->getCalendar($period),
|
'calendar' => $this->timelineService->getCalendar($period),
|
||||||
'filterDto' => $filterDto,
|
'filterDto' => $filterDto,
|
||||||
|
'houseManagerOnly' => $houseManagerOnly,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,8 @@ class TimelineFilterController extends AbstractController
|
|||||||
public function index(Request $request): Response
|
public function index(Request $request): Response
|
||||||
{
|
{
|
||||||
$formData = $this->filterHandler->getFilterSettings();
|
$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([]);
|
$formData->setHotels([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
$builder
|
||||||
->add('hotels', MultiselectType::class, [
|
->add('hotels', MultiselectType::class, [
|
||||||
'label' => 'Haus/Destination',
|
'label' => 'Haus/Destination',
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{% set state_labels = { open: 'offen', pending: 'in Bewerbung', staffed: 'besetzt' } %}
|
{% 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' %}
|
{% set is_disposition = item.type == 'disposition' %}
|
||||||
<div class="timeline-bar timeline-bar--{{ item.state }}"
|
<div class="timeline-bar timeline-bar--{{ item.state }}"
|
||||||
style="grid-row: {{ row }}; grid-column: {{ item.column + 1 }} / span {{ item.span }}"
|
style="grid-row: {{ row }}; grid-column: {{ item.column + 1 }} / span {{ item.span }}"
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
{% if not is_disposition and item.state == 'open' %}
|
{% if not is_disposition and item.state == 'open' %}
|
||||||
<span class="font-bold uppercase">offen</span>
|
<span class="font-bold uppercase">offen</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if is_granted('ROLE_HOUSE_MANAGER') %}
|
{% if house_manager_only %}
|
||||||
<span class="truncate">{{ item.jobProfile }}</span>
|
<span class="truncate">{{ item.jobProfile }}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ path('app_administrative_assignment_detail', { 'uuid': item.assignmentUuid, 'r': return_url() }) }}"
|
<a href="{{ path('app_administrative_assignment_detail', { 'uuid': item.assignmentUuid, 'r': return_url() }) }}"
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
{% for row in house.rows %}
|
{% for row in house.rows %}
|
||||||
{% set row_number = loop.index %}
|
{% set row_number = loop.index %}
|
||||||
{% for item in row %}
|
{% for item in row %}
|
||||||
{{ _self.bar(item, row_number, state_labels) }}
|
{{ _self.bar(item, row_number, state_labels, houseManagerOnly) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Controller\Administrative\Assignment;
|
||||||
|
|
||||||
|
use App\Entity\Assignment;
|
||||||
|
use App\Entity\Destination;
|
||||||
|
use App\Entity\JobProfile;
|
||||||
|
use App\Entity\User;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BusPro also lists admins and managers as house managers. Only a house manager without a staff
|
||||||
|
* role is kept to their own houses; staff see every house, the house filter and the links.
|
||||||
|
*/
|
||||||
|
class TimelineControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
private KernelBrowser $client;
|
||||||
|
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->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<string> $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('[email protected]')
|
||||||
|
->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<string>
|
||||||
|
*/
|
||||||
|
private function houses(Crawler $crawler): array
|
||||||
|
{
|
||||||
|
return $crawler->filter('.timeline-house-label > span:first-child')->each(fn (Crawler $label) => trim($label->text()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user