diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 8148d8a..ceab7ba 100644
a
|
b
|
class User(models.Model):
|
218 | 218 | permissions = set() |
219 | 219 | for backend in auth.get_backends(): |
220 | 220 | if hasattr(backend, "get_group_permissions"): |
221 | | if obj is not None and backend.supports_object_permissions: |
222 | | group_permissions = backend.get_group_permissions(self, obj) |
| 221 | if obj is not None: |
| 222 | if backend.supports_object_permissions: |
| 223 | permissions.update( |
| 224 | backend.get_group_permissions(self, obj) |
| 225 | ) |
223 | 226 | else: |
224 | | group_permissions = backend.get_group_permissions(self) |
225 | | permissions.update(group_permissions) |
| 227 | permissions.update(backend.get_group_permissions(self)) |
226 | 228 | return permissions |
227 | 229 | |
228 | 230 | def get_all_permissions(self, obj=None): |
229 | 231 | permissions = set() |
230 | 232 | for backend in auth.get_backends(): |
231 | 233 | if hasattr(backend, "get_all_permissions"): |
232 | | if obj is not None and backend.supports_object_permissions: |
233 | | all_permissions = backend.get_all_permissions(self, obj) |
| 234 | if obj is not None: |
| 235 | if backend.supports_object_permissions: |
| 236 | permissions.update( |
| 237 | backend.get_all_permissions(self, obj) |
| 238 | ) |
234 | 239 | else: |
235 | | all_permissions = backend.get_all_permissions(self) |
236 | | permissions.update(all_permissions) |
| 240 | permissions.update(backend.get_all_permissions(self)) |
237 | 241 | return permissions |
238 | 242 | |
239 | 243 | def has_perm(self, perm, obj=None): |
… |
… |
class User(models.Model):
|
255 | 259 | # Otherwise we need to check the backends. |
256 | 260 | for backend in auth.get_backends(): |
257 | 261 | if hasattr(backend, "has_perm"): |
258 | | if obj is not None and backend.supports_object_permissions: |
259 | | if backend.has_perm(self, perm, obj): |
260 | | return True |
| 262 | if obj is not None: |
| 263 | if (backend.supports_object_permissions and |
| 264 | backend.has_perm(self, perm, obj)): |
| 265 | return True |
261 | 266 | else: |
262 | 267 | if backend.has_perm(self, perm): |
263 | 268 | return True |
diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
index bf5611a..af15d0b 100644
a
|
b
|
class BackendTest(TestCase):
|
69 | 69 | self.assertEqual(user.has_perm('test'), False) |
70 | 70 | self.assertEqual(user.has_perms(['auth.test2', 'auth.test3']), False) |
71 | 71 | |
| 72 | def test_has_no_object_perm(self): |
| 73 | """Regressiontest for #12462""" |
| 74 | user = User.objects.get(username='test') |
| 75 | content_type=ContentType.objects.get_for_model(Group) |
| 76 | perm = Permission.objects.create(name='test', content_type=content_type, codename='test') |
| 77 | user.user_permissions.add(perm) |
| 78 | user.save() |
| 79 | |
| 80 | self.assertEqual(user.has_perm('auth.test', 'object'), False) |
| 81 | self.assertEqual(user.get_all_permissions('object'), set([])) |
| 82 | self.assertEqual(user.has_perm('auth.test'), True) |
| 83 | self.assertEqual(user.get_all_permissions(), set(['auth.test'])) |
| 84 | |
| 85 | |
| 86 | |
72 | 87 | |
73 | 88 | class TestObj(object): |
74 | 89 | pass |