|
|
@@ -27,16 +27,27 @@ final class CurrentAccessExtension extends AbstractExtension
|
|
|
return $resourceClass === Access::class;
|
|
|
}
|
|
|
|
|
|
- public function addWhere(QueryBuilder $queryBuilder, string $resourceClass, ?Operation $operation): void
|
|
|
+ protected function addWhere(QueryBuilder $queryBuilder, string $resourceClass, ?Operation $operation): void
|
|
|
{
|
|
|
- /** @var Access $currentUser */
|
|
|
- $currentUser = $this->security->getUser();
|
|
|
- $rootAlias = $queryBuilder->getRootAliases()[0];
|
|
|
- $queryBuilder
|
|
|
- ->andWhere(sprintf('%s.organization = :current_organization', $rootAlias))
|
|
|
- ->setParameter('current_organization', $currentUser->getOrganization())
|
|
|
- ;
|
|
|
-
|
|
|
- $this->currentAccessExtensionIterator->addWhere($queryBuilder, $operation?->getName());
|
|
|
+ $token = $this->security->getToken();
|
|
|
+ if ($token === null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $currentUser = $token->getUser();
|
|
|
+ if (!$currentUser instanceof Access) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $organization = $currentUser->getOrganization();
|
|
|
+ $rootAliases = $queryBuilder->getRootAliases();
|
|
|
+ if (empty($rootAliases)) {
|
|
|
+ throw new \LogicException('No root alias defined.');
|
|
|
+ }
|
|
|
+
|
|
|
+ $rootAlias = $rootAliases[0];
|
|
|
+ $queryBuilder->andWhere(sprintf('%s.organization = :current_organization', $rootAlias));
|
|
|
+ $queryBuilder->setParameter('current_organization', $organization);
|
|
|
+
|
|
|
+ $operationName = $operation ? $operation->getName() : '';
|
|
|
+ $this->currentAccessExtensionIterator->addWhere($queryBuilder, $operationName);
|
|
|
}
|
|
|
}
|