Skip to content

Commit

Permalink
Merge pull request #1809 from uktrade/LTD-4672-organisation-document-…
Browse files Browse the repository at this point in the history
…streaming-endpoint

Add endpoint to stream document on organisation
  • Loading branch information
kevincarrogan authored Feb 7, 2024
2 parents 0ce06e9 + 9caf6ac commit 7063a06
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 82 deletions.
6 changes: 5 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ omit =
./api/staticdata/management/*
./runtime.txt
./lite_routing/management/commands/generate_rules_docs.py

branch = True

[report]
exclude_lines =
pragma: no cover
raise NotImplementedError
30 changes: 2 additions & 28 deletions api/documents/tests/test_document_stream.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
import boto3

from moto import mock_aws

from django.http import StreamingHttpResponse
from django.urls import reverse

from test_helpers.clients import DataTestClient

from api.conf.settings import (
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
AWS_REGION,
AWS_STORAGE_BUCKET_NAME,
)
from api.documents.libraries.s3_operations import init_s3_client


@mock_aws
class DocumentStream(DataTestClient):
def setUp(self):
super().setUp()
init_s3_client()
s3 = boto3.client(
"s3",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_REGION,
)
s3.create_bucket(
Bucket=AWS_STORAGE_BUCKET_NAME,
CreateBucketConfiguration={
"LocationConstraint": AWS_REGION,
},
)
s3.put_object(
Bucket=AWS_STORAGE_BUCKET_NAME,
Key="thisisakey",
Body=b"test",
)
self.create_default_bucket()
self.put_object_in_default_bucket("thisisakey", b"test")

def test_document_stream_as_caseworker(self):
# given there is a case document
Expand Down
6 changes: 6 additions & 0 deletions api/organisations/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework import filters


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

from api.organisations.libraries.get_organisation import get_request_user_organisation_id


class IsCaseworkerOrInDocumentOrganisation(permissions.BasePermission):
def has_permission(self, request, view):
if hasattr(request.user, "govuser"):
return True
elif hasattr(request.user, "exporteruser"):
return view.kwargs["pk"] == get_request_user_organisation_id(request)
raise NotImplementedError()

def has_object_permission(self, request, view, obj):
if hasattr(request.user, "govuser"):
return True
elif hasattr(request.user, "exporteruser"):
return obj.organisation_id == get_request_user_organisation_id(request)
raise NotImplementedError()
1 change: 1 addition & 0 deletions api/organisations/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def site_records_located_at(self, create, extracted, **kwargs):

class DocumentOnOrganisationFactory(factory.django.DjangoModelFactory):
document = factory.SubFactory(DocumentFactory)
expiry_date = factory.Faker("future_date")

class Meta:
model = models.DocumentOnOrganisation
Loading

0 comments on commit 7063a06

Please sign in to comment.