Add a mention on next calendars on search results

This commit is contained in:
2022-07-01 18:01:42 +02:00
parent 3dcec5d44a
commit 8bbd3b01d9
7 changed files with 79 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Security\Voter;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
@@ -23,6 +24,12 @@ use Symfony\Component\Security\Core\Security;
class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
public const CREATE = 'CHILL_CALENDAR_CALENDAR_CREATE';
public const DELETE = 'CHILL_CALENDAR_CALENDAR_DELETE';
public const EDIT = 'CHILL_CALENDAR_CALENDAR_EDIT';
public const SEE = 'CHILL_CALENDAR_CALENDAR_SEE';
private Security $security;
@@ -37,6 +44,7 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
$this->voterHelper = $voterHelperFactory
->generate(self::class)
->addCheckFor(AccompanyingPeriod::class, [self::SEE])
->addCheckFor(Calendar::class, [self::SEE, self::CREATE, self::EDIT, self::DELETE])
->build();
}
@@ -77,6 +85,18 @@ class CalendarVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
default:
throw new LogicException('subject not implemented');
}
} elseif ($subject instanceof Calendar) {
if (null !== $period = $subject->getAccompanyingPeriod()) {
switch ($attribute) {
case self::SEE:
case self::EDIT:
case self::CREATE:
return $this->security->isGranted(AccompanyingPeriodVoter::SEE, $period);
case self::DELETE:
return $this->security->isGranted(AccompanyingPeriodVoter::EDIT, $period);
}
}
}
throw new LogicException('attribute not implemented');