From aaa3176fee555c56003c44e8b360874bc535375e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 8 Oct 2026 15:13:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=EF=B8=8F(backend)=20stop=20deleting?= =?UTF-8?q?=20document=20in=20yhub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One feature we have is to still be able to read a soft deleted document in the application. Calling the yhub service to delete the document inside yhub make it unreachable, so it does not load anymore in the editor. Yhub map the permission on what Docs returns in its abilities. A soft deleted document will be in read only. --- src/backend/core/api/viewsets.py | 8 ----- .../documents/test_api_documents_delete.py | 29 ------------------- 2 files changed, 37 deletions(-) diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index 930dce20c..ce8911711 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -795,14 +795,6 @@ class DocumentViewSet( """Override to implement a soft delete instead of dumping the record in database.""" instance.soft_delete() - # the collaboration server holds the content: until it is told, it goes - # on serving the document to the clients editing it. On commit, because - # the task reads back what was just written to know what to report — it - # would find the document alive and restore it instead - transaction.on_commit( - partial(sync_service_deletions_in_cascade.delay, str(instance.id)) - ) - posthog_capture( PosthogEventName.DOC_DELETED, self.request.user, {}, document=instance ) diff --git a/src/backend/core/tests/documents/test_api_documents_delete.py b/src/backend/core/tests/documents/test_api_documents_delete.py index 6672b1376..f89503eb7 100644 --- a/src/backend/core/tests/documents/test_api_documents_delete.py +++ b/src/backend/core/tests/documents/test_api_documents_delete.py @@ -148,32 +148,3 @@ def test_api_documents_delete_authenticated_owner(via, mock_user_teams): {}, document=document, ) - - -def test_api_documents_delete_reports_the_deletion_to_the_collaboration_server( - django_capture_on_commit_callbacks, -): - """ - Deleting a document should tell the collaboration server, which holds its - content and would otherwise go on serving it to the clients editing it. - """ - user = factories.UserFactory() - document = factories.DocumentFactory(users=[(user, "owner")]) - child = factories.DocumentFactory(parent=document) - - client = APIClient() - client.force_login(user) - - # the report is made once the deletion is committed: the task reads it back - with ( - mock.patch("core.tasks.documents.YHubService") as mock_service, - django_capture_on_commit_callbacks(execute=True), - ): - response = client.delete(f"/api/v1.0/documents/{document.id!s}/") - - assert response.status_code == 204 - # the subtree goes with it - assert mock_service.return_value.delete_ydoc.call_args_list == [ - mock.call(document), - mock.call(child), - ]