From 4e3a84c68793f576db84be095039e011a43d2e50 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 2 Jun 2020 11:49:02 -0400 Subject: [PATCH] FIX: If creating a flag for a watched word, include the reason --- app/jobs/regular/process_post.rb | 7 ++++++- lib/post_action_creator.rb | 16 +++++++++++++--- spec/integration/watched_words_spec.rb | 8 +++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb index 871e1dbb4ae..24048a5f46f 100644 --- a/app/jobs/regular/process_post.rb +++ b/app/jobs/regular/process_post.rb @@ -44,7 +44,12 @@ module Jobs s = post.cooked s << " #{post.topic.title}" if post.post_number == 1 if !args[:bypass_bump] && WordWatcher.new(s).should_flag? - PostActionCreator.create(Discourse.system_user, post, :inappropriate) + PostActionCreator.create( + Discourse.system_user, + post, + :inappropriate, + reason: :watched_word + ) end end end diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rb index ab38576c8fa..f647a437cdc 100644 --- a/lib/post_action_creator.rb +++ b/lib/post_action_creator.rb @@ -7,8 +7,15 @@ class PostActionCreator # Shortcut methods for easier invocation class << self - def create(created_by, post, action_key, message: nil, created_at: nil) - new(created_by, post, PostActionType.types[action_key], message: message, created_at: created_at).perform + def create(created_by, post, action_key, message: nil, created_at: nil, reason: nil) + new( + created_by, + post, + PostActionType.types[action_key], + message: message, + created_at: created_at, + reason: reason + ).perform end [:like, :off_topic, :spam, :inappropriate, :bookmark].each do |action| @@ -31,7 +38,8 @@ class PostActionCreator message: nil, take_action: false, flag_topic: false, - created_at: nil + created_at: nil, + reason: nil ) @created_by = created_by @created_at = created_at || Time.zone.now @@ -46,6 +54,7 @@ class PostActionCreator @message = message @flag_topic = flag_topic @meta_post = nil + @reason = reason end def post_can_act? @@ -306,6 +315,7 @@ private created_at: @created_at, take_action: @take_action, meta_topic_id: @meta_post&.topic_id, + reason: @reason ) end diff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rb index 4657c7e0b16..b8f5fff39b5 100644 --- a/spec/integration/watched_words_spec.rb +++ b/spec/integration/watched_words_spec.rb @@ -141,7 +141,13 @@ describe WatchedWord do end it "should flag the post as inappropriate" do - should_flag_post(tl2_user, "I thought the #{flag_word.word} was bad.", Fabricate(:topic, user: tl2_user)) + topic = Fabricate(:topic, user: tl2_user) + post = Fabricate(:post, raw: "I said.... #{flag_word.word}", topic: topic, user: tl2_user) + Jobs::ProcessPost.new.execute(post_id: post.id) + expect(PostAction.where(post_id: post.id, post_action_type_id: PostActionType.types[:inappropriate]).exists?).to eq(true) + reviewable = ReviewableFlaggedPost.where(target: post) + expect(reviewable).to be_present + expect(ReviewableScore.where(reviewable: reviewable, reason: 'watched_word')).to be_present end it "should look at the title too" do