Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 4 additions & 0 deletions api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def get_queryset(self): # type: ignore[no-untyped-def]

organisation_id = self.request.query_params.get("organisation")
if organisation_id:
try:
int(organisation_id)
except (TypeError, ValueError):
raise ValidationError({"organisation": "Must be a valid integer."})
queryset = queryset.filter(organisation__id=organisation_id)

project_uuid = self.request.query_params.get("uuid")
Expand Down
14 changes: 14 additions & 0 deletions api/tests/unit/projects/test_unit_projects_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,20 @@ def test_list_projects__uuid_filter__returns_matching_project( # type: ignore[n
assert response.json()[0]["uuid"] == str(project.uuid)


def test_list_projects__non_numeric_organisation__returns_400( # type: ignore[no-untyped-def]
admin_client,
):
# Given
base_url = reverse("api-v1:projects:project-list")
url = f"{base_url}?organisation=A60ZG9cp5WC53RRZHDkIlUiWuAL57Jhi"

# When
response = admin_client.get(url)

# Then
assert response.status_code == status.HTTP_400_BAD_REQUEST


@pytest.mark.parametrize(
"client",
[(lazy_fixture("admin_master_api_key_client")), (lazy_fixture("admin_client"))],
Expand Down
Loading