示例#1
0
 def setUp(self):
     self.client = MinioClient(disable_private=True, disable_public=True)
     FileObject = collections.namedtuple('FileObject',
                                         'bucket_name object_name')
     self.file1 = FileObject(bucket_name='test-bucket',
                             object_name='test-object')
     self.file2 = FileObject(bucket_name='test-bucket',
                             object_name='test-object2')
     self.host = 'www.example.com'
示例#2
0
    def get(self, request, aquifer_id):

        client = MinioClient(request=request, disable_private=True)

        documents = client.get_documents(int(aquifer_id),
                                         resource="aquifer",
                                         include_private=False)

        return Response(documents)
示例#3
0
    def get(self, request, person_guid):
        user_is_staff = self.request.user.groups.filter(
            Q(name=REGISTRIES_EDIT_ROLE) | Q(name=REGISTRIES_VIEWER_ROLE)).exists()

        client = MinioClient(
            request=request, disable_private=(not user_is_staff))

        documents = client.get_documents(
            person_guid, resource="driller", include_private=user_is_staff)

        return Response(documents)
示例#4
0
    def get(self, request, tag):
        user_is_staff = self.request.user.groups.filter(
            name=WELLS_VIEWER_ROLE).exists()

        client = MinioClient(request=request,
                             disable_private=(not user_is_staff))

        documents = client.get_documents(int(tag),
                                         include_private=user_is_staff)

        return Response(documents)
示例#5
0
    def get(self, request, aquifer_id, **kwargs):
        user_is_staff = self.request.user.groups.filter(
            name=AQUIFERS_EDIT_ROLE).exists()

        client = MinioClient(request=request,
                             disable_private=(not user_is_staff))

        documents = client.get_documents(int(aquifer_id),
                                         resource="aquifer",
                                         include_private=user_is_staff)

        return Response(documents)
示例#6
0
    def get(self, request, person_guid):
        person = get_object_or_404(self.queryset, pk=person_guid)
        client = MinioClient(
            request=request, disable_private=False)

        object_name = request.GET.get("filename")
        filename = client.format_object_name(object_name, person.person_guid, "driller")
        bucket_name = get_env_variable("S3_REGISTRANT_BUCKET")

        # All documents are private for drillers
        url = client.get_presigned_put_url(
            filename, bucket_name=bucket_name, private=True)

        return JsonResponse({"object_name": object_name, "url": url})
示例#7
0
    def delete(self, request, person_guid):
        person = get_object_or_404(self.queryset, pk=person_guid)
        client = MinioClient(
            request=request, disable_private=False)

        is_private = False
        bucket_name = get_env_variable("S3_REGISTRANT_BUCKET")

        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_REGISTRANT_BUCKET")

        object_name = request.GET.get("filename")
        client.delete_document(object_name, bucket_name=bucket_name, private=is_private)

        return HttpResponse(status=204)
示例#8
0
    def delete(self, request, aquifer_id, **kwargs):
        client = MinioClient(request=request, disable_private=False)

        is_private = False
        bucket_name = get_env_variable("S3_AQUIFER_BUCKET")

        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_AQUIFER_BUCKET")

        object_name = client.get_bucket_folder(
            int(aquifer_id), "aquifer") + "/" + request.GET.get("filename")
        client.delete_document(object_name,
                               bucket_name=bucket_name,
                               private=is_private)

        return HttpResponse(status=204)
示例#9
0
    def get(self, request, aquifer_id, **kwargs):
        client = MinioClient(request=request, disable_private=False)

        object_name = request.GET.get("filename")
        filename = client.format_object_name(object_name, int(aquifer_id),
                                             "aquifer")
        bucket_name = get_env_variable("S3_AQUIFER_BUCKET")

        is_private = False
        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_AQUIFER_BUCKET")

        url = client.get_presigned_put_url(filename,
                                           bucket_name=bucket_name,
                                           private=is_private)

        return JsonResponse({"object_name": object_name, "url": url})
示例#10
0
    def get(self, request, submission_id):
        submission = get_object_or_404(self.queryset, pk=submission_id)

        client = MinioClient(
            request=request, disable_private=False)

        object_name = request.GET.get("filename")
        filename = client.format_object_name(object_name, int(submission.well.well_tag_number), "well")
        bucket_name = get_env_variable("S3_ROOT_BUCKET")

        is_private = False
        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_ROOT_BUCKET")

        url = client.get_presigned_put_url(
            filename, bucket_name=bucket_name, private=is_private)

        return JsonResponse({"object_name": object_name, "url": url})
示例#11
0
    def get(self, request, tag, **kwargs):

        well = get_object_or_404(Well, pk=tag)

        if well.well_publication_status\
                .well_publication_status_code == 'Unpublished':
            if not self.request.user.groups.filter(name=WELLS_EDIT_ROLE).exists():
                return HttpResponseNotFound()

        user_is_staff = self.request.user.groups.filter(
            name=WELLS_VIEWER_ROLE).exists()

        client = MinioClient(
            request=request, disable_private=(not user_is_staff))

        documents = client.get_documents(
            int(tag), resource="well", include_private=user_is_staff)

        return Response(documents)
示例#12
0
    def delete(self, request, tag, **kwargs):
        well = get_object_or_404(self.queryset, pk=tag)
        client = MinioClient(request=request, disable_private=False)

        is_private = False
        bucket_name = get_env_variable("S3_ROOT_BUCKET")

        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_ROOT_BUCKET")

        object_name = client.get_bucket_folder(int(
            well.well_tag_number), "well") + "/" + request.GET.get("filename")

        # TODO: This should probably be "S3_WELL_BUCKET" but that will require a file migration
        client.delete_document(object_name,
                               bucket_name=bucket_name,
                               private=is_private)

        return HttpResponse(status=204)
示例#13
0
    def get(self, request, tag, **kwargs):
        well = get_object_or_404(self.queryset, pk=tag)
        client = MinioClient(request=request, disable_private=False)

        object_name = request.GET.get("filename")
        filename = client.format_object_name(object_name,
                                             int(well.well_tag_number), "well")
        bucket_name = get_env_variable("S3_ROOT_BUCKET")

        is_private = False
        if request.GET.get("private") == "true":
            is_private = True
            bucket_name = get_env_variable("S3_PRIVATE_ROOT_BUCKET")

        # TODO: This should probably be "S3_WELL_BUCKET" but that will require a file migration
        url = client.get_presigned_put_url(filename,
                                           bucket_name=bucket_name,
                                           private=is_private)

        return JsonResponse({"object_name": object_name, "url": url})
示例#14
0
class DocumentTests(TestCase):
    def setUp(self):
        self.client = MinioClient(disable_private=True, disable_public=True)
        FileObject = collections.namedtuple('FileObject',
                                            'bucket_name object_name')
        self.file1 = FileObject(bucket_name='test-bucket',
                                object_name='test-object')
        self.file2 = FileObject(bucket_name='test-bucket',
                                object_name='test-object2')
        self.host = 'www.example.com'

    def test_create_url(self):
        url = self.client.create_url(self.file1, self.host)
        self.assertEqual(url,
                         'https://www.example.com/test-bucket/test-object')

    def test_create_url_list(self):
        file_list = [self.file1, self.file2]
        url_list = self.client.create_url_list(file_list, self.host)

        self.assertEqual(len(url_list), 2)
        self.assertEqual(url_list[1]['name'], 'test-object2')