Skip to content

Commit

Permalink
fix: issue retrieving project with master api key (#2623)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Aug 10, 2023
1 parent 863c863 commit 1514bf7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
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

3 comments on commit 1514bf7

@vercel
Copy link

@vercel vercel bot commented on 1514bf7 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 1514bf7 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-git-main-flagsmith.vercel.app
docs-flagsmith.vercel.app
docs.flagsmith.com
docs.bullet-train.io

@vercel
Copy link

@vercel vercel bot commented on 1514bf7 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.