Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to stream document on organisation #1809

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading