Rafał Pitoń 10 years ago
parent
commit
bfbb9f0853
2 changed files with 22 additions and 3 deletions
  1. 8 3
      misago/acl/panels.py
  2. 14 0
      misago/core/tests/test_common_middleware_redirect.py

+ 8 - 3
misago/acl/panels.py

@@ -13,18 +13,23 @@ class MisagoACLPanel(Panel):
     def nav_subtitle(self):
     def nav_subtitle(self):
         misago_user = self.get_stats().get('misago_user')
         misago_user = self.get_stats().get('misago_user')
 
 
-        if misago_user.is_authenticated():
+        if misago_user and misago_user.is_authenticated():
             return misago_user.username
             return misago_user.username
         else:
         else:
             return _("Anonymous user")
             return _("Anonymous user")
 
 
     def process_response(self, request, response):
     def process_response(self, request, response):
         try:
         try:
-            misago_acl = request.user.acl
+            misago_user = request.user
+        except AttributeError:
+            misago_user = None
+
+        try:
+            misago_acl = misago_user.acl
         except AttributeError:
         except AttributeError:
             misago_acl = {}
             misago_acl = {}
 
 
         self.record_stats({
         self.record_stats({
-            'misago_user': request.user,
+            'misago_user': misago_user,
             'misago_acl': misago_acl,
             'misago_acl': misago_acl,
         })
         })

+ 14 - 0
misago/core/tests/test_common_middleware_redirect.py

@@ -0,0 +1,14 @@
+from misago.users.testutils import AuthenticatedUserTestCase
+
+
+class ChangeForumOptionsTests(AuthenticatedUserTestCase):
+    def test_slashless_redirect(self):
+        """
+        Regression test for https://github.com/rafalp/Misago/issues/450
+
+        there shouldn't be crash when request path lacks trailing slash
+        """
+        response = self.client.get(self.user.get_absolute_url()[:-1])
+        self.assertEqual(response.status_code, 301)
+        self.assertTrue(
+            response['location'].endswith(self.user.get_absolute_url()))