mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-01 10:59:45 +00:00
Revert "Merge branch 'revert-671bb6d5' into 'master'"
This reverts merge request !732
This commit is contained in:
@@ -11,9 +11,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Security\Voter;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Entity\CalendarDoc;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class CalendarDocVoter extends Voter
|
||||
@@ -27,24 +29,29 @@ class CalendarDocVoter extends Voter
|
||||
'CHILL_CALENDAR_DOC_SEE',
|
||||
];
|
||||
|
||||
public function __construct(private readonly Security $security)
|
||||
{
|
||||
}
|
||||
public function __construct(private readonly Security $security) {}
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
{
|
||||
return \in_array($attribute, self::ALL, true) && $subject instanceof CalendarDoc;
|
||||
return \in_array($attribute, self::ALL, true) && ($subject instanceof CalendarDoc || $subject instanceof Calendar);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CalendarDoc $subject
|
||||
*/
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
return match ($attribute) {
|
||||
self::EDIT => $this->security->isGranted(CalendarVoter::EDIT, $subject->getCalendar()),
|
||||
self::SEE => $this->security->isGranted(CalendarVoter::SEE, $subject->getCalendar()),
|
||||
default => throw new \UnexpectedValueException('Attribute not supported: '.$attribute),
|
||||
};
|
||||
if ($subject instanceof Calendar) {
|
||||
return match ($attribute) {
|
||||
self::EDIT => $this->security->isGranted(CalendarVoter::EDIT, $subject),
|
||||
self::SEE => $this->security->isGranted(CalendarVoter::SEE, $subject),
|
||||
default => throw new LogicException('attribute not supported for this Voter'),
|
||||
};
|
||||
} elseif ($subject instanceof CalendarDoc) {
|
||||
return match ($attribute) {
|
||||
self::EDIT => $this->security->isGranted(CalendarVoter::EDIT, $subject->getCalendar()),
|
||||
self::SEE => $this->security->isGranted(CalendarVoter::SEE, $subject->getCalendar()),
|
||||
default => throw new \UnexpectedValueException('Attribute not supported: '.$attribute),
|
||||
};
|
||||
}
|
||||
|
||||
throw new LogicException('Subject not supported for this Voter');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user