[Fixes #13994] fix fecet count coherent with the visible resources on 5.0.x#14012
[Fixes #13994] fix fecet count coherent with the visible resources on 5.0.x#14012
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where facet counts were not consistent with the resources visible to a user. It introduces a new Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to make facet counts consistent with visible resources by applying the same filters. The main change involves using the ResourceBaseViewSet to filter querysets in the facet view. A new AdvertisedFilter is also introduced to handle resource visibility based on the 'advertised' status and user permissions. My review focuses on improving the clarity and robustness of the new filter logic. I've suggested refactoring the parameter parsing to be more explicit and simplifying the conditional logic for user status checks.
| try: | ||
| _filter = request.query_params.get("advertised", "None") | ||
| advertised = strtobool(_filter) if _filter.lower() != "all" else "all" | ||
| except Exception: | ||
| advertised = None |
There was a problem hiding this comment.
The logic for parsing the advertised query parameter can be made more explicit and robust. Using a broad except Exception can hide unexpected errors by catching more than just ValueError from strtobool and AttributeError if the parameter is missing. A clearer approach would be to handle the absence of the parameter separately and then parse its value.
| try: | |
| _filter = request.query_params.get("advertised", "None") | |
| advertised = strtobool(_filter) if _filter.lower() != "all" else "all" | |
| except Exception: | |
| advertised = None | |
| _filter = request.query_params.get("advertised") | |
| if _filter is None: | |
| advertised = None | |
| else: | |
| if _filter.lower() == "all": | |
| advertised = "all" | |
| else: | |
| try: | |
| advertised = strtobool(_filter) | |
| except ValueError: | |
| advertised = None |
| is_admin = user.is_superuser if user and user.is_authenticated else False | ||
| if not is_admin and user and not user.is_anonymous: | ||
| queryset = (queryset.filter(advertised=True) | queryset.filter(owner=user)).distinct() | ||
| elif not user or user.is_anonymous: | ||
| queryset = queryset.filter(advertised=True) |
There was a problem hiding this comment.
The conditional logic for filtering based on user authentication and admin status can be simplified for better readability and maintainability. The request.user object provides boolean properties like is_authenticated and is_superuser that can make these checks more direct and remove the need for the is_admin local variable.
| is_admin = user.is_superuser if user and user.is_authenticated else False | |
| if not is_admin and user and not user.is_anonymous: | |
| queryset = (queryset.filter(advertised=True) | queryset.filter(owner=user)).distinct() | |
| elif not user or user.is_anonymous: | |
| queryset = queryset.filter(advertised=True) | |
| if not user.is_superuser and user.is_authenticated: | |
| queryset = (queryset.filter(advertised=True) | queryset.filter(owner=user)).distinct() | |
| elif not user.is_authenticated: | |
| queryset = queryset.filter(advertised=True) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 5.0.x #14012 +/- ##
========================================
Coverage ? 74.09%
========================================
Files ? 932
Lines ? 55867
Branches ? 7540
========================================
Hits ? 41396
Misses ? 12821
Partials ? 1650 🚀 New features to boost your workflow:
|
Fixes #13994
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.