A platform for community discussion. Free, open, simple.
FIX: If creating a flag for a watched word, include the reason
Robin Ward4e3a84c68793
diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rbindex 871e1dbb4ae..24048a5f46f 100644--- a/app/jobs/regular/process_post.rb+++ b/app/jobs/regular/process_post.rb@@ -44,7 +44,12 @@ module Jobss = post.cookeds << " #{post.topic.title}" if post.post_number == 1if !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+ )endendenddiff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rbindex 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 invocationclass << 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+ ).performend[:like, :off_topic, :spam, :inappropriate, :bookmark].each do |action|@@ -31,7 +38,8 @@ class PostActionCreatormessage: 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 = reasonenddef post_can_act?@@ -306,6 +315,7 @@ privatecreated_at: @created_at,take_action: @take_action,meta_topic_id: @meta_post&.topic_id,+ reason: @reason)enddiff --git a/spec/integration/watched_words_spec.rb b/spec/integration/watched_words_spec.rbindex 4657c7e0b16..b8f5fff39b5 100644--- a/spec/integration/watched_words_spec.rb+++ b/spec/integration/watched_words_spec.rb@@ -141,7 +141,13 @@ describe WatchedWord doendit "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_presentendit "should look at the title too" do