fix: take voter attribute into account
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user