Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue retrieving project with master api key #2623

Merged
merged 1 commit into from
Aug 10, 2023
Merged
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
21 changes: 12 additions & 9 deletions api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ def get_queryset(self):
else:
queryset = self.request.user.get_permitted_projects(
permission_key=VIEW_PROJECT
).annotate(
)

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(
total_features=Count(
"features",
filter=Q(features__deleted_at__isnull=True),
Expand All @@ -102,14 +113,6 @@ 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: 11 additions & 6 deletions api/tests/unit/projects/test_unit_projects_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -8,8 +9,10 @@
PROJECT_NAME = "Test project"


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

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

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


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

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

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