<?php
namespace App\Security\Voter;
use App\Entity\Demand;
use Symfony\Component\Security\Core\User\UserInterface;
class DemandVoter extends AbstractDeepVoter
{
public const TRANSFER = 'transfer';
public static $listAttribute = 'list_demands';
protected function listAttribute(): string
{
return self::$listAttribute;
}
protected function createAttribute(): string
{
return 'none';
}
protected function supports($attribute, $subject): bool
{
return parent::supports($attribute, $subject)
|| self::TRANSFER === $attribute
;
}
protected function isSupportedSubject(object $subject): bool
{
return $subject instanceof Demand;
}
protected function canList(UserInterface $user): bool
{
return $user->isFirstLevelOrLower()
|| $user->isAnAdmin()
;
}
protected function canCreate(UserInterface $user): bool
{
return false;
}
protected function canRead(UserInterface $user): bool
{
return $user->isFirstLevelOrLower()
|| $user->isAnAdmin()
;
}
protected function canUpdate(UserInterface $user): bool
{
return $user->isCompanyDirector()
|| $user->isMainAdmin()
;
}
protected function canDelete(UserInterface $user): bool
{
return $user->isMainAdmin();
}
protected function additionalActions(string $attribute, UserInterface $user): bool
{
if (self::TRANSFER === $attribute
&& $user->isFirstLevelOrLower()
) {
return true;
}
return false;
}
}