mirror of
https://github.com/discourse/discourse.git
synced 2025-08-17 18:04:11 +08:00
DEV: Add Plugin modifier for reviewable creation (bot posts) (#33161)
I need reviewables to be created for bot users in a private plugin. This allows me to do that.
This commit is contained in:
parent
5314b6aa82
commit
e39c7b4cbb
2 changed files with 36 additions and 1 deletions
|
@ -384,7 +384,17 @@ class PostActionCreator
|
|||
|
||||
def create_reviewable(result)
|
||||
return unless flagging_post?
|
||||
return if @post.user_id.to_i < 0
|
||||
|
||||
# Return early if the reviewable is being created for a user with a negative user_id.
|
||||
# Plugin apply_modifier can remove this early return for special cases.
|
||||
is_bot_post = @post.user_id.to_i < 0
|
||||
if DiscoursePluginRegistry.apply_modifier(
|
||||
:post_action_creator_block_reviewable_for_bot,
|
||||
is_bot_post,
|
||||
@post,
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
result.reviewable =
|
||||
ReviewableFlaggedPost.needs_review!(
|
||||
|
|
|
@ -196,6 +196,31 @@ RSpec.describe PostActionCreator do
|
|||
end
|
||||
end
|
||||
|
||||
describe "non-human user being flagged" do
|
||||
fab!(:system_post) { Fabricate(:post, user: Discourse.system_user) }
|
||||
|
||||
it "doesn't create reviewable" do
|
||||
result = PostActionCreator.create(user, system_post, :inappropriate)
|
||||
expect(result.success?).to eq(true)
|
||||
|
||||
expect(result.reviewable).to be_blank
|
||||
end
|
||||
|
||||
it "applies modifier and can allow reviewable creation for non-human users" do
|
||||
plugin = Plugin::Instance.new
|
||||
modifier = :post_action_creator_block_reviewable_for_bot
|
||||
proc = Proc.new { false }
|
||||
DiscoursePluginRegistry.register_modifier(plugin, modifier, &proc)
|
||||
|
||||
result = PostActionCreator.create(user, system_post, :inappropriate)
|
||||
expect(result.success?).to eq(true)
|
||||
|
||||
expect(result.reviewable).to be_present
|
||||
ensure
|
||||
DiscoursePluginRegistry.unregister_modifier(plugin, modifier, &proc)
|
||||
end
|
||||
end
|
||||
|
||||
context "with existing reviewable" do
|
||||
let!(:reviewable) do
|
||||
PostActionCreator.create(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue