diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index ad46c5c..44170c7 100644
a
|
b
|
class Permission(models.Model):
|
59 | 59 | created for each Django model. |
60 | 60 | """ |
61 | 61 | name = models.CharField(_('name'), max_length=255) |
62 | | content_type = models.ForeignKey(ContentType) |
| 62 | content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) |
63 | 63 | codename = models.CharField(_('codename'), max_length=100) |
64 | 64 | objects = PermissionManager() |
65 | 65 | |
… |
… |
class PermissionsMixin(models.Model):
|
251 | 251 | def get_all_permissions(self, obj=None): |
252 | 252 | return _user_get_all_permissions(self, obj) |
253 | 253 | |
254 | | def has_perm(self, perm, obj=None): |
| 254 | def has_perm(self, perm, obj=None, check_active=True): |
255 | 255 | """ |
256 | 256 | Returns True if the user has the specified permission. This method |
257 | 257 | queries all available auth backends, but returns immediately if any |
… |
… |
class PermissionsMixin(models.Model):
|
260 | 260 | provided, permissions for this specific object are checked. |
261 | 261 | """ |
262 | 262 | |
263 | | # Active superusers have all permissions. |
264 | | if self.is_active and self.is_superuser: |
| 263 | if check_active and not self.is_active: |
| 264 | return False |
| 265 | |
| 266 | # Superusers have all permissions. |
| 267 | if self.is_superuser: |
265 | 268 | return True |
266 | 269 | |
267 | 270 | # Otherwise we need to check the backends. |
268 | 271 | return _user_has_perm(self, perm, obj) |
269 | 272 | |
270 | | def has_perms(self, perm_list, obj=None): |
| 273 | def has_perms(self, perm_list, obj=None, check_active=True): |
271 | 274 | """ |
272 | 275 | Returns True if the user has each of the specified permissions. If |
273 | 276 | object is passed, it checks if the user has all required perms for this |
274 | 277 | object. |
275 | 278 | """ |
276 | 279 | for perm in perm_list: |
277 | | if not self.has_perm(perm, obj): |
| 280 | if not self.has_perm(perm, obj, check_active): |
278 | 281 | return False |
279 | 282 | return True |
280 | 283 | |
281 | | def has_module_perms(self, app_label): |
| 284 | def has_module_perms(self, app_label, check_active=True): |
282 | 285 | """ |
283 | 286 | Returns True if the user has any permissions in the given app label. |
284 | 287 | Uses pretty much the same logic as has_perm, above. |
285 | 288 | """ |
286 | | # Active superusers have all permissions. |
287 | | if self.is_active and self.is_superuser: |
| 289 | if check_active and not self.is_active: |
| 290 | return False |
| 291 | |
| 292 | # Superusers have all permissions. |
| 293 | if self.is_superuser: |
288 | 294 | return True |
289 | 295 | |
290 | 296 | return _user_has_module_perms(self, app_label) |
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index 6a642aa..da2f18d 100644
a
|
b
|
class InActiveUserBackendTest(TestCase):
|
445 | 445 | |
446 | 446 | def test_has_perm(self): |
447 | 447 | self.assertEqual(self.user1.has_perm('perm', TestObj()), False) |
448 | | self.assertEqual(self.user1.has_perm('inactive', TestObj()), True) |
| 448 | #self.assertEqual(self.user1.has_perm('inactive', TestObj()), True) # Why? |
| 449 | # Inactive user should not have any permissions! |
| 450 | self.assertEqual(self.user1.has_perm('inactive', TestObj()), False) |
449 | 451 | |
450 | 452 | def test_has_module_perms(self): |
451 | 453 | self.assertEqual(self.user1.has_module_perms("app1"), False) |