<?php
namespace App\Voter\__Accounting;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class AccountingSellingVoter extends Voter
{
const COMPANY_SALE_LIST = "ACCOUNTING_SELLING_COMPANY_SALE_LIST";
const COMPANY_SALE_SHOW_ALL_SELLERS = "ACCOUNTING_SELLING_COMPANY_SALE_SHOW_ALL_SELLERS";
const PARTNER_SALE_LIST = "ACCOUNTING_SELLING_PARTNER_SALE_LIST";
const PARTNER_SALE_SHOW_ALL_SELLERS = "ACCOUNTING_SELLING_PARTNER_SALE_SHOW_ALL_SELLERS";
const SELLER_SALE_LIST = "ACCOUNTING_SELLING_SELLER_SALE_LIST";
const SELLER_SALE_SHOW_ALL_SELLERS = "ACCOUNTING_SELLING_SELLER_SALE_SHOW_ALL_SELLERS";
const CABIN_SALE_LIST = "ACCOUNTING_SELLING_CABIN_SALE_LIST";
const CABIN_SALE_SHOW_ALL_SELLERS = "ACCOUNTING_SELLING_CABIN_SALE_SHOW_ALL_SELLERS";
protected function supports($attribute, $subject): bool
{
return in_array($attribute, [
self::COMPANY_SALE_LIST,
self::COMPANY_SALE_SHOW_ALL_SELLERS,
self::PARTNER_SALE_LIST,
self::PARTNER_SALE_SHOW_ALL_SELLERS,
self::SELLER_SALE_LIST,
self::SELLER_SALE_SHOW_ALL_SELLERS,
self::CABIN_SALE_LIST,
self::CABIN_SALE_SHOW_ALL_SELLERS,
]);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$loggedUser = $token->getUser();
if (!$loggedUser instanceof UserInterface) {
return false;
}
return in_array($attribute, $loggedUser->getRoles());
}
}