refs #423. Updated Voter secutiry into ORganizationalUnit
parent
43099c6bcc
commit
e727e6caa8
|
@ -10,7 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
#[Get(shortName: 'Menu')]
|
#[Get(shortName: 'Menu')]
|
||||||
final class MenuOutput extends AbstractOutput
|
final class MenuOutput extends AbstractOutput
|
||||||
{
|
{
|
||||||
#[Groups(['menu:read'])]
|
#[Groups(['menu:read', 'organizational-unit:read'])]
|
||||||
public string $name;
|
public string $name;
|
||||||
|
|
||||||
#[Groups(['menu:read'])]
|
#[Groups(['menu:read'])]
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Security\Voter;
|
||||||
use App\Dto\Output\OrganizationalUnitOutput;
|
use App\Dto\Output\OrganizationalUnitOutput;
|
||||||
use App\Entity\OrganizationalUnit;
|
use App\Entity\OrganizationalUnit;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use App\Model\UserGroupPermissions;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
@ -24,11 +25,15 @@ class OrganizationalUnitVoter extends Voter
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $token->getUser();
|
$user = $token->getUser();
|
||||||
|
|
||||||
// if the user is anonymous, do not grant access
|
|
||||||
if (!$user instanceof UserInterface) {
|
if (!$user instanceof UserInterface) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array(UserGroupPermissions::ROLE_SUPER_ADMIN, $user->getRoles())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($attribute === 'ORGANIZATIONAL_UNIT_VIEW' ) {
|
if ($attribute === 'ORGANIZATIONAL_UNIT_VIEW' ) {
|
||||||
foreach ($user->getAllowedOrganizationalUnits() as $allowedOrganizationalUnit) {
|
foreach ($user->getAllowedOrganizationalUnits() as $allowedOrganizationalUnit) {
|
||||||
if ($allowedOrganizationalUnit->getId() === $subject->getEntity()->getId()) {
|
if ($allowedOrganizationalUnit->getId() === $subject->getEntity()->getId()) {
|
||||||
|
|
Loading…
Reference in New Issue