diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index f16d8f5a..676b3ea4 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -41,8 +41,7 @@ require File.dirname(__FILE__) + '/redmine_dmsf/patches/queries_controller_patch require File.dirname(__FILE__) + '/redmine_dmsf/patches/pdf_patch' # A workaround for obsolete 'alias_method' usage in RedmineUp's plugins -if (RedmineDmsf::Plugin.present?(:redmine_questions) || Redmine::Plugin.installed?(:redmine_contacts) || - Redmine::Plugin.installed?(:redmine_checklists)) && !Redmine::Plugin.installed?(:easy_extensions) +if RedmineDmsf::Plugin.an_osolete_plugin_present? require File.dirname(__FILE__) + '/redmine_dmsf/patches/notifiable_ru_patch' else require File.dirname(__FILE__) + '/redmine_dmsf/patches/notifiable_patch' diff --git a/lib/redmine_dmsf/patches/notifiable_patch.rb b/lib/redmine_dmsf/patches/notifiable_patch.rb index a61a812a..c14530d0 100644 --- a/lib/redmine_dmsf/patches/notifiable_patch.rb +++ b/lib/redmine_dmsf/patches/notifiable_patch.rb @@ -55,7 +55,6 @@ end if Redmine::Plugin.installed?(:easy_extensions) RedmineExtensions::PatchManager.register_patch_to_be_first 'Redmine::Notifiable', 'RedmineDmsf::Patches::NotifiablePatch', prepend: true, first: true -elsif(!(RedmineDmsf::Plugin.present?(:redmine_questions) || Redmine::Plugin.installed?(:redmine_contacts) || - Redmine::Plugin.installed?(:redmine_checklists))) +elsif(!RedmineDmsf::Plugin.an_osolete_plugin_present?) Redmine::Notifiable.prepend RedmineDmsf::Patches::NotifiablePatch end diff --git a/lib/redmine_dmsf/plugin.rb b/lib/redmine_dmsf/plugin.rb index 1b7dd974..dd022e35 100644 --- a/lib/redmine_dmsf/plugin.rb +++ b/lib/redmine_dmsf/plugin.rb @@ -29,5 +29,19 @@ module RedmineDmsf Dir.exist? File.join(Rails.root, 'plugins', id.to_s) end + # Return true if a plugin that overrides Redmine::Notifiable and use the deprecated method alias_method_chain is + # present. + # It is related especially to plugins made by AplhaNode and RedmineUP. + def self.an_osolete_plugin_present? + plugins = %w(questions contacts checklists db passwords) + plugins.each do|plugin| + if Plugin.present?("redmine_#{plugin}") + return true + end + end + return false + end + end + end diff --git a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb index 92484476..f1a94450 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb @@ -31,4 +31,17 @@ class DmsfPluginTest < RedmineDmsf::Test::HelperTest assert !RedmineDmsf::Plugin.present?(:redmine_dmsfx) end + def test_an_osolete_plugin_present_no + # No such plugin is present + assert !RedmineDmsf::Plugin.an_osolete_plugin_present? + end + + def test_an_osolete_plugin_present_yes + # Create a fake redmine_checklists plugin + path = File.join(Rails.root, 'plugins', 'redmine_checklists') + Dir.mkdir(path) unless Dir.exist?(path) + assert RedmineDmsf::Plugin.an_osolete_plugin_present? + Dir.rmdir(path) if Dir.exist?(path) + end + end