FIX: Moderator actions and small actions shouldn't prevent fully merged topics from closing (#13200)
When a topic is fully merged into another topic we close it and schedule its deleting. But, because of a bug, if the merged topic contains some moderator actions or small actions it won't be merged. This change fixes this problem. An important note: in general, we don't want to close a topic after moving posts if it still contains some regular posts or whispers. But when we are moving posts to a private message we don't want the notice about it to be publicly visible. So we use whispers with action_code == 'split_topic' instead of small_actions in such cases and we should ignore this specific kind of whispers when decide if we should close the merged topic.
This commit is contained in:
parent
d9484db718
commit
b7b8f5e6f3
|
@ -66,8 +66,6 @@ class PostMover
|
|||
Guardian.new(user).ensure_can_see! topic
|
||||
@destination_topic = topic
|
||||
|
||||
moving_all_posts = (@original_topic.posts.pluck(:id).sort == @post_ids.sort)
|
||||
|
||||
create_temp_table
|
||||
delete_invalid_post_timings
|
||||
move_each_post
|
||||
|
@ -78,7 +76,11 @@ class PostMover
|
|||
update_upload_security_status
|
||||
update_bookmarks
|
||||
|
||||
if moving_all_posts
|
||||
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
|
||||
close_topic_and_schedule_deletion
|
||||
end
|
||||
|
||||
|
|
|
@ -58,6 +58,14 @@ describe PostMover do
|
|||
@like = PostActionCreator.like(another_user, p4)
|
||||
end
|
||||
|
||||
def add_moderator_post_to(topic, post_type)
|
||||
topic.add_moderator_post(
|
||||
user,
|
||||
"message",
|
||||
post_type: post_type,
|
||||
action_code: "split_topic")
|
||||
end
|
||||
|
||||
context 'success' do
|
||||
|
||||
it "correctly handles notifications and bread crumbs" do
|
||||
|
@ -664,6 +672,17 @@ describe PostMover do
|
|||
expect(timer).to be_nil
|
||||
end
|
||||
|
||||
it "ignores moderator posts and closes the topic if all regular posts were moved" do
|
||||
add_moderator_post_to topic, Post.types[:moderator_action]
|
||||
add_moderator_post_to topic, Post.types[:small_action]
|
||||
|
||||
posts_to_move = [p1.id, p2.id, p3.id, p4.id]
|
||||
topic.move_posts(user, posts_to_move, destination_topic_id: destination_topic.id)
|
||||
|
||||
topic.reload
|
||||
expect(topic).to be_closed
|
||||
end
|
||||
|
||||
it "does not try to move small action posts" do
|
||||
small_action = Fabricate(:post, topic: topic, raw: "A small action", post_type: Post.types[:small_action])
|
||||
moved_to = topic.move_posts(user, [p1.id, p2.id, p3.id, p4.id, small_action.id], destination_topic_id: destination_topic.id)
|
||||
|
|
Loading…
Reference in New Issue