don't filter category groups for superusers
---
This commit is contained in:
parent
d27719803d
commit
b93392594a
2 changed files with 12 additions and 10 deletions
|
@ -83,10 +83,12 @@ class Category(models.Model):
|
|||
return Post.objects.filter(topic__forum__category__id=self.id).select_related()
|
||||
|
||||
def has_access(self, user):
|
||||
if user.is_superuser:
|
||||
return True
|
||||
if self.groups.exists():
|
||||
if user.is_authenticated():
|
||||
if not self.groups.filter(user__pk=user.id).exists():
|
||||
return False
|
||||
if not self.groups.filter(user__pk=user.id).exists():
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -39,16 +39,16 @@ def index(request, full=True):
|
|||
guest_count = len(guests_cached)
|
||||
users_count = len(users_online)
|
||||
|
||||
_forums = Forum.objects.all()
|
||||
user = request.user
|
||||
if not user.is_superuser:
|
||||
user_groups = user.groups.all() or [] # need 'or []' for anonymous user otherwise: 'EmptyManager' object is not iterable
|
||||
_forums = _forums.filter(Q(category__groups__in=user_groups) | Q(category__groups__isnull=True))
|
||||
|
||||
_forums = _forums.select_related('last_post__topic', 'last_post__user', 'category')
|
||||
|
||||
cats = {}
|
||||
forums = {}
|
||||
user_groups = request.user.groups.all()
|
||||
if request.user.is_anonymous(): # in django 1.1 EmptyQuerySet raise exception
|
||||
user_groups = []
|
||||
_forums = Forum.objects.filter(
|
||||
Q(category__groups__in=user_groups) | \
|
||||
Q(category__groups__isnull=True)).select_related('last_post__topic',
|
||||
'last_post__user',
|
||||
'category')
|
||||
for forum in _forums:
|
||||
cat = cats.setdefault(forum.category.id,
|
||||
{'id': forum.category.id, 'cat': forum.category, 'forums': []})
|
||||
|
|
Reference in a new issue