mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 10:03:49 +00:00
improve userPicker: delegate query to authorization helper
This commit is contained in:
@@ -87,34 +87,10 @@ class UserPickerType extends AbstractType
|
||||
->setDefault('choice_label', function(User $u) {
|
||||
return $u->getUsername();
|
||||
})
|
||||
->setNormalizer('query_builder', function(Options $options) {
|
||||
$roles = $this->authorizationHelper->getParentRoles($options['role']);
|
||||
$roles[] = $options['role'];
|
||||
->setNormalizer('choices', function(Options $options) {
|
||||
|
||||
$qb = $this->userRepository->createQueryBuilder('u');
|
||||
$qb
|
||||
// add center constraint
|
||||
->join('u.groupCenters', 'ug')
|
||||
->where($qb->expr()->eq('ug.center', ':center'))
|
||||
->setParameter('center', $options['center'])
|
||||
// link to permission groups
|
||||
->join('ug.permissionsGroup', 'pg')
|
||||
// role constraints
|
||||
->join('pg.roleScopes', 'roleScope')
|
||||
->andWhere($qb->expr()->in('roleScope.role', ':roles'))
|
||||
->setParameter(
|
||||
'roles',
|
||||
\array_map(
|
||||
function(Role $role) { return $role->getRole(); },
|
||||
$roles
|
||||
)
|
||||
)
|
||||
// add active constraint
|
||||
->andWhere('u.enabled = :enabled')
|
||||
->setParameter('enabled', true)
|
||||
;
|
||||
|
||||
return $qb;
|
||||
return $this->authorizationHelper
|
||||
->findUsersReaching($options['role'], $options['center']);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
Reference in New Issue
Block a user