<?php
namespace App\Access\Infrastructure\Security;
/**
* Chequeo de permisos de un rol sobre una ventana (AD_Window_Access) de iDempiere.
*
* Uso en un controlador:
* $this->denyAccessUnlessGranted(WindowAccessVoter::VIEW, $this->windowID);
* $this->denyAccessUnlessGranted(WindowAccessVoter::EDIT, $this->windowID);
*
* @author rbellorin@sumagroups.com
* @version 2026-07-02
*/
use App\Access\Application\UseCase\CheckWindowAccess;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class WindowAccessVoter extends Voter
{
public const VIEW = 'WINDOW_VIEW';
public const EDIT = 'WINDOW_EDIT';
public function __construct(
private readonly CheckWindowAccess $checkWindowAccess
) {
}
protected function supports(string $attribute, $subject): bool
{
return in_array($attribute, [self::VIEW, self::EDIT], true) && is_numeric($subject);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return ($this->checkWindowAccess)((int) $subject, $attribute === self::EDIT);
}
}