wip: initial commit

This commit is contained in:
Björn Fromme
2024-11-20 18:32:09 +01:00
parent ae964198e9
commit d4c4e69d09
91 changed files with 32685 additions and 144 deletions
+45
View File
@@ -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();
}
}