roles logic updated
This commit is contained in:
parent
307e615fb3
commit
41c6e82a13
|
|
@ -8,11 +8,13 @@ use App\Entity\User;
|
|||
use App\Entity\UserOrganizatonApp;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use App\Service\ActionService;
|
||||
use App\Service\UserService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
class UserOrganizationAppService
|
||||
{
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly ActionService $actionService)
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly ActionService $actionService, private readonly Security $security, private readonly UserService $userService)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -35,9 +37,9 @@ class UserOrganizationAppService
|
|||
if (!isset($grouped[$appId])) {
|
||||
$grouped[$appId] = [
|
||||
'uoId' => $uoa->getUserOrganization()->getId(),
|
||||
'application' => $app, // you can still pass entity here
|
||||
'roles' => [], // selected roles for display
|
||||
'rolesArray' => [], // all possible roles
|
||||
'application' => $app,
|
||||
'roles' => [],
|
||||
'rolesArray' => [],
|
||||
'selectedRoleIds' => [],
|
||||
];
|
||||
}
|
||||
|
|
@ -49,11 +51,17 @@ class UserOrganizationAppService
|
|||
$grouped[$appId]['selectedRoleIds'][] = $roleEntity->getId();
|
||||
}
|
||||
|
||||
// roles are the same for all apps → load once, inject into each appGroup
|
||||
// Load all possible roles once
|
||||
$allRoles = $this->entityManager->getRepository(Roles::class)->findAll();
|
||||
|
||||
foreach ($grouped as &$appGroup) {
|
||||
foreach ($allRoles as $role) {
|
||||
// exclude SUPER ADMIN from assignable roles if current user is just ADMIN
|
||||
if ($this->security->isGranted('ROLE_ADMIN') && !$this->security->isGranted('ROLE_SUPER_ADMIN')
|
||||
&& $role->getName() === 'SUPER ADMIN') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$appGroup['rolesArray'][] = [
|
||||
'id' => $role->getId(),
|
||||
'name' => $role->getName(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue