src/Security/Voter/Permissions/Admin/AdminOrganizationVoter.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\Permissions\Admin;
  3. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. class AdminOrganizationVoter extends AdminVoter
  6. {
  7.     /** @todo: Documentation on relations on user profiles */
  8.     protected function getUserProfiles(UserInterface $userstring $organizationId): array
  9.     {
  10.         $heimdallUser $this->userManager->findUser($user->getUsername());
  11.         $userProfiles $this->userProfileManager->getUserProfiles($heimdallUser);
  12.         try {
  13.             $organization $this->organizationManager->getOrganization($organizationId);
  14.         } catch (BadRequestHttpException $e) {
  15.             $organization null;
  16.         }
  17.         $contractUserProfiles = [];
  18.         if ($organization) {
  19.             $contractId $organization->getContract(); 
  20.             $contractUserProfiles array_filter(
  21.                 $userProfiles,
  22.                 fn ($userProfile) => in_array($contractId$userProfile->getContracts())
  23.             );  
  24.         }
  25.         $organizationUserProfiles array_filter(
  26.             $userProfiles,
  27.             fn ($userProfile) => in_array(
  28.                     $organizationId,
  29.                     $userProfile->getOrganizations()
  30.                 ) || !empty($userProfile->getPortals())
  31.         );
  32.         return array_merge($organizationUserProfiles$contractUserProfiles);
  33.     }
  34. }