From 8fe2ea7a1ca9c069a0608c91d73660920414af22 Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Fri, 1 Dec 2023 13:09:56 -0500 Subject: [PATCH] fix: Add group owners to missing endpoint (#3080) --- api/features/serializers.py | 3 +- api/features/views.py | 2 +- .../unit/features/test_unit_features_views.py | 42 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/api/features/serializers.py b/api/features/serializers.py index 6eda71a37f65..82c50f1d0652 100644 --- a/api/features/serializers.py +++ b/api/features/serializers.py @@ -101,7 +101,7 @@ class ListCreateFeatureSerializer(DeleteBeforeUpdateWritableNestedModelSerialize many=True, required=False ) owners = UserListSerializer(many=True, read_only=True) - + group_owners = UserPermissionGroupSummarySerializer(many=True, read_only=True) num_segment_overrides = serializers.SerializerMethodField( help_text="Number of segment overrides that exist for the given feature " "in the environment provided by the `environment` query parameter." @@ -126,6 +126,7 @@ class Meta: "multivariate_options", "is_archived", "owners", + "group_owners", "uuid", "project", "num_segment_overrides", diff --git a/api/features/views.py b/api/features/views.py index ac9798995c61..195ff2885d73 100644 --- a/api/features/views.py +++ b/api/features/views.py @@ -117,7 +117,7 @@ def get_queryset(self): project = get_object_or_404(accessible_projects, pk=self.kwargs["project_pk"]) queryset = project.features.all().prefetch_related( - "multivariate_options", "owners", "tags" + "multivariate_options", "owners", "tags", "group_owners" ) query_serializer = FeatureQuerySerializer(data=self.request.query_params) diff --git a/api/tests/unit/features/test_unit_features_views.py b/api/tests/unit/features/test_unit_features_views.py index 3d3b506c8bfc..b8094f728edc 100644 --- a/api/tests/unit/features/test_unit_features_views.py +++ b/api/tests/unit/features/test_unit_features_views.py @@ -1685,6 +1685,45 @@ def test_list_features_return_tags(client, project, feature): assert "tags" in feature +def test_list_features_group_owners( + staff_client: APIClient, + project: Project, + feature: Feature, + with_project_permissions: Callable[[list[str], int | None], UserProjectPermission], +) -> None: + # Given + with_project_permissions([VIEW_PROJECT]) + feature = Feature.objects.create(name="test_feature", project=project) + organisation = project.organisation + group_1 = UserPermissionGroup.objects.create( + name="Test Group", organisation=organisation + ) + group_2 = UserPermissionGroup.objects.create( + name="Second Group", organisation=organisation + ) + feature.group_owners.add(group_1.id, group_2.id) + + url = reverse("api-v1:projects:project-features-list", args=[project.id]) + + # When + response = staff_client.get(url) + + # Then + assert response.status_code == status.HTTP_200_OK + + response_json = response.json() + + feature = response_json["results"][1] + assert feature["group_owners"][0] == { + "id": group_1.id, + "name": group_1.name, + } + assert feature["group_owners"][1] == { + "id": group_2.id, + "name": group_2.name, + } + + @pytest.mark.parametrize( "client", [lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")], @@ -1721,7 +1760,6 @@ def test_get_feature_by_uuid(client, project, feature): # Then assert response.status_code == status.HTTP_200_OK - assert response.json()["id"] == feature.id assert response.json()["uuid"] == str(feature.uuid) @@ -2361,7 +2399,7 @@ def test_list_features_n_plus_1( v1_feature_state.clone(env=environment, version=i, live_from=timezone.now()) # When - with django_assert_num_queries(13): + with django_assert_num_queries(14): response = staff_client.get(url) # Then