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

feat: add group owners to features #2908

Merged
merged 19 commits into from
Nov 6, 2023
Merged

Conversation

zachaysan
Copy link
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

This adds two endpoints to features. The first is to allow the addition of groups as owners of a feature. Think groups like "design department" which could have many users under them. It also allows the removal of groups through a separate, similar endpoint.

This work supports this ticket, though I would like to get feedback before implementing any filtering of features so that part of the ticket is not yet complete.

How did you test this code?

I wrote two new tests that go through the API. I was a little confused as to why the practice was to use a master key for authentication, but I kept with the normal way of doing things since that is how other parts of the codebase around that part did it.

Copy link

vercel bot commented Oct 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2023 7:26pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2023 7:26pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2023 7:26pm

@github-actions github-actions bot added the api Issue related to the REST API label Oct 31, 2023
@zachaysan zachaysan requested review from matthewelwell and a team October 31, 2023 17:35
Copy link
Contributor

github-actions bot commented Oct 31, 2023

Uffizzi Preview deployment-39890 was deleted.

api/features/serializers.py Outdated Show resolved Hide resolved
api/features/serializers.py Outdated Show resolved Hide resolved
api/tests/unit/features/test_unit_features_views.py Outdated Show resolved Hide resolved
api/features/views.py Outdated Show resolved Hide resolved
api/features/views.py Outdated Show resolved Hide resolved
api/features/serializers.py Outdated Show resolved Hide resolved
api/users/serializers.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6e6a48b) 95.63% compared to head (18197c1) 95.62%.
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2908      +/-   ##
==========================================
- Coverage   95.63%   95.62%   -0.02%     
==========================================
  Files        1011     1012       +1     
  Lines       29006    29122     +116     
==========================================
+ Hits        27741    27848     +107     
- Misses       1265     1274       +9     
Files Coverage Δ
...i/features/migrations/0060_feature_group_owners.py 100.00% <100.00%> (ø)
api/features/models.py 93.68% <100.00%> (+0.01%) ⬆️
api/features/permissions.py 82.35% <ø> (ø)
api/features/serializers.py 95.76% <100.00%> (+0.16%) ⬆️
api/features/views.py 86.37% <100.00%> (+0.92%) ⬆️
api/import_export/export.py 100.00% <ø> (ø)
...pi/tests/unit/features/test_unit_features_views.py 100.00% <100.00%> (ø)
api/users/serializers.py 93.33% <100.00%> (ø)
api/users/views.py 91.21% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 171 to 178
if not UserPermissionGroup.objects.filter(
id__in=data["group_ids"],
organisation_id=feature.project.organisation_id,
).count() == len(data["group_ids"]):
raise serializers.ValidationError("Some groups not found")

serializer = FeatureGroupOwnerInputSerializer(data=data)
serializer.is_valid(raise_exception=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should just switch these around since, otherwise, if someone posts an empty body (or any body missing the group_ids key) we would throw a 500 instead of, in the code below, a 400 explaining what the issue is.

Suggested change
if not UserPermissionGroup.objects.filter(
id__in=data["group_ids"],
organisation_id=feature.project.organisation_id,
).count() == len(data["group_ids"]):
raise serializers.ValidationError("Some groups not found")
serializer = FeatureGroupOwnerInputSerializer(data=data)
serializer.is_valid(raise_exception=True)
serializer = FeatureGroupOwnerInputSerializer(data=data)
serializer.is_valid(raise_exception=True)
if not UserPermissionGroup.objects.filter(
id__in=serializer.validated_data["group_ids"],
organisation_id=feature.project.organisation_id,
).count() == len(serializer.validated_data["group_ids"]):
raise serializers.ValidationError("Some groups not found")

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, the diff looks bad, but all I've done is switched the serializer validation and the ORM validation around (and used serializer.validated_data instead of data["group_ids"])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok cool, I see what you're going for. I've updated the PR with the changes.

Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

One minor nitpick but I've approved anyway.

if not UserPermissionGroup.objects.filter(
id__in=serializer.validated_data["group_ids"],
organisation_id=feature.project.organisation_id,
).count() == len(data["group_ids"]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
).count() == len(data["group_ids"]):
).count() == len(serializer.validated_data["group_ids"]):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Blast! I've committed the fix. (Not sure what black, etc would do if I use the GH interface)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants