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: Add group owners to missing endpoint #3080

Merged
merged 4 commits into from
Dec 1, 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
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