src/Security/Voter/Permissions/Admin/AdminPortalVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\Permissions\Admin;
  3. use App\Helper\Common\CommonHelper;
  4. use App\Models\Heimdall\Profile;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. class AdminPortalVoter extends AdminVoter
  7. {
  8.     protected function supports($attribute$subject): bool
  9.     {
  10.         if (!in_array($attribute, [Profile::PROFILE_SUPER_ADMINProfile::PROFILE_ADMIN_SERVICEProfile::PROFILE_ADMIN_USER])) {
  11.             return false;
  12.         }
  13.         return is_string($subject) && !CommonHelper::isUuid($subject);
  14.     }
  15.     protected function getUserProfiles(UserInterface $userstring $entityId): array
  16.     {
  17.         $heimdallUser $this->userManager->findUser($user->getUsername());
  18.         $userProfiles $this->userProfileManager->getUserProfiles($heimdallUser);
  19.         return array_filter(
  20.             $userProfiles,
  21.             fn ($userProfile) => in_array($entityId$userProfile->getPortals())
  22.         );
  23.     }
  24. }