Feature #32545

Plugin API for adding a new notification

Added by Hong Cheu Lim 11 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Email notifications
Target version:-
Resolution:

Description

In lib/redmine/notifiable.rb, there is a TODO: Plugin API for adding a new notification?.
I found out that, one can provide this API via Redmine Hooks, although I dont know if this is the correct approach.
The patch below seems to be working at least for me (Redmine 4.0.5, ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]).

diff --git a/lib/redmine/notifiable.rb b/lib/redmine/notifiable.rb
index 41fd736..822d216 100644
--- a/lib/redmine/notifiable.rb
+++ b/lib/redmine/notifiable.rb
@@ -21,6 +21,9 @@ module Redmine
       notifications << Notifiable.new('message_posted')
       notifications << Notifiable.new('wiki_content_added')
       notifications << Notifiable.new('wiki_content_updated')
+      Redmine::Hook.call_hook(:add_notifiable).each do |notifiable|
+        notifications += notifiable
+      end
       notifications
     end
   end

In any plugin

# In plugins/my_plugin/lib/hooks.rb
module MyPluginHooks
  class MyPluginHooks < Redmine::Hook::Listener
    def add_notifiable(_context)
      [Redmine::Notifiable.new('my_plugin_new_notifiable')]
    end
  end
end

# In plugins/my_plugin/init.rb
...
require_relative 'lib/hooks.rb'
...

# Now we can use
Setting.notified_events.include?('my_plugin_new_notifiable')


Also available in: Atom PDF