refactoring duplicated code
@@ -615,27 +615,18 @@ def get_my_resources_list(user, annotate=False, filter=None, **kwargs):
if not filter or 'owned' in filter:
# get a list of resources with effective OWNER privilege
owned_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.OWNER)
- # remove obsoleted resources from the owned_resources
- owned_resources = owned_resources.exclude(object_id__in=Relation.objects.filter(
- type='isReplacedBy').values('object_id')).exclude(extra_data__to_be_deleted__isnull=False)
if not filter or 'editable' in filter:
# get a list of resources with effective CHANGE privilege (should include resources that the
# user has access to via group
editable_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.CHANGE,
via_group=True)
- # remove obsoleted resources from the editable_resources
- editable_resources = editable_resources.exclude(object_id__in=Relation.objects.filter(
- type='isReplacedBy').values('object_id'))
if not filter or 'viewable' in filter:
# get a list of resources with effective VIEW privilege (should include resources that the
# user has access via group
viewable_resources = user.uaccess.get_resources_with_explicit_access(PrivilegeCodes.VIEW,
via_group=True)
- # remove obsoleted resources from the viewable_resources
- viewable_resources = viewable_resources.exclude(object_id__in=Relation.objects.filter(
- type='isReplacedBy').values('object_id'))
if not filter or 'discovered' in filter:
discovered_resources = user.ulabels.my_resources
@@ -652,6 +643,10 @@ def get_my_resources_list(user, annotate=False, filter=None, **kwargs):
if not filter or 'favorites' in filter:
resource_collection = resource_collection | favorite_resources.distinct()
+ # remove obsoleted resources
+ resource_collection = resource_collection.exclude(object_id__in=Relation.objects.filter(
+ type='isReplacedBy').values('object_id')).exclude(extra_data__to_be_deleted__isnull=False)
+
# When used in the My Resources page, annotate for speed
if annotate:
# The annotated field 'has_labels' would allow us to query the DB for labels only if the
