From c502b834c47274b85427cd3b0849e5b38d760288 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Pi=C4=8Dman?=
Date: Fri, 2 Jun 2023 16:56:00 +0200
Subject: [PATCH] An option to remove the original Documents module
---
CHANGELOG.md | 2 +
after_init.rb | 4 --
app/views/settings/_dmsf_settings.html.erb | 8 +++
config/locales/cs.yml | 2 +
config/locales/de.yml | 2 +
config/locales/en.yml | 2 +
config/locales/es.yml | 2 +
config/locales/fa.yml | 2 +
config/locales/fr.yml | 2 +
config/locales/hu.yml | 2 +
config/locales/it.yml | 2 +
config/locales/ja.yml | 2 +
config/locales/ko.yml | 2 +
config/locales/nl.yml | 2 +
config/locales/pl.yml | 2 +
config/locales/pt-BR.yml | 2 +
config/locales/sl.yml | 2 +
config/locales/zh-TW.yml | 2 +
config/locales/zh.yml | 2 +
init.rb | 3 +-
lib/redmine_dmsf.rb | 2 +
.../patches/access_control_patch.rb | 56 +++++++++++++++++++
lib/redmine_dmsf/patches/search_patch.rb | 56 +++++++++++++++++++
test/unit/lib/acccess_control_patch_test.rb | 31 ++++++++++
test/unit/{ => lib}/attachable_patch_test.rb | 2 +-
test/unit/lib/search_patch_test.rb | 31 ++++++++++
26 files changed, 221 insertions(+), 6 deletions(-)
create mode 100644 lib/redmine_dmsf/patches/access_control_patch.rb
create mode 100644 lib/redmine_dmsf/patches/search_patch.rb
create mode 100644 test/unit/lib/acccess_control_patch_test.rb
rename test/unit/{ => lib}/attachable_patch_test.rb (95%)
create mode 100644 test/unit/lib/search_patch_test.rb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d7b996c..601dab51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ Changelog for Redmine DMSF
3.0.13 ????-??-??
------------------
+ An option to disable the original module Documents in the plugin's settings
+
3.0.12 2023-03-15
------------------
diff --git a/after_init.rb b/after_init.rb
index 60cf99b7..df8e5a1b 100644
--- a/after_init.rb
+++ b/after_init.rb
@@ -144,10 +144,6 @@ Rails.application.configure do
Redmine::Activity.register :dmsf_file_revision_accesses, default: false
Redmine::Activity.register :dmsf_file_revisions
- # Uncomment to remove the original Documents from searching and project's modules (replaced with DMSF)
- # Redmine::Search.available_search_types.delete('documents')
- # Redmine::AccessControl.available_project_modules.delete(:documents)
-
if Redmine::Plugin.installed?('easy_extensions')
require "#{File.dirname(__FILE__)}/lib/redmine_dmsf/webdav/custom_middleware"
config.middleware.insert_before ActionDispatch::Cookies, RedmineDmsf::Webdav::CustomMiddleware
diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb
index b3599f72..130495f0 100644
--- a/app/views/settings/_dmsf_settings.html.erb
+++ b/app/views/settings/_dmsf_settings.html.erb
@@ -176,6 +176,14 @@
+
+ <%= content_tag :label, l(:label_remove_original_documents_module) %>
+ <%= check_box_tag 'settings[remove_original_documents_module]', false, @settings['remove_original_documents_module'] %>
+
+ <%= l(:label_default) %>: <%= l(:general_text_No) %>
+
+
+
<%= l(:label_dmsf_columns) %>
diff --git a/config/locales/cs.yml b/config/locales/cs.yml
index 88e2a584..95e1c034 100644
--- a/config/locales/cs.yml
+++ b/config/locales/cs.yml
@@ -468,6 +468,8 @@ cs:
field_default_dmsf_query: Výchozí dotaz DMS
field_receive_download_notification: Dostávat notifikace o stažení
+ label_remove_original_documents_module: Odstranit původní modul Dokumenty
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 6c4b4627..87f07440 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -464,6 +464,8 @@ de:
field_default_dmsf_query: Standardabfrage DMS
field_receive_download_notification: Bekomen Benachrichtigen über Herunterladen
+ label_remove_original_documents_module: Entfernen originelles Modul Dokumente
+
easy_pages:
modules:
dmsf_locked_documents: Von mir gesperrte Dokumente
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 82675fee..cd462e46 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -468,6 +468,8 @@ en:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 9487e7b1..178c4319 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -468,6 +468,8 @@ es:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/fa.yml b/config/locales/fa.yml
index 9c7b3ba6..fc82acb7 100644
--- a/config/locales/fa.yml
+++ b/config/locales/fa.yml
@@ -447,6 +447,8 @@ fa:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: اسناد قفل شدهی من
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index c86e557f..00f8c177 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -468,6 +468,8 @@ fr:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/hu.yml b/config/locales/hu.yml
index d2db82e9..9398aee6 100644
--- a/config/locales/hu.yml
+++ b/config/locales/hu.yml
@@ -467,6 +467,8 @@ hu:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 1bf3b8d1..f3de3ecc 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -468,6 +468,8 @@ it: # Italian strings thx 2 Matteo Arceci!
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index 98c3edd8..9521b2d5 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -469,6 +469,8 @@ ja:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: 自分がロック中の文書
diff --git a/config/locales/ko.yml b/config/locales/ko.yml
index 244e0b1d..264d0f59 100644
--- a/config/locales/ko.yml
+++ b/config/locales/ko.yml
@@ -468,6 +468,8 @@ ko:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: 내 잠긴 파일
diff --git a/config/locales/nl.yml b/config/locales/nl.yml
index c39cb201..18e873c4 100644
--- a/config/locales/nl.yml
+++ b/config/locales/nl.yml
@@ -468,6 +468,8 @@ nl:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/pl.yml b/config/locales/pl.yml
index 4484d620..d50419bc 100644
--- a/config/locales/pl.yml
+++ b/config/locales/pl.yml
@@ -468,6 +468,8 @@ pl:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml
index 12879f89..943b19b1 100644
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -468,6 +468,8 @@ pt-BR:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/sl.yml b/config/locales/sl.yml
index 19cc1864..70e8cb75 100644
--- a/config/locales/sl.yml
+++ b/config/locales/sl.yml
@@ -468,6 +468,8 @@ sl:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml
index bf2dc901..744593fc 100644
--- a/config/locales/zh-TW.yml
+++ b/config/locales/zh-TW.yml
@@ -467,6 +467,8 @@ zh-TW:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 22300611..00f0c147 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -468,6 +468,8 @@ zh:
field_default_dmsf_query: Default DMS query
field_receive_download_notification: Receive download notifications
+ label_remove_original_documents_module: Remove the original Documents module
+
easy_pages:
modules:
dmsf_locked_documents: My locked documents
diff --git a/init.rb b/init.rb
index 7526c19a..07ea14f2 100644
--- a/init.rb
+++ b/init.rb
@@ -63,7 +63,8 @@ Redmine::Plugin.register :redmine_dmsf do
'office_bin' => 'libreoffice',
'dmsf_global_menu_disabled' => nil,
'dmsf_default_query' => nil,
- 'empty_minor_version_by_default' => nil
+ 'empty_minor_version_by_default' => nil,
+ 'remove_original_documents_module' => nil
}
end
diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb
index 0783bf44..b6ede9ec 100644
--- a/lib/redmine_dmsf.rb
+++ b/lib/redmine_dmsf.rb
@@ -39,6 +39,8 @@ 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"
require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/pdf_patch"
+require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/access_control_patch"
+require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/search_patch"
# A workaround for obsolete 'alias_method' usage in RedmineUp's plugins
if RedmineDmsf::Plugin.an_obsolete_plugin_present?
diff --git a/lib/redmine_dmsf/patches/access_control_patch.rb b/lib/redmine_dmsf/patches/access_control_patch.rb
new file mode 100644
index 00000000..cab046a3
--- /dev/null
+++ b/lib/redmine_dmsf/patches/access_control_patch.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright © 2011-23 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 Patches
+ # AccessControll patch
+ module AccessControlPatch
+ ##################################################################################################################
+ # Overriden methods
+ def self.prepended(base)
+ class << base
+ prepend ClassMethods
+ end
+ end
+
+ # Class methods
+ module ClassMethods
+ def available_project_modules
+ # Removes the original Documents from project's modules (replaced with DMSF)
+ if Setting.plugin_redmine_dmsf['remove_original_documents_module']
+ super.reject { |m| m == :documents }
+ else
+ super
+ end
+ end
+ end
+ end
+ end
+end
+
+# Apply the patch
+if Redmine::Plugin.installed?('easy_extensions')
+ RedmineExtensions::PatchManager.register_patch_to_be_first 'Redmine::Acts::Attachable::InstanceMethods',
+ 'RedmineDmsf::Patches::AccessControlPatch',
+ prepend: true,
+ first: true
+else
+ Redmine::AccessControl.prepend RedmineDmsf::Patches::AccessControlPatch
+end
diff --git a/lib/redmine_dmsf/patches/search_patch.rb b/lib/redmine_dmsf/patches/search_patch.rb
new file mode 100644
index 00000000..5d58e91c
--- /dev/null
+++ b/lib/redmine_dmsf/patches/search_patch.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright © 2011-23 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 Patches
+ # Search patch
+ module SearchPatch
+ ##################################################################################################################
+ # Overridden methods
+ def self.prepended(base)
+ class << base
+ prepend ClassMethods
+ end
+ end
+
+ # Class methods
+ module ClassMethods
+ def available_search_types
+ # Removes the original Documents from searching (replaced with DMSF)
+ if Setting.plugin_redmine_dmsf['remove_original_documents_module']
+ super.reject { |t| t == 'documents' }
+ else
+ super
+ end
+ end
+ end
+ end
+ end
+end
+
+# Apply the patch
+if Redmine::Plugin.installed?('easy_extensions')
+ RedmineExtensions::PatchManager.register_patch_to_be_first 'Redmine::Acts::Attachable::InstanceMethods',
+ 'RedmineDmsf::Patches::SearchPatch',
+ prepend: true,
+ first: true
+else
+ Redmine::Search.prepend RedmineDmsf::Patches::SearchPatch
+end
diff --git a/test/unit/lib/acccess_control_patch_test.rb b/test/unit/lib/acccess_control_patch_test.rb
new file mode 100644
index 00000000..01303ed1
--- /dev/null
+++ b/test/unit/lib/acccess_control_patch_test.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright © 2011-23 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__)
+
+# AccessControl patch tests
+class AccessControlPatchTest < RedmineDmsf::Test::UnitTest
+ def test_available_project_modules
+ Setting.plugin_redmine_dmsf['remove_original_documents_module'] = nil
+ assert Redmine::AccessControl.available_project_modules.include?(:documents)
+ Setting.plugin_redmine_dmsf['remove_original_documents_module'] = '1'
+ assert_not Redmine::AccessControl.available_project_modules.include?(:documents)
+ end
+end
diff --git a/test/unit/attachable_patch_test.rb b/test/unit/lib/attachable_patch_test.rb
similarity index 95%
rename from test/unit/attachable_patch_test.rb
rename to test/unit/lib/attachable_patch_test.rb
index 460994de..d21270be 100644
--- a/test/unit/attachable_patch_test.rb
+++ b/test/unit/lib/attachable_patch_test.rb
@@ -18,7 +18,7 @@
# 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__)
+require File.expand_path('../../../test_helper', __FILE__)
# Attachable tests
class AttachablePatchTest < RedmineDmsf::Test::UnitTest
diff --git a/test/unit/lib/search_patch_test.rb b/test/unit/lib/search_patch_test.rb
new file mode 100644
index 00000000..43731bcc
--- /dev/null
+++ b/test/unit/lib/search_patch_test.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright © 2011-23 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__)
+
+# Search patch tests
+class SearchPatchTest < RedmineDmsf::Test::UnitTest
+ def test_available_search_types
+ Setting.plugin_redmine_dmsf['remove_original_documents_module'] = nil
+ assert Redmine::Search.available_search_types.include?('documents')
+ Setting.plugin_redmine_dmsf['remove_original_documents_module'] = '1'
+ assert_not Redmine::Search.available_search_types.include?('documents')
+ end
+end