wip: initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
class BookingVoter extends Voter
|
||||
{
|
||||
public const VIEW = 'VIEW';
|
||||
public const EDIT = 'EDIT';
|
||||
|
||||
public function __construct(private readonly RequestStack $requestStack)
|
||||
{
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
if (false === in_array($attribute, [self::VIEW, self::EDIT])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $subject instanceof Booking;
|
||||
}
|
||||
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||
{
|
||||
$bpnUser = $this->requestStack->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Booking $booking */
|
||||
$booking = $subject;
|
||||
|
||||
if ($booking->applicant->personId !== $bpnUser->getPersonId()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $booking->isEditable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user