src/Access/Infrastructure/Security/WindowAccessVoter.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Access\Infrastructure\Security;
  3. /**
  4. * Chequeo de permisos de un rol sobre una ventana (AD_Window_Access) de iDempiere.
  5. *
  6. * Uso en un controlador:
  7. * $this->denyAccessUnlessGranted(WindowAccessVoter::VIEW, $this->windowID);
  8. * $this->denyAccessUnlessGranted(WindowAccessVoter::EDIT, $this->windowID);
  9. *
  10. * @author rbellorin@sumagroups.com
  11. * @version 2026-07-02
  12. */
  13. use App\Access\Application\UseCase\CheckWindowAccess;
  14. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  15. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  16. class WindowAccessVoter extends Voter
  17. {
  18. public const VIEW = 'WINDOW_VIEW';
  19. public const EDIT = 'WINDOW_EDIT';
  20. public function __construct(
  21. private readonly CheckWindowAccess $checkWindowAccess
  22. ) {
  23. }
  24. protected function supports(string $attribute, $subject): bool
  25. {
  26. return in_array($attribute, [self::VIEW, self::EDIT], true) && is_numeric($subject);
  27. }
  28. protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
  29. {
  30. return ($this->checkWindowAccess)((int) $subject, $attribute === self::EDIT);
  31. }
  32. }