feat: relax filtering constraints for non-admin groups price users

This commit is contained in:
Björn Fromme
2026-08-24 14:32:45 +02:00
parent 178df9b787
commit 35826088cb
8 changed files with 50 additions and 233 deletions
@@ -1,97 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form\Admin\Filter;
use App\Entity\User;
use App\Form\Admin\Filter\AccommodationBookingFilterOptionsProvider;
use App\Repository\Groups\AccommodationBookingRepository;
use App\Repository\Groups\AccommodationRepository;
use App\Repository\UserRepository;
use PHPUnit\Framework\TestCase;
class AccommodationBookingFilterOptionsProviderTest extends TestCase
{
public function testSomebodyAssignedWithoutTheRoleStaysFilterable(): void
{
$staff = $this->user(1, '[email protected]');
$formerStaff = $this->user(2, '[email protected]');
$options = $this->provider([$staff], [$formerStaff])->formOptions(true);
self::assertSame(
['[email protected]', '[email protected]'],
array_map(static fn (User $u) => $u->getEmail(), $options['managers']),
'a booking assigned to someone who lost the groups role has to remain findable',
);
}
public function testSomebodyBothAssignedAndOnStaffIsOfferedOnce(): void
{
$manager = $this->user(1, '[email protected]');
$options = $this->provider([$manager], [$manager])->formOptions(true);
self::assertCount(1, $options['managers']);
}
public function testManagersAreSortedByEmail(): void
{
$options = $this->provider(
[$this->user(1, '[email protected]'), $this->user(2, '[email protected]')],
[$this->user(3, '[email protected]')],
)->formOptions(true);
self::assertSame(
['[email protected]', '[email protected]', '[email protected]'],
array_map(static fn (User $u) => $u->getEmail(), $options['managers']),
);
}
public function testStaffWhoCannotSeeOtherBookingsGetNoManagerFilterAtAll(): void
{
$options = $this->provider([$this->user(1, '[email protected]')], [])->formOptions(false);
self::assertFalse($options['can_filter_by_manager']);
self::assertSame([], $options['managers']);
}
public function testTheManagerFilterIsAPermissionNotAConsequenceOfEmptyData(): void
{
// Nobody holds a groups role and nothing is assigned yet — a group admin still gets to
// filter, which is what keeps the "no assignment" triage available on day one.
$options = $this->provider([], [])->formOptions(true);
self::assertTrue($options['can_filter_by_manager']);
self::assertSame([], $options['managers']);
}
/**
* @param User[] $groupsStaff
* @param User[] $assigned
*/
private function provider(array $groupsStaff, array $assigned): AccommodationBookingFilterOptionsProvider
{
$users = $this->createMock(UserRepository::class);
$users->method('findGroupsStaff')->willReturn($groupsStaff);
$bookings = $this->createMock(AccommodationBookingRepository::class);
$bookings->method('findAssignedManagers')->willReturn($assigned);
$accommodations = $this->createMock(AccommodationRepository::class);
$accommodations->method('findBy')->willReturn([]);
return new AccommodationBookingFilterOptionsProvider($users, $bookings, $accommodations);
}
private function user(int $id, string $email): User
{
$user = new User($email);
$idProperty = new \ReflectionProperty(User::class, 'id');
$idProperty->setValue($user, $id);
return $user;
}
}
@@ -28,26 +28,24 @@ class AccommodationBookingFilterDtoTest extends TestCase
);
self::assertSame((new \DateTimeImmutable('today'))->format('Y-m-d'), $filter->dateFrom?->format('Y-m-d'));
self::assertNull($filter->managedBy, 'a group admin sees everybodys bookings');
self::assertFalse($filter->managedByLocked);
}
public function testEverybodyElseStartsPinnedToTheirOwnBookings(): void
public function testEverybodyElseStartsFilteredToTheirOwnBookings(): void
{
$user = new User('[email protected]');
$filter = AccommodationBookingFilterDto::defaults(false, $user);
self::assertSame($user, $filter->managedBy);
self::assertTrue($filter->managedByLocked);
}
public function testThePinnedManagerChipCannotBeDismissed(): void
public function testTheDefaultManagerChipCanBeDismissed(): void
{
$filter = AccommodationBookingFilterDto::defaults(false, new User('[email protected]'));
$chip = $this->chipFor($filter, 'Betreuer:in');
self::assertNotNull($chip);
self::assertFalse($chip->isRemovable());
self::assertTrue($chip->isRemovable());
}
public function testAChosenManagerChipCanBeDismissed(): void