Beispiel #1
0
    def check_and_call(request, *args, **kwargs):

        user = request.user

        print user.id

        params = request.POST.copy()

        if user.is_superuser:
            return func(request, *args, **kwargs)

        if "uuid" in params:
            service_name_or_uuid = params.get('uuid')

        prog = re.compile(
            "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
        )

        result = prog.match(service_name_or_uuid)

        if result is None:
            parsed_name = service_name_or_uuid.replace("_", " ").strip()
        else:
            uuid = service_name_or_uuid

        try:
            if result is None:
                service = Service.objects.get(name=parsed_name)
            else:
                service = Service.objects.get(id=uuid)

        except Service.DoesNotExist:
            response = helper.get_error_response(strings.SERVICE_NOT_FOUND)
            return JsonResponse(response)

        owner = service.get_service_owners()

        if owner['account_id'] == user.id:
            return func(request, *args, **kwargs)
        else:
            response = helper.get_error_response(
                strings.OPERATION_NOT_PERMITTED, strings.FORBIDDEN_403)

            return JsonResponse({
                "resp": response,
                "user": user.is_authenticated()
            })
Beispiel #2
0
    def test_service_invalid_owner_institution(self):

        response_name = self.client_stub.get('/api/v1/portfolio/services/B2SAFE/service_owner/Claudia_Cacciari/institution')
        response_uuid = self.client_stub.get('/api/v1/portfolio/services/88b35b0d-adc2-4a2e-b5fc-cae2d6f5456a/service_owner/a9976cd2-14e4-47b7-9363-7e9faba2f200/institution')

        expected_response = helper.get_error_response(strings.OWNER_NOT_FOUND)

        self.assertJSONEqual(json.dumps(expected_response), response_name.content)
        self.assertJSONEqual(json.dumps(expected_response), response_uuid.content)
Beispiel #3
0
    def test_edit_non_existing_service_component(self):
        post_data = {
            "name": "Test name",
            "description": "Test description",
            "uuid": "56601d76-c1e2-488c-a812-dba8e5508c2e"
        }

        response = self.client_stub.post("/api/v1/component/edit", post_data)
        expected_response = helper.get_error_response(strings.SERVICE_COMPONENT_NOT_FOUND, status=strings.NOT_FOUND_404)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #4
0
    def test_edit_institution_no_uuid(self):

        post_data = {
            "name": "Test name",
            "address": "Test address",
            "country": "Test country",
            "department": "Test department"
        }

        response = self.client_stub.post("/api/v1/owner/institution/edit", post_data)
        expected_response = helper.get_error_response(strings.INSTITUTION_UUID_NOT_PROVIDED, strings.REJECTED_406)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #5
0
    def test_edit_non_existing_institution(self):

        post_data = {
            "name": "Test name",
            "address": "Test address",
            "country": "Test country",
            "department": "Test department",
            "uuid": "72eee88a-aaa4-4d7b-86a4-4124e3a9d99d"
        }

        response = self.client_stub.post("/api/v1/owner/institution/edit", post_data)
        expected_response = helper.get_error_response(strings.INSTITUTION_NOT_FOUND, strings.NOT_FOUND_404)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #6
0
    def test_edit_owner_no_uuid(self):

        post_data = {
            "first_name": "Test first name",
            "last_name": "Test last name",
            "email": "Test email",
            "phone": "Test phone",
            "institution_uuid": "224fe496-5023-49e6-8953-19d5b1331333"
        }

        response = self.client_stub.post("/api/v1/owner/edit", post_data)
        expected_response = helper.get_error_response(strings.SERVICE_OWNER_UUID_NOT_PROVIDED, strings.REJECTED_406)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #7
0
    def test_edit_contact_no_uuid(self):

        post_data = {
            "first_name": "Test first name",
            "last_name": "Test last name",
            "email": "Test email",
            "phone": "Test phone",
            "url": "Test url"
        }

        response = self.client_stub.post("/api/v1/owner/contact_information/edit", post_data)
        expected_response = helper.get_error_response(strings.SERVICE_CONTACT_INFORMATION_UUID_NOT_PROVIDED, strings.REJECTED_406)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #8
0
    def check_and_call(request, *args, **kwargs):

        user = request.user

        if user.is_superuser:
            return func(request, *args, **kwargs)

        if user.is_staff:
            return func(request, *args, **kwargs)

        response = helper.get_error_response(strings.OPERATION_NOT_PERMITTED,
                                             strings.FORBIDDEN_403)

        return redirect(LOGIN_REDIRECT_URL + "?next=" + request.path)
Beispiel #9
0
    def test_edit_non_existing_owner(self):

        post_data = {
            "first_name": "Test first name",
            "last_name": "Test last name",
            "email": "Test email",
            "phone": "Test phone",
            "institution_uuid": "224fe496-5023-49e6-8953-19d5b1331333",
            "uuid": "a9976cd2-14e4-47b7-9353-7e9faba2f20d"
        }

        response = self.client_stub.post("/api/v1/owner/edit", post_data)
        expected_response = helper.get_error_response(strings.SERVICE_OWNER_NOT_FOUND, strings.NOT_FOUND_404)
        self.assertJSONEqual(json.dumps(expected_response), response.content)
Beispiel #10
0
    def test_edit_non_existing_contact(self):

        post_data = {
            "first_name": "Test first name",
            "last_name": "Test last name",
            "email": "Test email",
            "phone": "Test phone",
            "url": "Test url",
            "uuid": "7166dfad-082b-4e81-bf86-cae10af12cfc"
        }

        response = self.client_stub.post("/api/v1/owner/contact_information/edit", post_data)
        expected_response = helper.get_error_response(strings.CONTACT_INFORMATION_NOT_FOUND, strings.NOT_FOUND_404)
        self.assertJSONEqual(json.dumps(expected_response), response.content)