Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove first attempt at RW access for old api/v1
Roland Geideraeae8f6fef51
diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.pyindex ad881eb07..ac00f7084 100644--- a/wger/manager/tests/testcase.py+++ b/wger/manager/tests/testcase.py@@ -530,13 +530,14 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):response = self.api_client.get(self.url)self.assertValidJSONResponse(response)--## NOTE: post is not implemented by tastypie - dashdrum 2/20/2014def test_post(self):'''Tests a POST request++ Read-only at the moment, all requests fail'''- # Only perform the checks on derived classes++ # Only perform the checks on derived classesif self.__class__.__name__ == 'ApiBaseResourceTestCase':return@@ -545,19 +546,18 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):response = self.api_client.post(self.url, data=self.data)self.assertHttpUnauthorized(response)+ # User with accessif self.resource_updatable:+ response = self.api_client.post(self.url,+ data=self.data,+ authentication=self.get_credentials())+ self.assertHttpNotImplemented(response)# If a different user should fail, testresponse = self.api_client.post(self.url,data=self.data,authentication=self.get_credentials(self.user_fail))- self.assertHttpUnauthorized(response)-- # User with access- response = self.api_client.post(self.url,- data=self.data,- authentication=self.get_credentials())- self.assertHttpAccepted(response)+ self.assertHttpNotImplemented(response)# public resource (ingredients, exercises), no authentication neededelse:@@ -570,6 +570,8 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):def test_delete(self):'''Tests a DELETE request++ Read-only at the moment, all requests fail'''# Only perform the checks on derived classes@@ -581,18 +583,16 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):response = self.api_client.delete(self.url)self.assertHttpUnauthorized(response)-+ # User with accessif self.resource_updatable:+ response = self.api_client.delete(self.url, authentication=self.get_credentials())+ self.assertHttpUnauthorized(response)# If a different user should fail, testauthentication = self.get_credentials(self.user_fail)response = self.api_client.delete(self.url,authentication=authentication)self.assertHttpUnauthorized(response)-- # User with access- response = self.api_client.delete(self.url, authentication=self.get_credentials())- self.assertHttpAccepted(response)# public resource (ingredients, exercises), no authentication neededelse:@@ -605,6 +605,8 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):def test_put(self):'''Tests a PUT request++ Read-only at the moment, all requests fail'''# Only perform the checks on derived classes@@ -621,7 +623,7 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):response = self.api_client.put(self.url,data=self.data,authentication=self.get_credentials())- self.assertHttpAccepted(response)+ self.assertHttpUnauthorized(response)# If a different user should fail, testresponse = self.api_client.put(self.url,@@ -640,6 +642,8 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):def test_patch(self):'''Tests a PATCH request++ Read-only at the moment, all requests fail'''# Only perform the checks on derived classes@@ -656,7 +660,7 @@ class ApiBaseResourceTestCase(ResourceTestCase, BaseTestCase):response = self.api_client.patch(self.url,data=self.data,authentication=self.get_credentials())- self.assertHttpAccepted(response)+ self.assertHttpUnauthorized(response)# If a different user should fail, testauthentication = self.get_credentials(self.user_fail)diff --git a/wger/utils/resources.py b/wger/utils/resources.pyindex 98b921db7..8b85173f5 100644--- a/wger/utils/resources.py+++ b/wger/utils/resources.py@@ -15,7 +15,6 @@import loggingfrom tastypie.authorization import ReadOnlyAuthorization-from tastypie.exceptions import TastypieError, Unauthorizedlogger = logging.getLogger('wger.custom')@@ -36,29 +35,3 @@ class UserObjectsOnlyAuthorization(ReadOnlyAuthorization):# Objects without owner information can be accessedexcept AttributeError:return True-- def create_detail(self, object_list, bundle):- ### In what scenario is this method used? - dashdrum 2/20/2014- raise TastypieError('create_detail authorization check')- try:- return bundle.obj.get_owner_object().user == bundle.request.user- except AttributeError:- raise Unauthorized("You are not allowed to access that resource.")-- def update_detail(self, object_list, bundle):- # Check for an owner_object and compare users- try:- return bundle.obj.get_owner_object().user == bundle.request.user- # Only objects with owner information should use this authorization class- # Fail authorization attempt if the attribute is not found- except AttributeError:- raise Unauthorized("You are not allowed to access that resource.")-- def delete_detail(self, object_list, bundle):- # Check for an owner_object and compare users- try:- return bundle.obj.get_owner_object().user == bundle.request.user- # Only objects with owner information should use this authorization class- # Fail authorization attempt if the attribute is not found- except AttributeError:- raise Unauthorized("You are not allowed to access that resource.")\ No newline at end of file