fix: match hotel codes assigned to users at beginning or end

This commit is contained in:
Björn Fromme
2025-01-06 12:22:39 +01:00
parent 5a07d95837
commit edaa294cc9
3 changed files with 14 additions and 24 deletions
@@ -43,7 +43,7 @@ class HotelDataProvider
$hotels = [];
foreach ($this->getAll() as $hotel) {
if (str_starts_with($hotel->getCode(), $code)) {
if (str_starts_with($hotel->getCode(), $code) || str_ends_with($hotel->getCode(), $code)) {
$hotels[] = $hotel;
}
}
@@ -2,7 +2,6 @@
namespace App\Controller\HouseManager;
use App\BusProNet\DataProvider\HotelDataProvider;
use App\Entity\User;
use App\Repository\DispositionRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -12,10 +11,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class IndexController extends AbstractController
{
public function __construct(
private readonly HotelDataProvider $hotelDataProvider,
private readonly DispositionRepository $dispositionRepository
) {
public function __construct(private readonly DispositionRepository $dispositionRepository)
{
}
#[Route('/house-manager', name: 'app_house_manager_index')]
@@ -25,11 +22,6 @@ class IndexController extends AbstractController
/** @var User $user */
$user = $this->getUser();
$hotels = $this
->hotelDataProvider
->findByCode($user->getHotelCode())
;
$newDispositions = $this
->dispositionRepository
->findNewDispositionsByHotelCode($user->getHotelCode())
+11 -13
View File
@@ -69,20 +69,18 @@ class DispositionVoter extends Voter
return false;
}
$hotels = $this
->hotelDataProvider
->findByCode($token->getUser()->getHotelCode())
;
$hotelBusProIds = array_map(function (Hotel $hotel) {
return $hotel->getBusProId();
}, $hotels);
$destination = $disposition
->getAssignment()
->getDestination()
;
$userHotelCode = $token->getUser()->getHotelCode();
return in_array($destination->getHotelBusProId(), $hotelBusProIds)
&& $destination->getDateTo() < new \DateTimeImmutable();
$destination = $disposition
->getAssignment()
->getDestination()
;
$isMatchingHotel = str_starts_with($destination->getHotelCode(), $userHotelCode)
|| str_ends_with($destination->getHotelCode(), $userHotelCode);
$isPast = $destination->getDateTo() < new \DateTimeImmutable();
return $isMatchingHotel && $isPast;
}
private function assertTeamerAccess(Disposition $disposition): bool