Skip to content

Commit

Permalink
Revert "fix: issue retrieving project with master api key (#2623)"
Browse files Browse the repository at this point in the history
This reverts commit 1514bf7.
  • Loading branch information
matthewelwell committed Aug 10, 2023
1 parent ca2ce04 commit 041aebe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
21 changes: 9 additions & 12 deletions api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,7 @@ def get_queryset(self):
else:
queryset = self.request.user.get_permitted_projects(
permission_key=VIEW_PROJECT
)

organisation_id = self.request.query_params.get("organisation")
if organisation_id:
queryset = queryset.filter(organisation__id=organisation_id)

project_uuid = self.request.query_params.get("uuid")
if project_uuid:
queryset = queryset.filter(uuid=project_uuid)

if self.action == "retrieve":
queryset = queryset.annotate(
).annotate(
total_features=Count(
"features",
filter=Q(features__deleted_at__isnull=True),
Expand All @@ -113,6 +102,14 @@ def get_queryset(self):
),
)

organisation_id = self.request.query_params.get("organisation")
if organisation_id:
queryset = queryset.filter(organisation__id=organisation_id)

project_uuid = self.request.query_params.get("uuid")
if project_uuid:
queryset = queryset.filter(uuid=project_uuid)

return queryset

def perform_create(self, serializer):
Expand Down
17 changes: 6 additions & 11 deletions api/tests/unit/projects/test_unit_projects_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from django.urls import reverse
from pytest_lazyfixture import lazy_fixture
from rest_framework import status

from projects.models import Project
Expand All @@ -9,10 +8,8 @@
PROJECT_NAME = "Test project"


@pytest.mark.parametrize(
"client", (lazy_fixture("admin_client"), lazy_fixture("master_api_key_client"))
)
def test_get_project_list_data(client, organisation):
@pytest.mark.django_db
def test_get_project_list_data(admin_client, organisation):
# Given
hide_disabled_flags = False
enable_dynamo_db = False
Expand All @@ -31,7 +28,7 @@ def test_get_project_list_data(client, organisation):
)

# When
response = client.get(list_url)
response = admin_client.get(list_url)

# Then
assert response.status_code == status.HTTP_200_OK
Expand All @@ -51,10 +48,8 @@ def test_get_project_list_data(client, organisation):
assert "total_segments" not in response.json()[0].keys()


@pytest.mark.parametrize(
"client", (lazy_fixture("admin_client"), lazy_fixture("master_api_key_client"))
)
def test_get_project_data_by_id(client, organisation):
@pytest.mark.django_db
def test_get_project_data_by_id(admin_client, organisation):
# Given
project = Project.objects.create(
name=PROJECT_NAME,
Expand All @@ -63,7 +58,7 @@ def test_get_project_data_by_id(client, organisation):
url = reverse("api-v1:projects:project-detail", args=[project.id])

# When
response = client.get(url)
response = admin_client.get(url)

# Then
assert response.status_code == status.HTTP_200_OK
Expand Down

0 comments on commit 041aebe

Please sign in to comment.