DEV: adds plugin api to add custom recipients of a post revision (#10367)
* DEV: adds plugin api to add custom recipients of a post revision Usage: ``` add_post_revision_notifier_recipients do |post_revision| [78] end ```
This commit is contained in:
parent
712ab33ff8
commit
8a0478b97d
|
@ -114,6 +114,10 @@ class PostActionNotifier
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
custom_post_revision_notifier_recipients.each do |block|
|
||||||
|
user_ids.concat(block.call(post_revision))
|
||||||
|
end
|
||||||
|
|
||||||
if user_ids.present?
|
if user_ids.present?
|
||||||
DB.after_commit do
|
DB.after_commit do
|
||||||
Jobs.enqueue(:notify_post_revision,
|
Jobs.enqueue(:notify_post_revision,
|
||||||
|
@ -137,4 +141,12 @@ class PostActionNotifier
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.custom_post_revision_notifier_recipients
|
||||||
|
@custom_post_revision_notifier_recipients ||= Set.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.add_post_revision_notifier_recipients(&block)
|
||||||
|
custom_post_revision_notifier_recipients << block
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -280,6 +280,15 @@ class Plugin::Instance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Allows to add additional user_ids to the list of people notified when doing a post revision
|
||||||
|
def add_post_revision_notifier_recipients(&block)
|
||||||
|
reloadable_patch do |plugin|
|
||||||
|
::PostActionNotifier.add_post_revision_notifier_recipients do |post_revision|
|
||||||
|
plugin.enabled? ? block.call(post_revision) : []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
|
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
|
||||||
def add_preloaded_group_custom_field(field)
|
def add_preloaded_group_custom_field(field)
|
||||||
reloadable_patch do |plugin|
|
reloadable_patch do |plugin|
|
||||||
|
|
|
@ -98,6 +98,28 @@ describe PostActionNotifier do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when using plugin API to add custom recipients' do
|
||||||
|
let(:lurker) { Fabricate(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
plugin = Plugin::Instance.new
|
||||||
|
plugin.add_post_revision_notifier_recipients do |post_revision|
|
||||||
|
[lurker.id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
DiscoursePluginRegistry.reset!
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'notifies the specified user of the revision' do
|
||||||
|
expect {
|
||||||
|
post.revise(evil_trout, raw: "world is the new body of the message")
|
||||||
|
}.to change {
|
||||||
|
lurker.notifications.count
|
||||||
|
}.by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'private message' do
|
context 'private message' do
|
||||||
|
|
Loading…
Reference in New Issue