mirror of
https://github.com/suitenumerique/docs.git
synced 2026-09-24 02:25:08 +02:00
✨(backend) wired soft deletion with yhub server
yhub is the source of truth, when a user delete a document, it should also be deleted in the yhub server. We call the yhub server in the perform_destroy action but also the restore endpoint of yhub when a document is restored.
This commit is contained in:
@@ -8,6 +8,7 @@ import logging
|
||||
import socket
|
||||
import uuid
|
||||
from collections import defaultdict
|
||||
from functools import partial
|
||||
from urllib.parse import unquote, urlencode, urlparse
|
||||
|
||||
from django.conf import settings
|
||||
@@ -69,6 +70,7 @@ from core.services.search_indexers import (
|
||||
)
|
||||
from core.services.yhub_services import YHubError, YHubService
|
||||
from core.tasks.access import reset_service_connections_in_cascade
|
||||
from core.tasks.documents import sync_service_deletions_in_cascade
|
||||
from core.tasks.mail import send_ask_for_access_mail
|
||||
from core.tasks.search import trigger_batch_document_indexer
|
||||
from core.utils.analytics import PosthogEventName, posthog_capture
|
||||
@@ -827,6 +829,14 @@ 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
|
||||
)
|
||||
@@ -1113,6 +1123,13 @@ class DocumentViewSet(
|
||||
except RuntimeError as err:
|
||||
raise drf.exceptions.ValidationError({"detail": str(err)}) from err
|
||||
|
||||
# the counterpart of the deletion: the same walk puts back the content
|
||||
# of the documents that came back with this one, and it reads the
|
||||
# restored state back, hence on commit as well
|
||||
transaction.on_commit(
|
||||
partial(sync_service_deletions_in_cascade.delay, str(document.id))
|
||||
)
|
||||
|
||||
return drf_response.Response(
|
||||
{"detail": "Document has been successfully restored."},
|
||||
status=status.HTTP_200_OK,
|
||||
|
||||
Reference in New Issue
Block a user