Commits

Jens Diemer committed f0e5b1c

don't filter category groups for superusers
---

  • Participants
  • Parent commits 3cea918

Comments (0)

Files changed (2)

File djangobb_forum/models.py

         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

File djangobb_forum/views.py

     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': []})