Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Ignore bad filters on fetches to endpoints #360

Merged
merged 6 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
4 changes: 3 additions & 1 deletion backend/project/endpoints/projects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def get(self, uid=None):
filters = dict(request.args)
conditions = []
for key, value in filters.items():
conditions.append(getattr(Project, key) == value)
attribute = getattr(Project, key, None)
if attribute:
conditions.append(getattr(Project, key) == value)

# Get the projects
projects = Project.query
Expand Down
9 changes: 3 additions & 6 deletions backend/project/endpoints/submissions/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ def get(self, uid=None) -> dict[str, any]:
}
filters = dict(request.args)
try:
invalid_parameters = set(filters.keys()) - {"uid", "project_id"}
if invalid_parameters:
data["message"] = f"Invalid query parameter(s) {invalid_parameters}"
return data, 400

# Check the uid query parameter
user_id = filters.get("uid")
if user_id and not isinstance(user_id, str):
Expand All @@ -73,7 +68,9 @@ def get(self, uid=None) -> dict[str, any]:
# Filter the courses based on the query parameters
conditions = []
for key, value in filters.items():
conditions.append(getattr(Submission, key) == value)
attribute = getattr(Submission, key, None)
if attribute:
conditions.append(getattr(Submission, key) == value)

# Get the submissions
submissions = Submission.query
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/endpoints/submissions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_get_submission_wrong_parameter(self, client: FlaskClient):
"/submissions?parameter=0",
headers = {"X-CSRF-TOKEN":get_csrf_from_login(client, "teacher")}
)
assert response.status_code == 400
assert response.status_code == 200



Expand Down