<?php
namespace App\Security\Authorization\Voter;
use App\Entity\PrivateUser;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ViewBackendUserVoter extends Voter
{
public const VIEW = 'view';
protected function supports($attribute, $user)
{
if (self::VIEW !== $attribute) {
return false;
}
if (!$user instanceof User) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $user, TokenInterface $token)
{
$currentUser = $token->getUser();
if ($currentUser->isGranted('ROLE_STRANGER_SALESPERSON')) {
if ($user instanceof PrivateUser) {
return false;
}
if ($user->getSalesman() !== $currentUser) {
return false;
}
}
return true;
}
}