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

This commit is contained in:
Robin Ward 2020-06-02 11:49:02 -04:00
parent 3e8d548d35
commit 4e3a84c687
3 changed files with 26 additions and 5 deletions

View File

@ -44,7 +44,12 @@ module Jobs
s = post.cooked s = post.cooked
s << " #{post.topic.title}" if post.post_number == 1 s << " #{post.topic.title}" if post.post_number == 1
if !args[:bypass_bump] && WordWatcher.new(s).should_flag? 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 end
end end

View File

@ -7,8 +7,15 @@ class PostActionCreator
# Shortcut methods for easier invocation # Shortcut methods for easier invocation
class << self class << self
def create(created_by, post, action_key, message: nil, created_at: nil) 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).perform new(
created_by,
post,
PostActionType.types[action_key],
message: message,
created_at: created_at,
reason: reason
).perform
end end
[:like, :off_topic, :spam, :inappropriate, :bookmark].each do |action| [:like, :off_topic, :spam, :inappropriate, :bookmark].each do |action|
@ -31,7 +38,8 @@ class PostActionCreator
message: nil, message: nil,
take_action: false, take_action: false,
flag_topic: false, flag_topic: false,
created_at: nil created_at: nil,
reason: nil
) )
@created_by = created_by @created_by = created_by
@created_at = created_at || Time.zone.now @created_at = created_at || Time.zone.now
@ -46,6 +54,7 @@ class PostActionCreator
@message = message @message = message
@flag_topic = flag_topic @flag_topic = flag_topic
@meta_post = nil @meta_post = nil
@reason = reason
end end
def post_can_act? def post_can_act?
@ -306,6 +315,7 @@ private
created_at: @created_at, created_at: @created_at,
take_action: @take_action, take_action: @take_action,
meta_topic_id: @meta_post&.topic_id, meta_topic_id: @meta_post&.topic_id,
reason: @reason
) )
end end

View File

@ -141,7 +141,13 @@ describe WatchedWord do
end end
it "should flag the post as inappropriate" do 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 end
it "should look at the title too" do it "should look at the title too" do