Skip to content

Commit 32b293f

Browse files
committed
enhance PermissionController and AccessControlEntryRepository to support wildcard parameters in permission queries
1 parent 37abcf0 commit 32b293f

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/Controller/PermissionController.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,23 @@ public function indexAces(
8080
): Response {
8181
$this->validateAuthorization(SetPermissionVoter::ACL_READ, $request);
8282

83-
$params = [
84-
'objectType' => $request->query->get('objectType', false),
85-
'objectId' => $request->query->get('objectId', false),
86-
'userType' => $request->query->get('userType', false),
87-
'userId' => $request->query->get('userId', false),
83+
$queryKeys = [
84+
'objectType',
85+
'objectId',
86+
'userType',
87+
'userId',
88+
'userIdWildcard',
89+
'objectIdWildcard',
8890
];
8991

92+
$params = array_combine(
93+
$queryKeys,
94+
array_map(
95+
fn (string $key) => $request->query->get($key, false),
96+
$queryKeys
97+
)
98+
);
99+
90100
$params = array_filter($params, fn ($entry): bool => false !== $entry);
91101
$params = array_map(fn ($p): ?string => '' === $p || 'null' === $p ? null : $p, $params);
92102

src/Entity/AccessControlEntryRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function applyParams(QueryBuilder $queryBuilder, array $params = []): vo
104104
] as $col => $alias) {
105105
if (isset($params[$col])) {
106106
$queryBuilder
107-
->andWhere(sprintf('a.%s = :%s', $col, $alias))
107+
->andWhere(sprintf('a.%1$s = :%2$s'.(($params[$col.'Wildcard'] ?? false) ? ' OR a.%1$s IS NULL' : ''), $col, $alias))
108108
->setParameter($alias, $params[$col]);
109109
}
110110
}

0 commit comments

Comments
 (0)