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 endpoints for feature imports #3255

Merged
merged 14 commits into from
Jan 17, 2024

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 added information to docs/ if required so people know about the feature!
  • 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

Introduce two new endpoints to support ongoing feature imports. One is a list the other is a retrieve. These were initially going to be as part of the same viewset, but the router differences got in the way and so it was more straightforward to split the functionality apart, since the list view relies on the project_pk nested part of the router.

How did you test this code?

Four new tests, all of which are simple.

Copy link

vercel bot commented Jan 8, 2024

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 Jan 10, 2024 5:12pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2024 5:12pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2024 5:12pm

Copy link
Contributor

github-actions bot commented Jan 8, 2024

Uffizzi Preview deployment-43983 was deleted.

Comment on lines 134 to 156
class FeatureImportViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
serializer_class = FeatureImportSerializer
permission_classes = [FeatureImportListPermissions]

def get_queryset(self) -> QuerySet[FeatureImport]:
environment_ids = []
user = self.request.user

for environment in Environment.objects.filter(
project_id=self.kwargs["project_pk"],
):
if user.is_environment_admin(environment):
environment_ids.append(environment.id)

return FeatureImport.objects.filter(environment__in=environment_ids).order_by(
"-created_at"
)


class FeatureImportRetrieve(viewsets.GenericViewSet, mixins.RetrieveModelMixin):
serializer_class = FeatureImportSerializer
permission_classes = [FeatureImportRetrievePermissions]
queryset = FeatureImport.objects.all()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're only including one action on each of these viewsets, perhaps we should just use standard APIView classes? ListAPIView / RetrieveAPIView I mean.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about it, I'm not sure why we don't just combine them? I get that in one we have the object to do the permission check, but I don't really see how it's better than just filtering out in the queryset (which would essentially have the same effect as the get_object_or_404 that I suggested above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From our discussion on slack: Switch to just using the List and used the ListAPIView as mentioned.

@codecov-commenter
Copy link

Codecov Report

Attention: 61 lines in your changes are missing coverage. Please review.

Comparison is base (6500451) 95.95% compared to head (e7cb58d) 37.26%.
Report is 6 commits behind head on main.

Files Patch % Lines
...ature_segments/test_unit_feature_segments_views.py 0.00% 23 Missing ⚠️
...pi/tests/unit/features/test_unit_features_views.py 0.00% 15 Missing ⚠️
...sioning/test_unit_versioning_versioning_service.py 0.00% 8 Missing ⚠️
api/features/feature_segments/views.py 33.33% 4 Missing ⚠️
api/features/import_export/tasks.py 60.00% 4 Missing ⚠️
api/features/import_export/permissions.py 85.71% 1 Missing ⚠️
api/features/versioning/versioning_service.py 66.66% 1 Missing ⚠️
...ronments/identities/test_integration_identities.py 0.00% 1 Missing ⚠️
...ities/test_unit_identities_feature_states_views.py 0.00% 1 Missing ⚠️
...nts/test_unit_environments_feature_states_views.py 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3255       +/-   ##
===========================================
- Coverage   95.95%   37.26%   -58.69%     
===========================================
  Files        1067      999       -68     
  Lines       32649    29265     -3384     
===========================================
- Hits        31327    10907    -20420     
- Misses       1322    18358    +17036     

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

@zachaysan zachaysan added this pull request to the merge queue Jan 17, 2024
Merged via the queue into main with commit a2eeaf4 Jan 17, 2024
@zachaysan zachaysan deleted the feat/add_endpoints_for_feature_imports branch January 17, 2024 16:32
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.

3 participants