2
0
Fork 0
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:
Mark VanLandingham 2025-06-11 14:57:33 -05:00 committed by GitHub
parent 5314b6aa82
commit e39c7b4cbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -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!(

View file

@ -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(