mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-19 11:42:51 +00:00
Fixed: [calendar] refactor ACL on calendar
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CalendarBundle\Security\Voter;
|
||||
|
||||
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\Security;
|
||||
use UnexpectedValueException;
|
||||
use function in_array;
|
||||
|
||||
class CalendarDocVoter extends Voter
|
||||
{
|
||||
public const EDIT = 'CHILL_CALENDAR_DOC_EDIT';
|
||||
|
||||
public const SEE = 'CHILL_CALENDAR_DOC_SEE';
|
||||
|
||||
private const ALL = [
|
||||
'CHILL_CALENDAR_DOC_EDIT',
|
||||
'CHILL_CALENDAR_DOC_SEE',
|
||||
];
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject): bool
|
||||
{
|
||||
return in_array($attribute, self::ALL, true) && $subject instanceof CalendarDoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CalendarDoc $subject
|
||||
* @param mixed $attribute
|
||||
*/
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
|
||||
{
|
||||
switch ($attribute) {
|
||||
case self::EDIT:
|
||||
return $this->security->isGranted(CalendarVoter::EDIT, $subject->getCalendar());
|
||||
|
||||
case self::SEE:
|
||||
return $this->security->isGranted(CalendarVoter::SEE, $subject->getCalendar());
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException('Attribute not supported: ' . $attribute);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user