diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
index 9d67466..215c89d 100644
a
|
b
|
class ModelBackend(object):
|
19 | 19 | except User.DoesNotExist: |
20 | 20 | return None |
21 | 21 | |
| 22 | def get_user_permissions(self, user_obj): |
| 23 | """ |
| 24 | Returns a set of permission strings directly tied to user_obj. |
| 25 | """ |
| 26 | return set([u"%s.%s" % (p.content_type.app_label, p.codename) |
| 27 | for p in user_obj.user_permissions.select_related()]) |
| 28 | |
22 | 29 | def get_group_permissions(self, user_obj): |
23 | 30 | """ |
24 | 31 | Returns a set of permission strings that this user has through his/her |
… |
… |
class ModelBackend(object):
|
35 | 42 | if user_obj.is_anonymous(): |
36 | 43 | return set() |
37 | 44 | if not hasattr(user_obj, '_perm_cache'): |
38 | | user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()]) |
| 45 | user_obj._perm_cache = self.get_user_permissions(user_obj) |
39 | 46 | user_obj._perm_cache.update(self.get_group_permissions(user_obj)) |
40 | 47 | return user_obj._perm_cache |
41 | 48 | |
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
index 00b95ba..1dcf2bd 100644
a
|
b
|
Methods
|
209 | 209 | :meth:`~django.contrib.auth.models.User.set_unusable_password()` has |
210 | 210 | been called for this user. |
211 | 211 | |
| 212 | .. method:: models.User.get_user_permissions(obj=None) |
| 213 | |
| 214 | Returns a list of permission strings that the user has. |
| 215 | |
| 216 | .. versionadded:: 1.3 |
| 217 | |
| 218 | If ``obj`` is passed in, only returns the user permissions for |
| 219 | this specific object. |
| 220 | |
212 | 221 | .. method:: models.User.get_group_permissions(obj=None) |
213 | 222 | |
214 | 223 | Returns a list of permission strings that the user has, through his/her |
… |
… |
Handling authorization in custom backends
|
1527 | 1536 | Custom auth backends can provide their own permissions. |
1528 | 1537 | |
1529 | 1538 | The user model will delegate permission lookup functions |
1530 | | (:meth:`~django.contrib.auth.models.User.get_group_permissions()`, |
| 1539 | ((:meth:`~django.contrib.auth.models.User.get_user_permissions()`, |
| 1540 | :meth:`~django.contrib.auth.models.User.get_group_permissions()`, |
1531 | 1541 | :meth:`~django.contrib.auth.models.User.get_all_permissions()`, |
1532 | 1542 | :meth:`~django.contrib.auth.models.User.has_perm()`, and |
1533 | 1543 | :meth:`~django.contrib.auth.models.User.has_module_perms()`) to any |