Browse Source

small improvements in tests coverate for threads permissions

Rafał Pitoń 8 years ago
parent
commit
d662567b63
2 changed files with 61 additions and 25 deletions
  1. 0 25
      misago/threads/permissions/threads.py
  2. 61 0
      misago/threads/tests/test_threadslists.py

+ 0 - 25
misago/threads/permissions/threads.py

@@ -802,31 +802,6 @@ def has_time_to_edit_post(user, target):
 """
 Queryset helpers
 """
-def exclude_invisible_category_threads(queryset, user, category):
-    if user.is_authenticated():
-        condition_author = Q(starter_id=user.id)
-
-        can_mod = category.acl['can_approve_content']
-        can_hide = category.acl['can_hide_threads']
-
-        if not can_mod and not can_hide:
-            condition = Q(is_unapproved=False) & Q(is_hidden=False)
-            queryset = queryset.filter(condition_author | condition)
-        elif not can_mod:
-            condition = Q(is_unapproved=False)
-            queryset = queryset.filter(condition_author | condition)
-        elif not can_hide:
-            condition = Q(is_hidden=False)
-            queryset = queryset.filter(condition_author | condition)
-    else:
-        if not category.acl['can_approve_content']:
-            queryset = queryset.filter(is_unapproved=False)
-        if not category.acl['can_hide_threads']:
-            queryset = queryset.filter(is_hidden=False)
-
-    return queryset
-
-
 def exclude_invisible_threads(user, categories, queryset):
     show_all = []
     show_accepted_visible = []

+ 61 - 0
misago/threads/tests/test_threadslists.py

@@ -12,6 +12,7 @@ from misago.categories.models import Category
 from misago.core import threadstore
 from misago.core.cache import cache
 from misago.readtracker import categoriestracker, threadstracker
+from misago.users.models import AnonymousUser
 from misago.users.testutils import AuthenticatedUserTestCase
 
 from .. import testutils
@@ -1593,3 +1594,63 @@ class UnapprovedListTests(ThreadsListTestCase):
         self.assertEqual(response.status_code, 200)
         self.assertContains(response, visible_thread.get_absolute_url())
         self.assertNotContains(response, hidden_thread.get_absolute_url())
+
+
+class OwnerOnlyThreadsVisibilityTests(AuthenticatedUserTestCase):
+    def setUp(self):
+        super(OwnerOnlyThreadsVisibilityTests, self).setUp()
+
+        self.category = Category.objects.get(slug='first-category')
+
+    def override_acl(self, user):
+        category_acl = user.acl['categories'][self.category.pk].copy()
+        category_acl.update({
+            'can_see_all_threads': 0
+        })
+        user.acl['categories'][self.category.pk] = category_acl
+
+        override_acl(user, user.acl)
+
+    def test_owned_threads_visibility(self):
+        """only user-posted threads are visible in category"""
+        self.override_acl(self.user)
+
+        visible_thread = testutils.post_thread(
+            poster=self.user,
+            category=self.category,
+            is_unapproved=True,
+        )
+
+        hidden_thread = testutils.post_thread(
+            category=self.category,
+            is_unapproved=True,
+        )
+
+        response = self.client.get(self.category.get_absolute_url())
+
+        self.assertEqual(response.status_code, 200)
+        self.assertContains(response, visible_thread.get_absolute_url())
+        self.assertNotContains(response, hidden_thread.get_absolute_url())
+
+    def test_owned_threads_visibility_anonymous(self):
+        """anons can't see any threads in limited visibility category"""
+        self.logout_user()
+
+        self.override_acl(AnonymousUser())
+
+        user_thread = testutils.post_thread(
+            poster=self.user,
+            category=self.category,
+            is_unapproved=True,
+        )
+
+        guest_thread = testutils.post_thread(
+            category=self.category,
+            is_unapproved=True,
+        )
+
+        response = self.client.get(self.category.get_absolute_url())
+
+        self.assertEqual(response.status_code, 200)
+        self.assertNotContains(response, user_thread.get_absolute_url())
+        self.assertNotContains(response, guest_thread.get_absolute_url())