FIX: If creating a flag for a watched word, include the reason

FIX: If creating a flag for a watched word, include the reason

diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb
index 871e1db..24048a5 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 ab38576..f647a43 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 4657c7e..b8f5fff 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

GitHub sha: 4e3a84c6

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/suggestion-modifiation-of-the-word-list-filter-approval-popup/115458/11