Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #14795 -- Ensure that get_all_permissions() returns the…

… right result (i.e., all permissions) for superusers. Thanks to jay.halleaux@gmail.com for the report, and Brett Haydon for the patch.

Backport of r14797 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14801 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 821b7f362c84bdb527618416e0b237ab2d10e638 1 parent 3ad1cb7
Russell Keith-Magee authored December 04, 2010
8  django/contrib/auth/backends.py
@@ -25,9 +25,11 @@ def get_group_permissions(self, user_obj):
25 25
         groups.
26 26
         """
27 27
         if not hasattr(user_obj, '_group_perm_cache'):
28  
-            perms = Permission.objects.filter(group__user=user_obj
29  
-                ).values_list('content_type__app_label', 'codename'
30  
-                ).order_by()
  28
+            if user_obj.is_superuser:
  29
+                perms = Permission.objects.all()
  30
+            else:
  31
+                perms = Permission.objects.filter(group__user=user_obj)
  32
+            perms = perms.values_list('content_type__app_label', 'codename').order_by()
31 33
             user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
32 34
         return user_obj._group_perm_cache
33 35
 
5  django/contrib/auth/tests/auth_backends.py
@@ -13,6 +13,7 @@ def setUp(self):
13 13
         self.curr_auth = settings.AUTHENTICATION_BACKENDS
14 14
         settings.AUTHENTICATION_BACKENDS = (self.backend,)
15 15
         User.objects.create_user('test', 'test@example.com', 'test')
  16
+        User.objects.create_superuser('test2', 'test2@example.com', 'test')
16 17
 
17 18
     def tearDown(self):
18 19
         settings.AUTHENTICATION_BACKENDS = self.curr_auth
@@ -88,6 +89,10 @@ def test_has_no_object_perm(self):
88 89
         self.assertEqual(user.has_perm('auth.test'), True)
89 90
         self.assertEqual(user.get_all_permissions(), set(['auth.test']))
90 91
 
  92
+    def test_get_all_superuser_permissions(self):
  93
+        "A superuser has all permissions. Refs #14795"
  94
+        user = User.objects.get(username='test2')
  95
+        self.assertEqual(len(user.get_all_permissions()), len(Permission.objects.all()))
91 96
 
92 97
 class TestObj(object):
93 98
     pass

0 notes on commit 821b7f3

Please sign in to comment.
Something went wrong with that request. Please try again.