Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions backend/apps/ifc_validation_bff/views_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,26 @@ def report(request, id: str):
if not user:
return create_redirect_response(login=True)

# return 404-NotFound if report is not for current user or if it is deleted
request = ValidationRequest.objects.filter(created_by__id=user.id, deleted=False, id=ValidationRequest.to_private_id(id)).first()
# resolve by request id or model id
if id.startswith("r"):
priv_id = ValidationRequest.to_private_id(id)

elif id.startswith("m"):
model_id = Model.to_private_id(id)
priv_id = (
ValidationRequest.objects.filter(model_id=model_id)
.values_list("id", flat=True)
.first()
)

if not priv_id:
return HttpResponseNotFound()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code only creates priv_id when the id starts with r or m, so any other id (like t42 or whatever) reaches 'if not priv_id). This doesn't exist or can't convert to an integer and crashes with a 500 error. Adding else: return HttpResponseNotFound() and try/except makes those ids get 404 instead.

Suggested change
if id.startswith("r"):
priv_id = ValidationRequest.to_private_id(id)
elif id.startswith("m"):
model_id = Model.to_private_id(id)
priv_id = (
ValidationRequest.objects.filter(model_id=model_id)
.values_list("id", flat=True)
.first()
)
if not priv_id:
return HttpResponseNotFound()
try:
if id.startswith("r"):
priv_id = ValidationRequest.to_private_id(id)
elif id.startswith("m"):
model_id = Model.to_private_id(id)
priv_id = (
ValidationRequest.objects.filter(model_id=model_id)
.values_list("id", flat=True)
.first()
)
else:
return HttpResponseNotFound()
except ValueError:
return HttpResponseNotFound()
if not priv_id:
return HttpResponseNotFound()


# return 404-NotFound if report is not for current user or if it is deleted; still allowed for staff users
if not user.is_staff:
request = ValidationRequest.objects.filter(created_by__id=user.id, deleted=False, id=priv_id).first()
else:
request = ValidationRequest.objects.filter(id=priv_id).first()
if not request:
return HttpResponseNotFound()

Expand Down
Loading