Skip to content

Commit

Permalink
fix: Add group owners to missing endpoint (#3080)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan authored Dec 1, 2023
1 parent af55fe3 commit 8fe2ea7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion api/features/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -126,6 +126,7 @@ class Meta:
"multivariate_options",
"is_archived",
"owners",
"group_owners",
"uuid",
"project",
"num_segment_overrides",
Expand Down
2 changes: 1 addition & 1 deletion api/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 40 additions & 2 deletions api/tests/unit/features/test_unit_features_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

3 comments on commit 8fe2ea7

@vercel
Copy link

@vercel vercel bot commented on 8fe2ea7 Dec 1, 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.com
docs-flagsmith.vercel.app
docs.bullet-train.io

@vercel
Copy link

@vercel vercel bot commented on 8fe2ea7 Dec 1, 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 8fe2ea7 Dec 1, 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.