From e01e7c1bcf88d43b16d1c4b9dee3036d03bb032e Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 19 Dec 2023 14:32:15 +0100 Subject: [PATCH] Update CI config: add Redmine 5 --- .github/workflows/{4_1_7.yml => 5_1_1.yml} | 6 +-- .github/workflows/master.yml | 2 +- README.md | 4 +- init.rb | 7 +-- lib/redmine_notified/hooks.rb | 9 ++++ .../mail_notifications_subscriber.rb | 46 ++++++++++--------- .../notifications_association_patch.rb | 4 +- 7 files changed, 43 insertions(+), 35 deletions(-) rename .github/workflows/{4_1_7.yml => 5_1_1.yml} (98%) diff --git a/.github/workflows/4_1_7.yml b/.github/workflows/5_1_1.yml similarity index 98% rename from .github/workflows/4_1_7.yml rename to .github/workflows/5_1_1.yml index 689c7a0..929f1c9 100644 --- a/.github/workflows/4_1_7.yml +++ b/.github/workflows/5_1_1.yml @@ -1,8 +1,8 @@ -name: Tests 4.1.7 +name: Tests 5.1.1 env: PLUGIN_NAME: redmine_notified - REDMINE_VERSION: 4.1.7 + REDMINE_VERSION: 5.1.1 RAILS_ENV: test on: @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['2.6'] + ruby: ['3.1'] db: ['postgres'] fail-fast: false diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index dbb29b9..1d058e7 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['2.7'] + ruby: ['3.1'] db: ['postgres'] fail-fast: false diff --git a/README.md b/README.md index 908bb9a..0fc20d0 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,11 @@ Test status |Plugin branch| Redmine Version | Test Status | |-------------|-------------------|------------------| |master | 4.2.11 | [![4.2.11][1]][5]| -|master | 4.1.7 | [![4.1.7][2]][5] | +|master | 5.1.1 | [![5.1.1][2]][5] | |master | master | [![master][4]][5]| [1]: https://github.com/jbbarth/redmine_notified/actions/workflows/4_2_11.yml/badge.svg -[2]: https://github.com/jbbarth/redmine_notified/actions/workflows/4_1_7.yml/badge.svg +[2]: https://github.com/jbbarth/redmine_notified/actions/workflows/5_1_1.yml/badge.svg [4]: https://github.com/jbbarth/redmine_notified/actions/workflows/master.yml/badge.svg [5]: https://github.com/jbbarth/redmine_notified/actions diff --git a/init.rb b/init.rb index e817899..6ac9662 100644 --- a/init.rb +++ b/init.rb @@ -1,10 +1,5 @@ require 'redmine' -require 'redmine_notified/hooks' - -ActiveSupport::Reloader.to_prepare do - require_dependency 'redmine_notified/mail_notifications_subscriber' - require_dependency 'redmine_notified/notifications_association_patch' -end +require_relative 'lib/redmine_notified/hooks' Redmine::Plugin.register :redmine_notified do name 'Redmine Notified plugin' diff --git a/lib/redmine_notified/hooks.rb b/lib/redmine_notified/hooks.rb index 679a6fc..8db868c 100644 --- a/lib/redmine_notified/hooks.rb +++ b/lib/redmine_notified/hooks.rb @@ -1,8 +1,17 @@ module RedmineNotified + class Hooks < Redmine::Hook::ViewListener #adds our css on each page def view_layouts_base_html_head(context) stylesheet_link_tag('plugin', :plugin => "redmine_notified") end end + + class ModelHook < Redmine::Hook::Listener + def after_plugins_loaded(_context = {}) + require_relative 'mail_notifications_subscriber' + require_relative 'notifications_association_patch' + end + end + end diff --git a/lib/redmine_notified/mail_notifications_subscriber.rb b/lib/redmine_notified/mail_notifications_subscriber.rb index 41bacf4..ca15d90 100644 --- a/lib/redmine_notified/mail_notifications_subscriber.rb +++ b/lib/redmine_notified/mail_notifications_subscriber.rb @@ -1,24 +1,28 @@ -ActiveSupport::Notifications.subscribe "deliver.action_mailer" do |name, start, finish, id, payload| - attrs = payload.dup.stringify_keys - %w(from to cc bcc).each do |key| - attrs[key] = attrs[key].join(", ") if attrs.has_key?(key) && attrs[key].is_a?(Enumerable) - end - attrs['mail'] = nil - begin - new_notif = Notification.new(attrs.slice(*Notification.column_names)) - new_notif.infer_object_from_message_id - old_notif = Notification.where(:notificable_type => new_notif.notificable_type, :notificable_id => new_notif.notificable_id).first - if old_notif - bcc = [] - bcc |= old_notif.bcc.split(', ') if old_notif.bcc.present? - bcc |= new_notif.bcc.split(', ') if new_notif.bcc.present? - old_notif.bcc = bcc.join(", ") - old_notif.save - else - new_notif.save +module RedmineNotified + module MailNotificationsSubscriber + ActiveSupport::Notifications.subscribe "deliver.action_mailer" do |name, start, finish, id, payload| + attrs = payload.dup.stringify_keys + %w(from to cc bcc).each do |key| + attrs[key] = attrs[key].join(", ") if attrs.has_key?(key) && attrs[key].is_a?(Enumerable) + end + attrs['mail'] = nil + begin + new_notif = Notification.new(attrs.slice(*Notification.column_names)) + new_notif.infer_object_from_message_id + old_notif = Notification.where(:notificable_type => new_notif.notificable_type, :notificable_id => new_notif.notificable_id).first + if old_notif + bcc = [] + bcc |= old_notif.bcc.split(', ') if old_notif.bcc.present? + bcc |= new_notif.bcc.split(', ') if new_notif.bcc.present? + old_notif.bcc = bcc.join(", ") + old_notif.save + else + new_notif.save + end + rescue + #this shouldn't happen, but hey, we don't want to prevent ticket creation if anything fails + Rails.logger.error("ERROR: redmine_notified plugin, unable to add notification for #{attrs.inspect}") + end end - rescue - #this shouldn't happen, but hey, we don't want to prevent ticket creation if anything fails - Rails.logger.error("ERROR: redmine_notified plugin, unable to add notification for #{attrs.inspect}") end end diff --git a/lib/redmine_notified/notifications_association_patch.rb b/lib/redmine_notified/notifications_association_patch.rb index 180c7c5..ca4ec0a 100644 --- a/lib/redmine_notified/notifications_association_patch.rb +++ b/lib/redmine_notified/notifications_association_patch.rb @@ -1,4 +1,4 @@ -module NotificationsAssociationPatch +module RedmineNotified::NotificationsAssociationPatch def self.included(base) base.class_eval do has_many :notifications, :as => :notificable @@ -8,5 +8,5 @@ def self.included(base) %w(issue journal news comment message wiki_content).each do |klass| require_dependency klass - klass.camelize.constantize.send(:include, NotificationsAssociationPatch) + klass.camelize.constantize.send(:include, RedmineNotified::NotificationsAssociationPatch) end