diff --git a/aleksis/apps/resint/urls.py b/aleksis/apps/resint/urls.py index f72aee866a7583501be114253243807f8e742ce6..aac33a387dab59df8c73364d52a27b9042e7e4e8 100644 --- a/aleksis/apps/resint/urls.py +++ b/aleksis/apps/resint/urls.py @@ -5,6 +5,7 @@ from .views import ( LiveDocumentDeleteView, LiveDocumentEditView, LiveDocumentListView, + LiveDocumentShowAPIView, LiveDocumentShowView, PosterCurrentView, PosterDeleteView, @@ -42,4 +43,9 @@ urlpatterns = [ path( "live_documents/<str:slug>.pdf", LiveDocumentShowView.as_view(), name="show_live_document", ), + path( + "api/live_documents/<str:slug>.pdf", + LiveDocumentShowAPIView.as_view(), + name="api_show_live_document", + ), ] diff --git a/aleksis/apps/resint/views.py b/aleksis/apps/resint/views.py index abef233ed69b751e1f236a92aebf5b96658a5a8a..fcc50f0b31126a312e40e117b17d2f120b6acecb 100644 --- a/aleksis/apps/resint/views.py +++ b/aleksis/apps/resint/views.py @@ -15,6 +15,7 @@ from django.views.generic.list import ListView from django_tables2 import SingleTableView from guardian.shortcuts import get_objects_for_user +from oauth2_provider.views.mixins import ClientProtectedResourceMixin from reversion.views import RevisionMixin from rules.contrib.views import PermissionRequiredMixin @@ -221,15 +222,24 @@ class LiveDocumentDeleteView(PermissionRequiredMixin, RevisionMixin, AdvancedDel success_message = _("The live document has been deleted.") -class LiveDocumentShowView(PermissionRequiredMixin, SingleObjectMixin, View): - """Show the current version of the live document.""" +class LiveDocumentShowBaseView(SingleObjectMixin, View): + """Base view for showing live documents.""" model = LiveDocument - permission_required = "resint.view_livedocument_rule" def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> FileResponse: live_document = self.get_object() file = live_document.get_current_file() if not file: raise Http404 - return FileResponse(file.file, content_type="application/pdf") + return FileResponse(file, content_type="application/pdf") + + +class LiveDocumentShowView(PermissionRequiredMixin, LiveDocumentShowBaseView): + """Show the current version of the live document.""" + + permission_required = "resint.view_livedocument_rule" + + +class LiveDocumentShowAPIView(ClientProtectedResourceMixin, LiveDocumentShowBaseView): + """Show the current version of the live document in API."""