1 | Index: django/contrib/auth/backends.py
|
---|
2 | ===================================================================
|
---|
3 | --- django/contrib/auth/backends.py (revision 12120)
|
---|
4 | +++ django/contrib/auth/backends.py (working copy)
|
---|
5 | @@ -%ld,%ld +%ld,%ld @@
|
---|
6 | Returns a set of permission strings that this user has through his/her
|
---|
7 | groups.
|
---|
8 | """
|
---|
9 | + if user_obj.is_anonymous():
|
---|
10 | + return set([])
|
---|
11 | if not hasattr(user_obj, '_group_perm_cache'):
|
---|
12 | cursor = connection.cursor()
|
---|
13 | # The SQL below works out to the following, after DB quoting:
|
---|
14 | @@ -%ld,%ld +%ld,%ld @@
|
---|
15 | return user_obj._group_perm_cache
|
---|
16 |
|
---|
17 | def get_all_permissions(self, user_obj):
|
---|
18 | + if user_obj.is_anonymous():
|
---|
19 | + return set([])
|
---|
20 | if not hasattr(user_obj, '_perm_cache'):
|
---|
21 | user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()])
|
---|
22 | user_obj._perm_cache.update(self.get_group_permissions(user_obj))
|
---|
23 | Index: django/contrib/auth/models.py
|
---|
24 | ===================================================================
|
---|
25 | --- django/contrib/auth/models.py (revision 12120)
|
---|
26 | +++ django/contrib/auth/models.py (working copy)
|
---|
27 | @@ -%ld,%ld +%ld,%ld @@
|
---|
28 | user_permissions = property(_get_user_permissions)
|
---|
29 |
|
---|
30 | def has_perm(self, perm, obj=None):
|
---|
31 | + for backend in auth.get_backends():
|
---|
32 | + if hasattr(backend, "has_perm"):
|
---|
33 | + if obj is not None:
|
---|
34 | + if (backend.supports_object_permissions and
|
---|
35 | + backend.has_perm(self, perm, obj)):
|
---|
36 | + return True
|
---|
37 | + else:
|
---|
38 | + if backend.has_perm(self, perm):
|
---|
39 | + return True
|
---|
40 | return False
|
---|
41 |
|
---|
42 | def has_perms(self, perm_list, obj=None):
|
---|
43 | - return False
|
---|
44 | + """
|
---|
45 | + Returns True if the user has each of the specified permissions.
|
---|
46 | + If object is passed, it checks if the user has all required perms
|
---|
47 | + for this object.
|
---|
48 | + """
|
---|
49 | + for perm in perm_list:
|
---|
50 | + if not self.has_perm(perm, obj):
|
---|
51 | + return False
|
---|
52 | + return True
|
---|
53 |
|
---|
54 | def has_module_perms(self, module):
|
---|
55 | + for backend in auth.get_backends():
|
---|
56 | + if hasattr(backend, "has_module_perms"):
|
---|
57 | + if backend.has_module_perms(self, app_label):
|
---|
58 | + return True
|
---|
59 | return False
|
---|
60 |
|
---|
61 | def get_and_delete_messages(self):
|
---|