(collaboration) notify the backend when the worker persists new content

notify the backend when the worker persists new content for
a document, so the lists ordered by `updated_at` follow the edits made on the
collaboration server. The backend serves it on
`POST /api/v1.0/documents/{id}/content-updated/`, authenticated with a short
lived RS256 JWT the collaboration server signs (`aud: "docs-backend"`) and
the backend verifies against the JWKS the collaboration server publishes on
`/collaboration/jwks/v1` — the mirror of the admin token the backend signs to
call it, so no long lived secret is shared and either side can roll its key
on its own
This commit is contained in:
Manuel Raynaud
2026-09-21 14:46:11 +02:00
parent 6f77d73e0e
commit b2be3bd2cb
15 changed files with 939 additions and 30 deletions
+31
View File
@@ -940,6 +940,37 @@ class DocumentViewSet(
{"id": str(document.id)}, status=status.HTTP_201_CREATED
)
@drf.decorators.action(
authentication_classes=[authentication.CollaborationServerAuthentication],
detail=True,
methods=["post"],
permission_classes=[],
url_path="content-updated",
)
def content_updated(self, request, *args, **kwargs):
"""
Record that the collaboration server saved a new content for a document.
The content of a document does not go through Django anymore, so nothing
would refresh its "updated_at" as it is edited and the lists ordered by
it would freeze. The collaboration server calls this once it persisted
the changes of a document, at most once per debounce window.
The update is written without going through the model, saving it would
trigger a re-indexing of a content Django did not see change.
"""
try:
document_id = uuid.UUID(kwargs["pk"])
except ValueError as err:
raise Http404 from err
if not models.Document.objects.filter(pk=document_id).update(
updated_at=timezone.now()
):
raise Http404
return drf_response.Response(status=status.HTTP_204_NO_CONTENT)
@drf.decorators.action(detail=True, methods=["post"])
@transaction.atomic
def move(self, request, *args, **kwargs):