Commit 8e4ea6ff authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

break links to collection when resource is soft-deleted

parent 6102aa94
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -906,7 +906,7 @@ def remove_resource_from_collection(
@_rpc_groups(["Resources"])
def delete_resource(user: User, resource_id: int) -> bool:
    """
    Permanently delete a resource given its id.
    Permanently (soft) delete a resource given its id.
    """
    query_set: Union[Iterator[Resource], QuerySet] = Resource.objects.filter(
        pk=resource_id, deleted_at__isnull=True
@@ -915,6 +915,11 @@ def delete_resource(user: User, resource_id: int) -> bool:
    if not resource_instance:
        return True
    _check_project_permission(user, resource_instance.ptr_project, PERM_RESOURCE_DELETE)
    # break link with current collections
    for current_collection in resource_instance.collections.all():
        remove_resource_from_collection(
            user, resource_instance.pk, current_collection.pk
        )
    resource_instance.soft_delete()
    return True