A platform for community discussion. Free, open, simple.
FIX: do not close the merged topic if the first post wasn't merged (#13564)
Andrei Prigorshnev11baf872ede1
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 8a7d351bfb2..c70ffaa3b0b 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -66,6 +66,18 @@ class PostMoverGuardian.new(user).ensure_can_see! topic@destination_topic = topic+ # when a topic contains some posts after moving posts to another topic we shouldn't close it+ # two types of posts should prevent a topic from closing:+ # 1. regular posts+ # 2. almost all whispers+ # we should only exclude whispers with action_code: 'split_topic'+ # because we use such whispers as a small-action posts when moving posts to the secret message+ # (in this case we don't want everyone to see that posts were moved, that's why we use whispers)+ original_topic_posts_count = @original_topic.posts+ .where("post_type = ? or (post_type = ? and action_code != 'split_topic')", Post.types[:regular], Post.types[:whisper])+ .count+ moving_all_posts = original_topic_posts_count == posts.length+create_temp_tabledelete_invalid_post_timingsmove_each_post@@ -76,11 +88,7 @@ class PostMoverupdate_upload_security_statusupdate_bookmarks- posts_left = @original_topic.posts- .where("post_type = ? or (post_type = ? and action_code != 'split_topic')", Post.types[:regular], Post.types[:whisper])- .count-- if posts_left == 1+ if moving_all_postsclose_topic_and_schedule_deletionenddiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 11c3eef1361..6c3e3a43ef9 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -626,7 +626,17 @@ describe PostMover doit "doesn't close the topic when not all posts were moved" dotopic.expects(:add_moderator_post).once- posts_to_move = [p1.id, p2.id, p3.id]+ posts_to_move = [p2.id, p3.id]+ moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)+ expect(moved_to).to be_present++ topic.reload+ expect(topic).to_not be_closed+ end++ it "doesn't close the topic when all posts except the first one were moved" do+ topic.expects(:add_moderator_post).once+ posts_to_move = [p2.id, p3.id, p4.id]moved_to = topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)expect(moved_to).to be_present