A platform for community discussion. Free, open, simple.
FIX: Correctly place moderator post for full topic move with freeze_original (#30324)
Mark VanLandingham415abe6491bd
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 1f69c8aa96a..e41683ae9f7 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -97,11 +97,15 @@ class PostMover@first_post_number_moved =posts.first.is_first_post? ? posts[1]&.post_number : posts.first.post_number- if @options[:freeze_original] # in this case we need to add the moderator post after the last copied post- from_posts = @original_topic.ordered_posts.where("post_number > ?", posts.last.post_number)- shift_post_numbers(from_posts) if !@full_move-- @first_post_number_moved = posts.last.post_number + 1+ if @options[:freeze_original]+ # in this case we need to add the moderator post after the last copied post+ if @full_move+ @first_post_number_moved = @original_topic.ordered_posts.last.post_number + 1+ else+ from_posts = @original_topic.ordered_posts.where("post_number > ?", posts.last.post_number)+ shift_post_numbers(from_posts)+ @first_post_number_moved = posts.last.post_number + 1+ endendmove_each_postdiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 35ac77d282d..ecf999d04c3 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -2898,7 +2898,7 @@ RSpec.describe PostMover do).to eq(true)end- it "creates the moderator message in the correct position" do+ it "creates the moderator message in the correct position for partial move" doPostMover.new(original_topic,Discourse.system_user,@@ -2908,11 +2908,34 @@ RSpec.describe PostMover do},).to_topic(destination_topic.id)- moderator_post =- original_topic.reload.ordered_posts.find_by(post_number: second_post.post_number + 1) # the next post- expect(moderator_post).to be_present- expect(moderator_post.post_type).to eq(Post.types[:small_action])- expect(moderator_post.action_code).to eq("split_topic")+ # Moderator post is right after the second_post since it was the last post moved+ expect(+ original_topic.ordered_posts.find_by(+ post_number: second_post.post_number + 1,+ post_type: Post.types[:small_action],+ action_code: "split_topic",+ ),+ ).to be_present+ end++ it "creates the moderator message in the correct position for full move" do+ small_action = Fabricate(:small_action, topic: original_topic)+ PostMover.new(+ original_topic,+ Discourse.system_user,+ [op.id, first_post.id, second_post.id, third_post.id],+ options: {+ freeze_original: true,+ },+ ).to_topic(destination_topic.id)++ expect(+ original_topic.ordered_posts.find_by(+ post_number: small_action.post_number + 1,+ post_type: Post.types[:small_action],+ action_code: "split_topic",+ ),+ ).to be_presentendcontext "with `post_mover_create_moderator_post` modifier" do