From ecf5ba498e34547c3d030cbdd5aa8996c15962a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Pi=C4=8Dman?=
Date: Thu, 6 Feb 2025 12:44:09 +0100
Subject: [PATCH] #1589 Puma compatibility
---
app/models/dmsf_file.rb | 2 +-
app/views/settings/_dmsf_settings.html.erb | 10 +----
lib/redmine_dmsf.rb | 1 +
lib/redmine_dmsf/plugin.rb | 8 ++--
patches/puma_patch.rb | 45 +++++++++++++++++++
.../unit/lib/redmine_dmsf/dmsf_plugin_test.rb | 5 +++
6 files changed, 57 insertions(+), 14 deletions(-)
create mode 100644 patches/puma_patch.rb
diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb
index fc0dbea4..b433a98b 100644
--- a/app/models/dmsf_file.rb
+++ b/app/models/dmsf_file.rb
@@ -362,7 +362,7 @@ class DmsfFile < ApplicationRecord
results = scope.where(find_options).uniq.to_a
results.delete_if { |x| !DmsfFolder.permissions?(x.dmsf_folder) }
- if !options[:titles_only] && RedmineDmsf::Plugin.xapian_available?
+ if !options[:titles_only] && RedmineDmsf::Plugin.lib_available?('xapian')
database = nil
begin
lang = RedmineDmsf.dmsf_stemming_lang
diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb
index 3f1a9343..5c93b670 100644
--- a/app/views/settings/_dmsf_settings.html.erb
+++ b/app/views/settings/_dmsf_settings.html.erb
@@ -355,15 +355,7 @@
<% else %>
- <% begin %>
- <% require 'xapian' %>
- <% xapian_disabled = false %>
- <% rescue LoadError => e %>
- <%= l(:warning_xapian_not_available) %>
- <% Rails.logger.warn e.message %>
- <% xapian_disabled = true %>
- <% end %>
- <% if RedmineDmsf::Plugin.xapian_available? %>
+ <% if RedmineDmsf::Plugin.lib_available?('xapian') %>
<%= content_tag :label, l(:label_index_database) %>
<%= text_field_tag 'settings[dmsf_index_database]', RedmineDmsf.dmsf_index_database, size: 50 %>
diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb
index 4539dd40..3e4d49b5 100644
--- a/lib/redmine_dmsf.rb
+++ b/lib/redmine_dmsf.rb
@@ -253,6 +253,7 @@ unless defined?(EasyPatchManager)
require "#{File.dirname(__FILE__)}/../patches/access_control_patch"
require "#{File.dirname(__FILE__)}/../patches/search_patch"
require "#{File.dirname(__FILE__)}/../patches/custom_field_patch"
+ require "#{File.dirname(__FILE__)}/../patches/puma_patch"
# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins
if RedmineDmsf::Plugin.an_obsolete_plugin_present?
require "#{File.dirname(__FILE__)}/../patches/notifiable_ru_patch"
diff --git a/lib/redmine_dmsf/plugin.rb b/lib/redmine_dmsf/plugin.rb
index 15775386..e4dcbbdc 100644
--- a/lib/redmine_dmsf/plugin.rb
+++ b/lib/redmine_dmsf/plugin.rb
@@ -39,12 +39,12 @@ module RedmineDmsf
false
end
- # Return true if Xapian binding is installed (gem ruby_xapian)
- def self.xapian_available?
- require 'xapian'
+ # Return true if the given gem is installed
+ def self.lib_available?(path)
+ require path
true
rescue LoadError => e
- Rails.logger.warn e.message
+ Rails.logger.info e.message
false
end
end
diff --git a/patches/puma_patch.rb b/patches/puma_patch.rb
new file mode 100644
index 00000000..37eaeecb
--- /dev/null
+++ b/patches/puma_patch.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+# Redmine plugin for Document Management System "Features"
+#
+# 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.
+#
+# Redmine's PDF export patch to view DMS images
+
+module RedmineDmsf
+ module Patches
+ # Puma
+ module PumaPatch
+ ##################################################################################################################
+ # Overridden methods
+ def self.included(base)
+ base.class_eval do
+ # WebDAV methods
+ methods = Puma::Const::SUPPORTED_HTTP_METHODS |
+ %w[OPTIONS HEAD GET PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK]
+ remove_const :SUPPORTED_HTTP_METHODS
+ const_set :SUPPORTED_HTTP_METHODS, methods.freeze
+ end
+ end
+ end
+ end
+end
+
+# Apply the patch
+if !defined?(EasyPatchManager) && RedmineDmsf::Plugin.lib_available?('puma/const')
+ Puma::Const.include RedmineDmsf::Patches::PumaPatch
+end
diff --git a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb
index c34ac8c5..a3ded3e9 100644
--- a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb
+++ b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb
@@ -42,4 +42,9 @@ class DmsfPluginTest < RedmineDmsf::Test::HelperTest
assert RedmineDmsf::Plugin.an_obsolete_plugin_present?
FileUtils.rm_rf path
end
+
+ def test_lib_available?
+ assert RedmineDmsf::Plugin.lib_available?('zip')
+ assert_not RedmineDmsf::Plugin.lib_available?('not_existing_gem')
+ end
end