src/Security/Voter/Analyse/MissionplanVoter.php line 14
<?php
namespace App\Security\Voter\Analyse;
use App\ApiResource\TimeTracking\Presence;
use App\Entity\Customer\Settings;
use App\Repository\Customer\SettingsRepository;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bundle\SecurityBundle\Security;
class MissionplanVoter extends Voter
{
final public const VIEW = 'MP_ENTITY_VIEW';
public function __construct(
private readonly Security $security, private readonly SettingsRepository $settingsRepository)
{
}
protected function supports(string $attribute, mixed $subject): bool
{
if(!in_array($attribute, [self::VIEW])){
return false;
}
return true;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
return false;
}
if (!$this->security->isGranted('ROLE_STAFF')){
return false;
}
// ... (check conditions and return true to grant permission) ...
return match($attribute) {
self::VIEW => $this->canView(),
default => throw new \LogicException('This code should not be reached!')
};
}
private function canView(): bool
{
$settings = $this->settingsRepository->getByKey("staff_plan_print");
if ($settings->getMetaValueString() == "1") {
return true;
}
return false;
}
}