Browse Source

wip #887: move posts from closed thread/category

Rafał Pitoń 7 years ago
parent
commit
598d28e2b2

+ 2 - 0
misago/threads/api/postendpoints/move.py

@@ -88,7 +88,9 @@ def clean_posts_for_move(request, thread):
 
 
     posts = []
     posts = []
     for post in posts_queryset:
     for post in posts_queryset:
+        post.category = thread.category
         post.thread = thread
         post.thread = thread
+
         allow_move_post(request.user, post)
         allow_move_post(request.user, post)
         posts.append(post)
         posts.append(post)
 
 

+ 2 - 1
misago/threads/permissions/threads.py

@@ -225,7 +225,8 @@ class CategoryPermissionsForm(forms.Form):
         help_text=_("Only users with this permission can edit protected posts."),
         help_text=_("Only users with this permission can edit protected posts."),
     )
     )
     can_move_posts = YesNoSwitch(
     can_move_posts = YesNoSwitch(
-        label=_("Can move posts"), help_text=_("Will be able to move posts to other threads.")
+        label=_("Can move posts"),
+        help_text=_("Will be able to move posts to other threads."),
     )
     )
     can_merge_posts = YesNoSwitch(label=_("Can merge posts"))
     can_merge_posts = YesNoSwitch(label=_("Can merge posts"))
     can_approve_content = YesNoSwitch(
     can_approve_content = YesNoSwitch(

+ 46 - 3
misago/threads/tests/test_thread_postmove_api.py

@@ -59,7 +59,7 @@ class ThreadPostMoveApiTestCase(AuthenticatedUserTestCase):
 
 
         override_acl(self.user, new_acl)
         override_acl(self.user, new_acl)
 
 
-    def override_other_acl(self, acl=None):
+    def override_other_acl(self, extra_acl=None):
         other_category_acl = self.user.acl_cache['categories'][self.category.pk].copy()
         other_category_acl = self.user.acl_cache['categories'][self.category.pk].copy()
         other_category_acl.update({
         other_category_acl.update({
             'can_see': 1,
             'can_see': 1,
@@ -71,8 +71,8 @@ class ThreadPostMoveApiTestCase(AuthenticatedUserTestCase):
             'can_move_posts': 1,
             'can_move_posts': 1,
         })
         })
 
 
-        if acl:
-            other_category_acl.update(acl)
+        if extra_acl:
+            other_category_acl.update(extra_acl)
 
 
         categories_acl = self.user.acl_cache['categories']
         categories_acl = self.user.acl_cache['categories']
         categories_acl[self.category_b.pk] = other_category_acl
         categories_acl[self.category_b.pk] = other_category_acl
@@ -323,6 +323,49 @@ class ThreadPostMoveApiTestCase(AuthenticatedUserTestCase):
             response, "You can't move posts the content you can't see.", status_code=400
             response, "You can't move posts the content you can't see.", status_code=400
         )
         )
 
 
+    def test_move_posts_closed_thread_no_permission(self):
+        """api recjects attempt to move posts from closed thread"""
+        other_thread = testutils.post_thread(self.category)
+
+        self.thread.is_closed = True
+        self.thread.save()
+
+        self.override_acl({'can_close_threads': 0})
+
+        response = self.client.post(
+            self.api_link,
+            json.dumps({
+                'thread_url': other_thread.get_absolute_url(),
+                'posts': [testutils.reply_thread(self.thread).pk],
+            }),
+            content_type="application/json",
+        )
+        self.assertContains(
+            response, "This thread is closed. You can't move posts in it.", status_code=400
+        )
+
+    def test_move_posts_closed_category_no_permission(self):
+        """api recjects attempt to move posts from closed thread"""
+        other_thread = testutils.post_thread(self.category_b)
+
+        self.category.is_closed = True
+        self.category.save()
+
+        self.override_acl({'can_close_threads': 0})
+        self.override_other_acl({'can_reply_threads': 1})
+
+        response = self.client.post(
+            self.api_link,
+            json.dumps({
+                'thread_url': other_thread.get_absolute_url(),
+                'posts': [testutils.reply_thread(self.thread).pk],
+            }),
+            content_type="application/json",
+        )
+        self.assertContains(
+            response, "This category is closed. You can't move posts in it.", status_code=400
+        )
+
     def test_move_posts(self):
     def test_move_posts(self):
         """api moves posts to other thread"""
         """api moves posts to other thread"""
         self.override_other_acl({'can_reply_threads': 1})
         self.override_other_acl({'can_reply_threads': 1})