-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Fixes #13994] fix fecet count coherent with the visible resources on 5.0.x #14012
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
base: 5.0.x
Are you sure you want to change the base?
Changes from all commits
57ac6f7
d3836ee
cee5b30
47f4680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -131,3 +131,33 @@ def filter_queryset(self, request, queryset, _): | |||||||||||||||||||
| _filter["id__in"] = [_facet.id for _facet in queryset if not _facet.resourcebase_set.exists()] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return queryset.filter(**_filter) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class AdvertisedFilter(BaseFilterBackend): | ||||||||||||||||||||
| def filter_queryset(self, request, queryset, view): | ||||||||||||||||||||
| # advertised | ||||||||||||||||||||
| # if superuser, all resources will be visible, otherwise only the advertised one and | ||||||||||||||||||||
| # the resource which the user is owner will be returned | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if getattr(view, "action", None) == "retrieve": | ||||||||||||||||||||
| return queryset | ||||||||||||||||||||
|
|
||||||||||||||||||||
| user = request.user | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| _filter = request.query_params.get("advertised", "None") | ||||||||||||||||||||
| advertised = strtobool(_filter) if _filter.lower() != "all" else "all" | ||||||||||||||||||||
| except Exception: | ||||||||||||||||||||
| advertised = None | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if advertised == "all": | ||||||||||||||||||||
| pass | ||||||||||||||||||||
| elif advertised is not None: | ||||||||||||||||||||
| queryset = queryset.filter(advertised=advertised) | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| 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) | ||||||||||||||||||||
|
Comment on lines
+157
to
+161
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conditional logic for filtering based on user authentication and admin status can be simplified for better readability and maintainability. The
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| return queryset | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for parsing the
advertisedquery parameter can be made more explicit and robust. Using a broadexcept Exceptioncan hide unexpected errors by catching more than justValueErrorfromstrtoboolandAttributeErrorif the parameter is missing. A clearer approach would be to handle the absence of the parameter separately and then parse its value.