<?php
declare(strict_types=1);
namespace Harmonizely\User\Voter;
use Harmonizely\Model\User;
use Harmonizely\Model\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
final class DeleteUserVoter extends Voter
{
public const DELETE_USER = 'delete_user';
protected function supports($attribute, $subject): bool
{
if (self::DELETE_USER !== $attribute) {
return false;
}
if (false === $subject instanceof UserInterface) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
/** @var User $subject */
/** @var UserInterface $loggedInUser */
$loggedInUser = $token->getUser();
return $loggedInUser->getId() === $subject->getId() && !$loggedInUser->isOnlySsoUser();
}
}