include current role in ScopePickerType and UserPickerType

Previously, only the "parent" roles were takent into account in those two
types. This commit fixe the bug by adding the current role to the query.
This commit is contained in:
Julien Fastré 2018-04-16 17:18:59 +02:00
parent 53901e4681
commit 96cd18563b
2 changed files with 8 additions and 2 deletions

View File

@ -113,6 +113,9 @@ class ScopePickerType extends AbstractType
*/
protected function buildAccessibleScopeQuery(Center $center, Role $role)
{
$roles = $this->authorizationHelper->getParentRoles($role);
$roles[] = $role;
$qb = $this->scopeRepository->createQueryBuilder('s');
$qb
// jointure to center
@ -128,7 +131,7 @@ class ScopePickerType extends AbstractType
function(Role $role) {
return $role->getRole();
},
$this->authorizationHelper->getParentRoles($role)
$roles
))
// user contraint
->andWhere(':user MEMBER OF gc.users')

View File

@ -88,6 +88,9 @@ class UserPickerType extends AbstractType
return $u->getUsername();
})
->setNormalizer('query_builder', function(Options $options) {
$roles = $this->authorizationHelper->getParentRoles($options['role']);
$roles[] = $options['role'];
$qb = $this->userRepository->createQueryBuilder('u');
$qb
// add center constraint
@ -103,7 +106,7 @@ class UserPickerType extends AbstractType
'roles',
\array_map(
function(Role $role) { return $role->getRole(); },
$this->authorizationHelper->getParentRoles($options['role'])
$roles
)
)
// add active constraint