fix: Allow PDF access for users with recommended vehicles
This commit is contained in:
@@ -1836,7 +1836,7 @@ async def get_car_performance_check_pdf(
|
|||||||
if not performance_check.pdf_path:
|
if not performance_check.pdf_path:
|
||||||
raise HTTPException(status_code=404, detail="PDF not available for this car")
|
raise HTTPException(status_code=404, detail="PDF not available for this car")
|
||||||
|
|
||||||
# Check access (admin, purchased performance check, or purchased car view)
|
# Check access (admin, purchased performance check, purchased car view, or recommended vehicle)
|
||||||
has_access = False
|
has_access = False
|
||||||
if current_user.is_admin:
|
if current_user.is_admin:
|
||||||
has_access = True
|
has_access = True
|
||||||
@@ -1853,7 +1853,14 @@ async def get_car_performance_check_pdf(
|
|||||||
CarView.car_id == car_id
|
CarView.car_id == car_id
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
has_access = (existing_perf_view is not None) or (existing_car_view is not None)
|
# Check 3: Car was recommended to user via vehicle request
|
||||||
|
recommended_vehicle = db.query(RequestVehicle).join(VehicleRequest).filter(
|
||||||
|
VehicleRequest.user_id == current_user.id,
|
||||||
|
RequestVehicle.car_id == car_id,
|
||||||
|
RequestVehicle.is_approved == True
|
||||||
|
).first()
|
||||||
|
|
||||||
|
has_access = (existing_perf_view is not None) or (existing_car_view is not None) or (recommended_vehicle is not None)
|
||||||
|
|
||||||
if not has_access:
|
if not has_access:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
Reference in New Issue
Block a user