Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_group_permissions by doing a separate lookup for the groups list... #5

Merged
merged 1 commit into from
Jan 31, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions permission_backend_nonrel/backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from django.contrib.auth.models import User, Group

from models import UserPermissionList, GroupPermissionList

Expand All @@ -10,7 +10,7 @@ class NonrelPermissionBackend(ModelBackend):
"""
supports_object_permissions = False
supports_anonymous_user = True

def get_group_permissions(self, user_obj, user_perm_obj=None):
"""
Returns a set of permission strings that this user has through his/her
Expand All @@ -20,27 +20,28 @@ def get_group_permissions(self, user_obj, user_perm_obj=None):
perms = set([])
if user_perm_obj is None:
user_perm_obj, created = UserPermissionList.objects.get_or_create(user=user_obj)

group_perm_lists = GroupPermissionList.objects.filter(group__id__in=user_perm_obj.group_fk_list)


groups = Group.objects.filter(id__in=user_perm_obj.group_fk_list)
group_perm_lists = GroupPermissionList.objects.filter(group__in=list(groups))

for group_perm_list in group_perm_lists:
perms.update(group_perm_list.permission_list)

user_obj._group_perm_cache = perms
return user_obj._group_perm_cache

def get_all_permissions(self, user_obj):
if user_obj.is_anonymous():
return set()
if not hasattr(user_obj, '_perm_cache'):
try:
pl = UserPermissionList.objects.get(user=user_obj)
user_obj._perm_cache = set(pl.permission_list)

except UserPermissionList.DoesNotExist:
pl = None
user_obj._perm_cache = set()

user_obj._perm_cache.update(self.get_group_permissions(user_obj,
pl))
return user_obj._perm_cache
Expand Down