vendor/nellapp/sdk-bundle/src/Permission/Security/Voter/ChannelUserMenuVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Permission\Security\Voter;
  3. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
  4. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  5. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\AdminChannelUserDataInterface;
  6. use Nellapp\Bundle\SDKBundle\Menu\Enum\ChannelMenuEnum;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. class ChannelUserMenuVoter extends Voter
  10. {
  11.     public function supportsType(string $subjectType): bool
  12.     {
  13.         return is_subclass_of($subjectTypeChannelInterface::class);
  14.     }
  15.     public function supportsAttribute(string $attribute): bool
  16.     {
  17.         return in_array($attributeChannelMenuEnum::getChoices());
  18.     }
  19.     protected function supports(string $attribute$subject): bool
  20.     {
  21.         return $this->supportsType($subject::class) && $this->supportsAttribute($attribute);
  22.     }
  23.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  24.     {
  25.         $user $token->getUser();
  26.         if (!$user instanceof UserInterface) {
  27.             return false;
  28.         }
  29.         $channelUserData $user->getChannelUserDataByChannel($subject);
  30.         if (!$channelUserData instanceof AdminChannelUserDataInterface || !$channelUserData->isActive()) {
  31.             return false;
  32.         }
  33.         return in_array($attribute$channelUserData->getDisplayedMenu() ?? []);
  34.     }
  35. }