fix: adopt multiple hotel codes
This commit is contained in:
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Security\Voter;
|
namespace App\Security\Voter;
|
||||||
|
|
||||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
|
||||||
use App\BusProNet\Model\Hotel;
|
|
||||||
use App\Entity\Disposition;
|
use App\Entity\Disposition;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
@@ -19,10 +17,8 @@ class DispositionVoter extends Voter
|
|||||||
public const INVOICE = 'INVOICE';
|
public const INVOICE = 'INVOICE';
|
||||||
public const FEEDBACK = 'FEEDBACK';
|
public const FEEDBACK = 'FEEDBACK';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(private readonly Security $security)
|
||||||
private readonly Security $security,
|
{
|
||||||
private readonly HotelDataProvider $hotelDataProvider
|
|
||||||
) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function supports(string $attribute, mixed $subject): bool
|
protected function supports(string $attribute, mixed $subject): bool
|
||||||
@@ -70,15 +66,15 @@ class DispositionVoter extends Voter
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$userHotelCode = $token->getUser()->getHotelCode();
|
/** @var User $user */
|
||||||
|
$user = $token->getUser();
|
||||||
|
|
||||||
$destination = $disposition
|
$destination = $disposition
|
||||||
->getAssignment()
|
->getAssignment()
|
||||||
->getDestination()
|
->getDestination()
|
||||||
;
|
;
|
||||||
|
|
||||||
$isMatchingHotel = str_starts_with($destination->getHotelCode(), $userHotelCode)
|
$isMatchingHotel = $user->hasHotelCodeMatch($destination->getHotelCode());
|
||||||
|| str_ends_with($destination->getHotelCode(), $userHotelCode);
|
|
||||||
$isPast = $destination->getDateTo() < new \DateTimeImmutable();
|
$isPast = $destination->getDateTo() < new \DateTimeImmutable();
|
||||||
|
|
||||||
return $isMatchingHotel && $isPast;
|
return $isMatchingHotel && $isPast;
|
||||||
|
|||||||
Reference in New Issue
Block a user