app/Service/Security/Voter/InWorkspace/EditInWorkspaceVoter.php line 10

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Sq\Service\Security\Voter\InWorkspace;
  3. use Sq\Entity\Schema\ORM as Entity;
  4. use Sq\Entity\Schema\ORM\UserOrganizationAssignment;
  5. use Sq\Service\Security\Voter\SecurityAttributes;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. class EditInWorkspaceVoter extends AbstractInWorkspaceVoter
  8. {
  9.     protected function getSupportedAttributeName(): string
  10.     {
  11.         return SecurityAttributes::EDIT;
  12.     }
  13.     protected function getValidRolesForAttribute(): array
  14.     {
  15.         return [
  16.             UserOrganizationAssignment::ROLE_OWNER,
  17.             UserOrganizationAssignment::ROLE_ADMIN,
  18.             UserOrganizationAssignment::ROLE_EDITOR,
  19.         ];
  20.     }
  21.     protected function voteSpecificToSubjectAndRole($subjectstring $roleTokenInterface $token): ?bool
  22.     {
  23.         if ($subject instanceof Entity\PostFamilyComment)
  24.         {
  25.             if ($subject->getWorkspace()->getOrganization()->getLegacyMember()->wasLegacySignup())
  26.             {
  27.                 return false;
  28.             }
  29.             $allowedRoles array_merge($this->getValidRolesForAttribute(), [UserOrganizationAssignment::ROLE_CLIENT]);
  30.             if (!in_array($role$allowedRolestrue))
  31.             {
  32.                 return false;
  33.             }
  34.             /** @var Entity\User $loggedInUser */
  35.             $loggedInUser $token->getUser();
  36.             return $subject->getAuthor()->getId() === $loggedInUser->getId();
  37.         }
  38.         return null;
  39.     }
  40.     protected function isAllowedWhenImpersonating(): bool
  41.     {
  42.         return false;
  43.     }
  44. }