fix: take voter attribute into account

This commit is contained in:
Björn Fromme
2025-04-24 20:58:05 +02:00
parent fbfe215c3d
commit 0e49a5cf99
+9 -5
View File
@@ -3,7 +3,7 @@
namespace App\Security\Voter;
use App\BusProNet\Model\Booking;
use App\BusProNet\Security\User;
use App\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
@@ -23,20 +23,24 @@ class BookingVoter extends Voter
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
/** @var User $bpnUser */
$bpnUser = $token->getUser();
/** @var User $user */
$user = $token->getUser();
if (null === $bpnUser) {
if (null === $user) {
return false;
}
/** @var Booking $booking */
$booking = $subject;
if ($booking->applicant->personId !== $bpnUser->getPersonId()) {
if ($booking->applicant->personId !== $user->getPersonId()) {
return false;
}
if (static::VIEW === $attribute) {
return true;
}
return $booking->isEditable();
}
}