Project

General

Profile

Actions

Feature #32545

open

Plugin API for adding a new notification

Added by Hong Cheu Lim over 4 years ago. Updated 11 months 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 #1

Updated by Go MAEDA over 3 years ago

  • Category changed from Email notifications to Plugin API
Actions #2

Updated by Vasiliy Gagarskiy 11 months ago

Any news?

Actions #3

Updated by Vasiliy Gagarskiy 11 months ago

Hong Cheu Lim wrote:

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]).

[...]

In any plugin
[...]

Go MAEDA Do you have any thoughts about plugin API, maybe ROADMAP?

Actions #4

Updated by Go MAEDA 11 months ago

  • Target version set to Candidate for next major release
Actions

Also available in: Atom PDF