Project

General

Profile

Actions

Feature #32545

open

Plugin API for adding a new notification

Added by Hong Cheu Lim almost 5 years ago. Updated over 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Plugin API
Start date:
Due date:
% Done:

0%

Estimated time:
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')


Actions

Also available in: Atom PDF