<?php
declare(strict_types=1);
namespace App\Bundles\ReportBundle\Security;
use App\Bundles\UserBundle\Entity\User;
use App\Bundles\UserBundle\Enum\SystemPermissionEnum;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
class ReportTemplateDeleteVoter extends Voter
{
public function __construct(private readonly Security $security)
{
}
protected function supports(string $attribute, $subject): bool
{
return $attribute === SystemPermissionEnum::SINGLE_REPORT_TEMPLATE_DELETE->value;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
/** @var User $user */
$user = $this->security->getUser();
return $subject->getUser() === $user;
}
}