Repository: learningequality/kolibri

Issue:
Removing resources should initiate removal if there's no other reason for them to be kept around
## Observed behavior
Currently flagging a resource for removal by a learner just notes the removal in our database and moves on. Until another import requires the space to be freed up, the resource will remain in place.

## Expected behavior
The removal request should be executed as soon as possible, assuming that no other users have requested the resource, or that an admin has explicitly asked for it to be imported.

## User-facing consequences
Inability to do 'spring cleaning' of their downloads, or otherwise free up space, unless they are hitting space limits during an import.

## Steps to reproduce
Download some resources.
Go to My Downloads and then remove them.
See that they are still available on the Learn tab


Follow up to #11177


Discussion:

Resolving patch:
diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py
--- a/kolibri/core/content/api.py
+++ b/kolibri/core/content/api.py
@@ -55,7 +55,7 @@
 from kolibri.core.content.models import ContentRequestReason
 from kolibri.core.content.models import ContentRequestStatus
 from kolibri.core.content.permissions import CanManageContent
-from kolibri.core.content.tasks import automatic_resource_import
+from kolibri.core.content.tasks import automatic_user_imported_resource_cleanup
 from kolibri.core.content.utils.content_types_tools import (
     renderable_contentnodes_q_filter,
 )
@@ -1400,7 +1400,7 @@ def delete(self, request, pk=None):
             content_request.contentnode_id = existing_download_request.contentnode_id
             content_request.save()
 
-        automatic_resource_import.enqueue_if_not()
+        automatic_user_imported_resource_cleanup.enqueue_if_not()
         return Response(status=status.HTTP_204_NO_CONTENT)
 
 
diff --git a/kolibri/core/content/tasks.py b/kolibri/core/content/tasks.py
--- a/kolibri/core/content/tasks.py
+++ b/kolibri/core/content/tasks.py
@@ -9,11 +9,14 @@
 from kolibri.core.auth.models import FacilityDataset
 from kolibri.core.content.models import ChannelMetadata
 from kolibri.core.content.models import ContentRequest
+from kolibri.core.content.models import ContentRequestReason
 from kolibri.core.content.models import ContentRequestStatus
 from kolibri.core.content.models import ContentRequestType
 from kolibri.core.content.utils.channel_import import import_channel_from_data
 from kolibri.core.content.utils.channels import get_mounted_drive_by_id
 from kolibri.core.content.utils.channels import read_channel_metadata_from_db_file
+from kolibri.core.content.utils.content_request import incomplete_removals_queryset
+from kolibri.core.content.utils.content_request import process_content_removal_requests
 from kolibri.core.content.utils.content_request import process_content_requests
 from kolibri.core.content.utils.content_request import synchronize_content_requests
 from kolibri.core.content.utils.paths import get_channel_lookup_url
@@ -394,6 +397,21 @@ def automatic_resource_import():
         process_content_requests()
 
 
+@register_task(
+    queue=QUEUE,
+    long_running=True,
+    status_fn=get_status,
+)
+def automatic_user_imported_resource_cleanup():
+    """
+    Processes content removal requests
+    """
+    incomplete_user_removals = incomplete_removals_queryset().filter(
+        reason=ContentRequestReason.UserInitiated
+    )
+    process_content_removal_requests(incomplete_user_removals)
+
+
 @register_task(
     long_running=True,
     status_fn=get_status,


Test patch: