From c02956e29c403bd971e4156c682dc9831e5ccd5e Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 28 Feb 2019 19:49:26 +0530 Subject: [PATCH] FIX: when posts are moved to a message then small action post should not be publicly visible (#7085) This fix is inspired from what we do in discourse-assigned plugin. https://github.com/discourse/discourse-assign/blob/master/lib/topic_assigner.rb#L184 https://github.com/discourse/discourse-assign/blob/master/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6#L125-L133 --- app/assets/javascripts/discourse/lib/transform-post.js.es6 | 3 ++- app/models/post_mover.rb | 3 ++- spec/models/post_mover_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6 index a560d1ba702..c0371aa157e 100644 --- a/app/assets/javascripts/discourse/lib/transform-post.js.es6 +++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6 @@ -114,7 +114,8 @@ export default function transformPost( postAtts.isAutoGenerated = post.is_auto_generated; postAtts.isModeratorAction = postType === postTypes.moderator_action; postAtts.isWhisper = postType === postTypes.whisper; - postAtts.isSmallAction = postType === postTypes.small_action; + postAtts.isSmallAction = + postType === postTypes.small_action || post.action_code === "split_topic"; postAtts.canBookmark = !!currentUser; postAtts.canManage = currentUser && currentUser.get("canManageTopic"); postAtts.canViewRawEmail = diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 47e8790018b..44dfed9b9b7 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -208,9 +208,10 @@ class PostMover ) end + post_type = @move_to_pm ? Post.types[:whisper] : Post.types[:small_action] original_topic.add_moderator_post( user, message, - post_type: Post.types[:small_action], + post_type: post_type, action_code: "split_topic", post_number: @first_post_number_moved ) diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 01dc7cf101a..80e707b25fe 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -619,7 +619,7 @@ describe PostMover do old_message.reload move_message = old_message.posts.find_by(post_number: 2) - expect(move_message.post_type).to eq(Post.types[:small_action]) + expect(move_message.post_type).to eq(Post.types[:whisper]) expect(move_message.raw).to include("2 posts were split") end end @@ -662,7 +662,7 @@ describe PostMover do it "uses the correct small action post" do moved_to = personal_message.move_posts(admin, [p2.id], destination_topic_id: another_personal_message.id, archetype: "private_message") - post = Post.find_by(topic_id: personal_message.id, post_type: Post.types[:small_action]) + post = Post.find_by(topic_id: personal_message.id, post_type: Post.types[:whisper]) expected_text = I18n.t( "move_posts.existing_message_moderator_post",