def test_change_owner_from_owner_to_user_ok(self): mock_owner = _create_user('1') mock_user = _create_user('2') data_api.change_owner(data=fixture_data.data_collection[ fixture_data.USER_1_NO_WORKSPACE], new_user=mock_user, user=mock_owner)
def test_change_owner_from_user_to_user_raises_exception(self): mock_owner = _create_user('1') mock_user = _create_user('2') with self.assertRaises(AccessControlError): data_api.change_owner(data=fixture_data.data_collection[fixture_data.USER_1_NO_WORKSPACE], new_user=mock_owner, user=mock_user)
def test_change_owner_as_superuser_ok(self): mock_user = _create_user("2", is_superuser=True) data_api.change_owner( document=fixture_data.data_collection[ fixture_data.USER_1_NO_WORKSPACE], new_user=mock_user, user=mock_user, )
def test_change_owner_from_owner_to_owner_ok(self): mock_owner = _create_user("1") data_api.change_owner( document=fixture_data.data_collection[ fixture_data.USER_1_NO_WORKSPACE], new_user=mock_owner, user=mock_owner, )
def patch(self, request, pk, user_id): """ Change the Owner of a data Args: request: HTTP request pk: ObjectId user_id: ObjectId Returns: - code: 200 content: None - code: 403 content: Authentication error - code: 404 content: Object was not found - code: 500 content: Internal server error """ try: # get object data_object = self.get_object(request, pk) user_object = self.get_user(user_id) # change owner data_api.change_owner(data_object, user_object, request.user) return Response({}, status=status.HTTP_200_OK) except Http404: content = {'message': 'Data or user not found.'} return Response(content, status=status.HTTP_404_NOT_FOUND) except AccessControlError as ace: content = {'message': str(ace)} return Response(content, status=status.HTTP_403_FORBIDDEN) except Exception as api_exception: content = {'message': str(api_exception)} return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Args: request: data_ids: user_id: Returns: """ try: list_data = _get_data(data_ids, request.user) except Exception, e: return HttpResponseBadRequest(e.message) try: new_user = user_api.get_user_by_id(user_id) for data in list_data: data_api.change_owner(data, new_user, request.user) except Exception, e: return HttpResponseBadRequest(e.message) return HttpResponse(json.dumps({}), content_type='application/javascript') def edit_record(request): """ Edit a record. Args: request: Returns: """ try: