diff --git a/adminlte2_pdq/middleware.py b/adminlte2_pdq/middleware.py index 89292c635c7c5692f64b57233450f46570eae8ab..03a5ba7f9a75db8d81a2a38d16d3db986df3711e 100644 --- a/adminlte2_pdq/middleware.py +++ b/adminlte2_pdq/middleware.py @@ -133,11 +133,17 @@ class AuthMiddleware: permissions = getattr(view_class, 'permission_required', []) one_of_permissions = getattr(view_class, 'permission_required_one', []) login_required = getattr(view_class, 'login_required', False) + view_name = view_class.__qualname__ + view_type = 'class-based' + view_perm_type = 'attribute' else: # Get attributes permissions = getattr(view.func, 'permissions', []) one_of_permissions = getattr(view.func, 'one_of_permissions', []) login_required = getattr(view.func, 'login_required', False) + view_name = view.func.__qualname__ + view_type = 'function-based' + view_perm_type = 'decorator' # If there are permissions, or login_required if exempt or permissions or one_of_permissions or login_required: @@ -145,9 +151,9 @@ class AuthMiddleware: # Permissions or Login Required not set, add messages, warnings, and return False warning_message = ( - f"The view '{view.func.__qualname__}' does not have the" + f"The {view_type} view '{view_name}' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + f" {view_perm_type} set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 00871fb51abb0f57fbb3e3839d2e32080383bfa1..d8112f010d99914c832d063cdf01e9d982a1dce8 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -89,9 +89,9 @@ class MiddlewareTestCase(TestCase): """test_middleware_blocks_when_user_anonymous_login_off_strict_on_login_wl_off_strict_wl_off""" with warnings.catch_warnings(record=True) as wa: warning_message = ( - "The view 'demo_css' does not have the" + "The function-based view 'demo_css' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + " decorator set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." @@ -137,9 +137,9 @@ class MiddlewareTestCase(TestCase): # Home is a new request that fails the login required being on and thus redirect to login page. with warnings.catch_warnings(record=True) as wa: warning_message = ( - "The view 'demo_css' does not have the" + "The function-based view 'demo_css' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + " decorator set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." @@ -223,9 +223,9 @@ class MiddlewareTestCase(TestCase): with warnings.catch_warnings(record=True) as wa: self.client.force_login(self.test_user_w_perms) warning_message = ( - "The view 'demo_css' does not have the" + "The function-based view 'demo_css' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + " decorator set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." @@ -259,9 +259,9 @@ class MiddlewareTestCase(TestCase): with warnings.catch_warnings(record=True) as wa: self.client.force_login(self.test_user_w_perms) warning_message = ( - "The view 'demo_css' does not have the" + "The function-based view 'demo_css' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + " decorator set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." @@ -284,9 +284,9 @@ class MiddlewareTestCase(TestCase): with warnings.catch_warnings(record=True) as wa: self.client.force_login(self.test_user_w_perms) warning_message = ( - "The view 'demo_css' does not have the" + "The function-based view 'demo_css' does not have the" " permission_required, one_of_permission, or login_required" - " attribute set and the option ADMINLTE2_USE_STRICT_POLICY is" + " decorator set and the option ADMINLTE2_USE_STRICT_POLICY is" " set to True. This means that this view is inaccessible until" " either permissions are set on the view or the url_name for the" " view is added to the ADMINLTE2_STRICT_POLICY_WHITELIST setting." @@ -343,7 +343,6 @@ class MiddlewareTestCase(TestCase): reverse('admin:auth_user_changelist'), follow=True ) - print(response.content.decode()) self.assertEqual(response.status_code, 200) self.assertContains(response, "Select user to change")