feat: relax filtering constraints for non-admin groups price users
This commit is contained in:
@@ -4,10 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\Filter\UserFilterDto;
|
||||
use App\Repository\Filter\AppliesListFiltersTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -67,4 +69,23 @@ class UserRepository extends ServiceEntityRepository
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Everyone worth filtering an accommodation booking by: current groups staff, plus whoever
|
||||
* a booking is still assigned to even after losing the role — otherwise a booking assigned
|
||||
* last season would become unfindable the moment its manager is deroled.
|
||||
*/
|
||||
public function createAccommodationBookingManagersQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->leftJoin(AccommodationBooking::class, 'booking', Join::ON, 'booking.managedBy = u')
|
||||
->andWhere('u.roles LIKE :groupsAdmin OR u.roles LIKE :groupsManager OR booking.id IS NOT NULL')
|
||||
->setParameter('groupsAdmin', '%"ROLE_GROUPS_ADMIN"%')
|
||||
->setParameter('groupsManager', '%"ROLE_GROUPS_MANAGER"%')
|
||||
->distinct()
|
||||
->orderBy('u.firstName')
|
||||
->addOrderBy('u.lastName')
|
||||
->addOrderBy('u.email')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user