Skip to content

Commit

Permalink
Add good document streaming endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Feb 9, 2024
1 parent a5ce86b commit 2ebd65a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/goods/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework import filters


class GoodFilter(filters.BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
return queryset.filter(good_id=view.kwargs["pk"])
8 changes: 8 additions & 0 deletions api/goods/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import permissions

from api.organisations.libraries.get_organisation import get_request_user_organisation_id


class IsDocumentInOrganisation(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
return obj.organisation_id == get_request_user_organisation_id(request)
5 changes: 5 additions & 0 deletions api/goods/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
views.GoodDocumentDetail.as_view(),
name="document",
),
path(
"<uuid:pk>/documents/<uuid:doc_pk>/stream/",
views.GoodDocumentStream.as_view(),
name="document_stream",
),
path(
"document_internal_good_on_application/<str:goods_on_application_pk>/",
views.DocumentGoodOnApplicationInternalView.as_view(),
Expand Down
13 changes: 13 additions & 0 deletions api/goods/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from api.core.authentication import ExporterAuthentication, SharedAuthentication, GovAuthentication
from api.core.exceptions import BadRequestError
from api.core.helpers import str_to_bool
from api.core.views import DocumentStreamAPIView
from api.documents.libraries.delete_documents_on_bad_request import delete_documents_on_bad_request
from api.documents.models import Document
from api.goods.enums import GoodStatus, GoodPvGraded, ItemCategory
from api.goods.filters import GoodFilter
from api.goods.goods_paginator import GoodListPaginator
from api.goods.helpers import (
FIREARMS_CORE_TYPES,
Expand All @@ -31,6 +33,7 @@
from api.goods.libraries.get_goods import get_good, get_good_document
from api.goods.libraries.save_good import create_or_update_good
from api.goods.models import Good, GoodDocument
from api.goods.permissions import IsDocumentInOrganisation
from api.goods.serializers import (
GoodAttachingSerializer,
GoodCreateSerializer,
Expand Down Expand Up @@ -539,6 +542,16 @@ def delete(self, request, pk, doc_pk):
return JsonResponse({"document": "deleted success"})


class GoodDocumentStream(DocumentStreamAPIView):
authentication_classes = (ExporterAuthentication,)
filter_backends = (GoodFilter,)
queryset = GoodDocument.objects.all()
permission_classes = (IsDocumentInOrganisation,)

def get_document(self, instance):
return instance


class DocumentGoodOnApplicationInternalView(APIView):
authentication_classes = (GovAuthentication,)
serializer_class = GoodOnApplicationInternalDocumentCreateSerializer
Expand Down

0 comments on commit 2ebd65a

Please sign in to comment.