Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Return a status 400 for logged out users

Roland Geider4278763da398
diff --git a/wger/core/api/views.py b/wger/core/api/views.py
index 28c02c565..6652009c9 100644
--- a/wger/core/api/views.py
+++ b/wger/core/api/views.py
@@ -170,8 +170,14 @@ class PermissionView(viewsets.ViewSet):
@staticmethod
def get(request):
+ if request.user.is_anonymous:
+ return Response(
+ "Please login",
+ status=status.HTTP_400_BAD_REQUEST,
+ )
+
permission = request.query_params.get('permission')
- if request.user.is_anonymous or permission is None:
+ if permission is None:
return Response(
"Please pass a permission name in the 'permission' parameter",
status=status.HTTP_400_BAD_REQUEST,
diff --git a/wger/core/tests/test_permission_api.py b/wger/core/tests/test_permission_api.py
index 6934710ac..61102e200 100644
--- a/wger/core/tests/test_permission_api.py
+++ b/wger/core/tests/test_permission_api.py
@@ -21,10 +21,11 @@ from wger.core.tests.api_base_test import ApiBaseTestCase
from wger.core.tests.base_testcase import BaseTestCase
-class ExerciseCustomApiTestCase(BaseTestCase, ApiBaseTestCase):
+class PermissionApiTestCase(BaseTestCase, ApiBaseTestCase):
url = '/api/v2/check-permission/'
error_message = "Please pass a permission name in the 'permission' parameter"
+ error_message_anon = "Please login"
def get_resource_name(self):
return 'check-permission'
@@ -35,7 +36,7 @@ class ExerciseCustomApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
- self.assertEqual(response.data, self.error_message)
+ self.assertEqual(response.data, self.error_message_anon)
def test_check_permission_anonymous_with_parameter(self):
"""
@@ -43,7 +44,7 @@ class ExerciseCustomApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
response = self.client.get(self.url + '?permission=exercises.change_muscle')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
- self.assertEqual(response.data, self.error_message)
+ self.assertEqual(response.data, self.error_message_anon)
def test_check_no_parameter_logged_in(self):
"""