From 5dce7c284c9da341a9d8bf33e94f0d106aeca835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Wed, 8 Jun 2022 13:37:25 +0200 Subject: [PATCH] Error while loading /settings #1364 --- lib/redmine_dmsf.rb | 5 +-- lib/redmine_dmsf/patches/notifiable_patch.rb | 2 +- .../patches/notifiable_ru_patch.rb | 5 +-- lib/redmine_dmsf/plugin.rb | 33 ++++++++++++++++++ .../unit/lib/redmine_dmsf/dmsf_plugin_test.rb | 34 +++++++++++++++++++ 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 lib/redmine_dmsf/plugin.rb create mode 100644 test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 6c9250fa..ef1b2f72 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -39,10 +39,7 @@ require File.dirname(__FILE__) + '/redmine_dmsf/patches/issue_patch' require File.dirname(__FILE__) + '/redmine_dmsf/patches/role_patch' require File.dirname(__FILE__) + '/redmine_dmsf/patches/queries_controller_patch' -# redmine_resources depends on redmine_contact and redmine_contacts is alphabetically sorted before redmine_dmsf -# in the plugin list. -if (Redmine::Plugin.installed?(:redmine_contacts) || Redmine::Plugin.installed?(:redmine_questions)) && - !Redmine::Plugin.installed?(:easy_extensions) +if RedmineDmsf::Plugin.present?(:redmine_questions) && !Redmine::Plugin.installed?(:easy_extensions) 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 f1d803d5..9a0bcced 100644 --- a/lib/redmine_dmsf/patches/notifiable_patch.rb +++ b/lib/redmine_dmsf/patches/notifiable_patch.rb @@ -55,6 +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 !(Redmine::Plugin.installed?(:redmine_contacts) || Redmine::Plugin.installed?(:redmine_questions)) +else Redmine::Notifiable.prepend RedmineDmsf::Patches::NotifiablePatch end \ No newline at end of file diff --git a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb b/lib/redmine_dmsf/patches/notifiable_ru_patch.rb index 5c53ba01..1d4fc89a 100644 --- a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb +++ b/lib/redmine_dmsf/patches/notifiable_ru_patch.rb @@ -54,7 +54,4 @@ module RedmineDmsf end # Apply the patch -if (Redmine::Plugin.installed?(:redmine_contacts) || Redmine::Plugin.installed?(:redmine_questions)) && - !Redmine::Plugin.installed?(:easy_extensions) - Redmine::Notifiable.send :include, RedmineDmsf::Patches::NotifiableRuPatch -end \ No newline at end of file +Redmine::Notifiable.send :include, RedmineDmsf::Patches::NotifiableRuPatch \ No newline at end of file diff --git a/lib/redmine_dmsf/plugin.rb b/lib/redmine_dmsf/plugin.rb new file mode 100644 index 00000000..1b7dd974 --- /dev/null +++ b/lib/redmine_dmsf/plugin.rb @@ -0,0 +1,33 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011 Vít Jonáš +# Copyright © 2011-22 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module RedmineDmsf + module Plugin + + # Checking physical presence of the plugin as Redmine::Plugin.installed? may return false due to alphabetical + # registering of available plugins. + def self.present?(id) + Dir.exist? File.join(Rails.root, 'plugins', id.to_s) + 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 new file mode 100644 index 00000000..92484476 --- /dev/null +++ b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb @@ -0,0 +1,34 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../../test_helper', __FILE__) + +class DmsfPluginTest < RedmineDmsf::Test::HelperTest + + def test_present_yes + assert RedmineDmsf::Plugin.present?(:redmine_dmsf) + end + + def test_present_no + assert !RedmineDmsf::Plugin.present?(:redmine_dmsfx) + end + +end