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; namespace App\Security\Voter;
use App\BusProNet\Model\Booking; 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\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter; 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 protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{ {
/** @var User $bpnUser */ /** @var User $user */
$bpnUser = $token->getUser(); $user = $token->getUser();
if (null === $bpnUser) { if (null === $user) {
return false; return false;
} }
/** @var Booking $booking */ /** @var Booking $booking */
$booking = $subject; $booking = $subject;
if ($booking->applicant->personId !== $bpnUser->getPersonId()) { if ($booking->applicant->personId !== $user->getPersonId()) {
return false; return false;
} }
if (static::VIEW === $attribute) {
return true;
}
return $booking->isEditable(); return $booking->isEditable();
} }
} }