<?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 AccountingTurnoverVoter extends Voter
{
const COMPANY_LIST = "ACCOUNTING_TURNOVER_COMPANY_LIST";
const PARTNER_LIST = "ACCOUNTING_TURNOVER_PARTNER_LIST";
const SELLER_LIST = "ACCOUNTING_TURNOVER_SELLER_LIST";
const INSURANCE_LIST = "ACCOUNTING_TURNOVER_INSURANCE_LIST";
const ADDITIONAL_SERVICES_LIST = "ACCOUNTING_TURNOVER_ADDITIONAL_SERVICES_LIST";
const QUOTE_ANALYSIS_LIST = "ACCOUNTING_TURNOVER_QUOTE_ANALYSIS_LIST";
const PROSPECT_REQUEST_ANALYSIS_LIST = "ACCOUNTING_TURNOVER_PROSPECT_REQUEST_ANALYSIS_LIST";
const SELLER_SHOW_ALL_SELLERS = "ACCOUNTING_TURNOVER_SELLER_SHOW_ALL_SELLERS";
protected function supports($attribute, $subject): bool
{
return in_array($attribute, [
self::COMPANY_LIST,
self::PARTNER_LIST,
self::SELLER_LIST,
self::INSURANCE_LIST,
self::ADDITIONAL_SERVICES_LIST,
self::PROSPECT_REQUEST_ANALYSIS_LIST,
self::QUOTE_ANALYSIS_LIST,
self::SELLER_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());
}
}