mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #28713 -- Prevented ModelBackend.get_all_permissions() from mutating get_user_permissions().
This commit is contained in:
parent
c1fa6672dd
commit
d98210c255
@ -75,7 +75,8 @@ class ModelBackend:
|
||||
if not user_obj.is_active or user_obj.is_anonymous or obj is not None:
|
||||
return set()
|
||||
if not hasattr(user_obj, '_perm_cache'):
|
||||
user_obj._perm_cache = self.get_user_permissions(user_obj)
|
||||
user_obj._perm_cache = set()
|
||||
user_obj._perm_cache.update(self.get_user_permissions(user_obj))
|
||||
user_obj._perm_cache.update(self.get_group_permissions(user_obj))
|
||||
return user_obj._perm_cache
|
||||
|
||||
|
@ -138,7 +138,7 @@ class BaseModelBackendTest:
|
||||
group.permissions.add(group_perm)
|
||||
|
||||
self.assertEqual(backend.get_all_permissions(user), {'auth.test_user', 'auth.test_group'})
|
||||
self.assertEqual(backend.get_user_permissions(user), {'auth.test_user', 'auth.test_group'})
|
||||
self.assertEqual(backend.get_user_permissions(user), {'auth.test_user'})
|
||||
self.assertEqual(backend.get_group_permissions(user), {'auth.test_group'})
|
||||
|
||||
with mock.patch.object(self.UserModel, 'is_anonymous', True):
|
||||
@ -164,7 +164,7 @@ class BaseModelBackendTest:
|
||||
group.permissions.add(group_perm)
|
||||
|
||||
self.assertEqual(backend.get_all_permissions(user), {'auth.test_user', 'auth.test_group'})
|
||||
self.assertEqual(backend.get_user_permissions(user), {'auth.test_user', 'auth.test_group'})
|
||||
self.assertEqual(backend.get_user_permissions(user), {'auth.test_user'})
|
||||
self.assertEqual(backend.get_group_permissions(user), {'auth.test_group'})
|
||||
|
||||
user.is_active = False
|
||||
|
Loading…
Reference in New Issue
Block a user