Skip to content

Commit

Permalink
[Fixes #7173] Improve the "get_visibile_reources" method: replace for…
Browse files Browse the repository at this point in the history
… loop with DB filtering
  • Loading branch information
afabiani committed Mar 28, 2021
1 parent 33c18dd commit 236fade
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ def apply_filters(self, request, applicable_filters):
else:
filtered = semi_filtered

if settings.RESOURCE_PUBLISHING or settings.ADMIN_MODERATE_UPLOADS:
filtered = self.filter_published(filtered, request)

if settings.GROUP_PRIVATE_RESOURCES:
filtered = self.filter_group(filtered, request)

if extent:
filtered = filter_bbox(filtered, extent)

Expand All @@ -239,16 +245,26 @@ def apply_filters(self, request, applicable_filters):
Q(owner__username__iexact=str(user))))
else:
filtered = filtered.exclude(Q(dirty_state=True))
return filtered

filtered = get_visible_resources(
filtered,
def filter_published(self, queryset, request):
filter_set = get_visible_resources(
queryset,
request.user if request else None,
request=request,
admin_approval_required=settings.ADMIN_MODERATE_UPLOADS,
unpublished_not_visible=settings.RESOURCE_PUBLISHING,
unpublished_not_visible=settings.RESOURCE_PUBLISHING)

return filter_set

def filter_group(self, queryset, request):
filter_set = get_visible_resources(
queryset,
request.user if request else None,
request=request,
private_groups_not_visibile=settings.GROUP_PRIVATE_RESOURCES)

return filtered
return filter_set

def filter_h_keywords(self, queryset, keywords):
treeqs = HierarchicalKeyword.objects.none()
Expand Down

0 comments on commit 236fade

Please sign in to comment.