Handle opening a version should rediect to head

This commit is contained in:
shamoon
2026-02-10 13:20:45 -08:00
parent 667e4b81eb
commit a5c211cc0f
3 changed files with 48 additions and 1 deletions

View File

@@ -805,6 +805,26 @@ class DocumentViewSet(
)
return super().get_serializer(*args, **kwargs)
@action(methods=["get"], detail=True, url_path="head")
def head(self, request, pk=None):
try:
doc = Document.global_objects.select_related(
"owner",
"head_version",
).get(pk=pk)
except Document.DoesNotExist:
raise Http404
head_doc = doc if doc.head_version_id is None else doc.head_version
if request.user is not None and not has_perms_owner_aware(
request.user,
"view_document",
head_doc,
):
return HttpResponseForbidden("Insufficient permissions")
return Response({"head_id": head_doc.id})
def update(self, request, *args, **kwargs):
response = super().update(request, *args, **kwargs)
from documents import index