vendor/nellapp/sdk-bundle/src/Developers/Security/Voter/ChannelScopeVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Developers\Security\Voter;
  3. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  4. use Nellapp\Bundle\SDKBundle\Developers\Security\Authorization\ScopeAuthorisationService;
  5. use Nellapp\Bundle\SDKBundle\GlobalGetters\Service\ConfigurationService;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  8. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  9. class ChannelScopeVoter extends Voter
  10. {
  11. public function __construct(
  12. private readonly ScopeAuthorisationService $scopeAuthorisationService,
  13. private readonly ConfigurationService $configurationService,
  14. ) {}
  15. protected function supports(mixed $attribute, mixed $subject): bool
  16. {
  17. return is_string($attribute)
  18. && str_starts_with($attribute, 'channel:')
  19. && $subject instanceof ChannelInterface;
  20. }
  21. protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
  22. {
  23. if (!$this->configurationService->getConfiguration($subject)?->isEnableDevelopersApi()) {
  24. throw new NotFoundHttpException();
  25. }
  26. return $this->scopeAuthorisationService->canAccessChannelScope($attribute, $subject);
  27. }
  28. }