mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FIX: If creating a flag for a watched word, include the reason
This commit is contained in:
parent
3e8d548d35
commit
4e3a84c687
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user