Handle permission

This commit is contained in:
Charles 2025-07-28 11:20:31 +02:00
parent a10b499522
commit 6446eb2ce1
1 changed files with 8 additions and 1 deletions

View File

@ -38,9 +38,16 @@ class UserController extends AbstractController
if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$usersByOrganization = $entityManager->getRepository(UsersOrganizations::class)->getActiveUsersGroupedByOrganization();
} else {
} else{
$userIdentifier = $this->getUser()->getUserIdentifier();
if (!$userIdentifier) {
return $this->redirectToRoute('app_login');
}
$organizations = $this->entityManager->getRepository(UsersOrganizations::class)->findOrganizationsByUserEmailAndRoleName($userIdentifier, 'ADMIN');
if(!$organizations) {
// if user is not admin in any organization, throw access denied
throw $this->createNotFoundException(self::ACCESS_DENIED);
}
$usersByOrganization = $this->entityManager->getRepository(UsersOrganizations::class)
->findActiveUsersByOrganizations($organizations);
}