From 041aebe76384d49a92d36b9729e3586973c6205d Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Thu, 10 Aug 2023 13:12:53 +0100 Subject: [PATCH] Revert "fix: issue retrieving project with master api key (#2623)" This reverts commit 1514bf735d670de67b847873061797608387f039. --- api/projects/views.py | 21 ++++++++----------- .../unit/projects/test_unit_projects_views.py | 17 ++++++--------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/api/projects/views.py b/api/projects/views.py index 1c11040b195b..627e45c15c52 100644 --- a/api/projects/views.py +++ b/api/projects/views.py @@ -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), @@ -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): diff --git a/api/tests/unit/projects/test_unit_projects_views.py b/api/tests/unit/projects/test_unit_projects_views.py index bfe94af39dfa..44a5f1f01659 100644 --- a/api/tests/unit/projects/test_unit_projects_views.py +++ b/api/tests/unit/projects/test_unit_projects_views.py @@ -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 @@ -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 @@ -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 @@ -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, @@ -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