app/Service/Security/Voter/InWorkspace/CreateInWorkspaceVoter.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 CreateInWorkspaceVoter extends AbstractInWorkspaceVoter
  8. {
  9.     protected function getSupportedAttributeName(): string
  10.     {
  11.         return SecurityAttributes::CREATE;
  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.             return in_array($role$allowedRolestrue);
  31.         }
  32.         return null;
  33.     }
  34.     protected function isAllowedWhenImpersonating(): bool
  35.     {
  36.         return false;
  37.     }
  38. }