From a2eeac38979af50564168bf8e63f108bff27f65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Thu, 27 Jun 2024 09:59:16 +0200 Subject: [PATCH] Easy tests --- Gemfile | 12 +++-- after_init.rb | 2 +- lib/redmine_dmsf.rb | 37 +++++++------- .../patches/application_helper_patch.rb | 42 ---------------- lib/redmine_dmsf/patches/role_patch.rb | 2 +- .../patches/search_controller_patch.rb | 44 ----------------- .../xapian_easy_search_helper_patch.rb | 42 ---------------- lib/xapian_easy_search/base_mapper.rb | 30 ------------ lib/xapian_easy_search/dmsf_file_mapper.rb | 49 ------------------- lib/xapian_easy_search/dmsf_folder_mapper.rb | 40 --------------- 10 files changed, 27 insertions(+), 273 deletions(-) delete mode 100644 lib/redmine_dmsf/patches/application_helper_patch.rb delete mode 100644 lib/redmine_dmsf/patches/search_controller_patch.rb delete mode 100644 lib/redmine_dmsf/patches/xapian_easy_search_helper_patch.rb delete mode 100644 lib/xapian_easy_search/base_mapper.rb delete mode 100644 lib/xapian_easy_search/dmsf_file_mapper.rb delete mode 100644 lib/xapian_easy_search/dmsf_folder_mapper.rb diff --git a/Gemfile b/Gemfile index b0ee5bb0..813755cf 100644 --- a/Gemfile +++ b/Gemfile @@ -19,17 +19,19 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. source 'https://rubygems.org' do - gem 'active_record_union' gem 'ox' # Dav4Rack gem 'rake' unless Dir.exist?(File.expand_path('../../redmine_dashboard', __FILE__)) gem 'uuidtools' - group :xapian do - gem 'xapian-ruby' - end gem 'zip-zip' unless Dir.exist?(File.expand_path('../../vault', __FILE__)) # Redmine extensions - gem 'simple_enum' unless Dir.exist?(File.expand_path('../../easyproject', __FILE__)) + unless Dir.exist?(File.expand_path('../../easyproject', __FILE__)) + gem 'active_record_union' + gem 'simple_enum' + group :xapian do + gem 'xapian-ruby' + end + end unless %w[easyproject easy_gantt custom_tables] .any? { |plugin| Dir.exist?(File.expand_path("../../#{plugin}", __FILE__)) } group :test do diff --git a/after_init.rb b/after_init.rb index 659c169b..84cc2d19 100644 --- a/after_init.rb +++ b/after_init.rb @@ -109,7 +109,7 @@ def dmsf_init end if Redmine::Plugin.installed?('easy_extensions') - ActiveSupport.on_load(:easyproject, yield: true) do + Rails.application.config.after_initialize do dmsf_init # Register panels for My page diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index d8eac720..ea387f13 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -39,7 +39,6 @@ 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" -require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/search_controller_patch" require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/custom_field_patch" # A workaround for obsolete 'alias_method' usage in RedmineUp's plugins @@ -53,12 +52,6 @@ require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/easy_crm_case_patch" require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/attachable_patch" require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb" - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/xapian_easy_search_helper_patch.rb" - require "#{File.dirname(__FILE__)}/redmine_dmsf/patches/application_helper_patch.rb" - - # Mappers - require "#{File.dirname(__FILE__)}/xapian_easy_search/dmsf_file_mapper.rb" - require "#{File.dirname(__FILE__)}/xapian_easy_search/dmsf_folder_mapper.rb" end # Load up classes that make up our WebDAV solution ontop of Dav4rack @@ -78,18 +71,24 @@ require "#{File.dirname(__FILE__)}/redmine_dmsf/errors/dmsf_zip_max_files_error" # Hooks -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/account_controller_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/search_controller_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/issues_controller_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/view_projects_form_hook" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/base_view_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/custom_field_view_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/issue_view_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/my_account_view_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/search_view_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/issues_helper_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/search_helper_hooks" -require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/project_helper_hooks" +def require_hooks + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/controllers/issues_controller_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/view_projects_form_hook" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/base_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/custom_field_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/issue_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/my_account_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/search_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/issues_helper_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/search_helper_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/project_helper_hooks" +end + +if defined?(EasyExtensions) + Rails.application.config.to_prepare { require_hooks } +else + require_hooks +end # Macros require "#{File.dirname(__FILE__)}/redmine_dmsf/macros" diff --git a/lib/redmine_dmsf/patches/application_helper_patch.rb b/lib/redmine_dmsf/patches/application_helper_patch.rb deleted file mode 100644 index d7129d51..00000000 --- a/lib/redmine_dmsf/patches/application_helper_patch.rb +++ /dev/null @@ -1,42 +0,0 @@ -# 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. - -module RedmineDmsf - module Patches - # ApplicationHelper patch - module ApplicationHelperPatch - ################################################################################################################## - # Overridden methods - - def xapian_link_to_entity(entity, html_options = {}) - if entity.is_a?(DmsfFolder) - link_to h(entity.to_s), dmsf_folder_path(id: entity.project_id, folder_id: entity), class: 'icon icon-folder' - elsif entity.is_a?(DmsfFile) - link_to h(entity.to_s), dmsf_file_path(id: entity), class: 'icon icon-file' - else - super - end - end - end - end -end - -# Apply the patch -ApplicationHelper.prepend RedmineDmsf::Patches::ApplicationHelperPatch if Redmine::Plugin.installed?('easy_extensions') diff --git a/lib/redmine_dmsf/patches/role_patch.rb b/lib/redmine_dmsf/patches/role_patch.rb index 4cd7a094..264e22d6 100644 --- a/lib/redmine_dmsf/patches/role_patch.rb +++ b/lib/redmine_dmsf/patches/role_patch.rb @@ -34,7 +34,7 @@ def self.included(base) def remove_dmsf_references return unless id - substitute = User.anonymous + substitute = Role.anonymous DmsfFolderPermission.where(object_id: id, object_type: 'Role').update_all object_id: substitute.id end end diff --git a/lib/redmine_dmsf/patches/search_controller_patch.rb b/lib/redmine_dmsf/patches/search_controller_patch.rb deleted file mode 100644 index 00d5878c..00000000 --- a/lib/redmine_dmsf/patches/search_controller_patch.rb +++ /dev/null @@ -1,44 +0,0 @@ -# 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. -# -module RedmineDmsf - module Patches - # Search controller patch - module SearchControllerPatch - ################################################################################################################## - # New methods - - private - - def query_params - p = super - p[:dmsf_files] = params[:dmsf_files].present? - p[:dmsf_folders] = params[:dmsf_folders].present? - p - end - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - EasyPatchManager.register_controller_patch 'SearchController', 'RedmineDmsf::Patches::SearchControllerPatch', - prepend: true -end diff --git a/lib/redmine_dmsf/patches/xapian_easy_search_helper_patch.rb b/lib/redmine_dmsf/patches/xapian_easy_search_helper_patch.rb deleted file mode 100644 index dc4fb6b4..00000000 --- a/lib/redmine_dmsf/patches/xapian_easy_search_helper_patch.rb +++ /dev/null @@ -1,42 +0,0 @@ -# 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. - -module RedmineDmsf - module Patches - # XapianEasySearchHelper patch - module XapianEasySearchHelperPatch - ################################################################################################################## - # Overridden methods - - def xapian_entity_path(xapian_doc) - if xapian_doc.values[:source_type] == 'dmsf_folder' - dmsf_folder_path id: xapian_doc.values[:project_id], folder_id: xapian_doc.values[:source_id] - else - super - end - end - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?('easy_extensions') - XapianEasySearchHelper.prepend RedmineDmsf::Patches::XapianEasySearchHelperPatch -end diff --git a/lib/xapian_easy_search/base_mapper.rb b/lib/xapian_easy_search/base_mapper.rb deleted file mode 100644 index d54623dc..00000000 --- a/lib/xapian_easy_search/base_mapper.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# Redmine plugin for Document Management System "Features" -# -# Vít Jonáš , Daniel Munn , 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. - -if defined?(EasyExtensions) - require 'xapian_easy_search/base_mapper' -else - module XapianEasySearch - # Foo class - class BaseMapper - def foo; end - end - end -end diff --git a/lib/xapian_easy_search/dmsf_file_mapper.rb b/lib/xapian_easy_search/dmsf_file_mapper.rb deleted file mode 100644 index b980fb85..00000000 --- a/lib/xapian_easy_search/dmsf_file_mapper.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -# Redmine plugin for Document Management System "Features" -# -# Vít Jonáš , Daniel Munn , 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('xapian_easy_search/base_mapper') if defined?(EasyExtensions) - -module XapianEasySearch - # DmsfFile mapper - class DmsfFileMapper < XapianEasySearch::BaseMapper - class << self - def default_index_options - super.merge( - title: :name, - updated_at: ->(dmsf_file) { dmsf_file&.last_revision&.updated_at }, - content: ->(dmsf_file) { dmsf_file&.content } - ) - end - - def extend_query_filter - proc do |query| - # TODO: we filter the results with all files visible for the user. It's the worst way how to filter them. - files = DmsfFile.visible - .joins('JOIN dmsf_file_revisions ON dmsf_file_revisions.dmsf_file_id = dmsf_files.id') - .joins(:project) - .where(Project.allowed_to_condition(User.current, :view_dmsf_files)).to_a - files.delete_if { |f| !DmsfFolder.permissions?(f.dmsf_folder) } - ids = files.map(&:id) - Xapian::Query.new Xapian::Query::OP_AND, query, boolean_filter_query(:source_id, ids) - end - end - end - end -end diff --git a/lib/xapian_easy_search/dmsf_folder_mapper.rb b/lib/xapian_easy_search/dmsf_folder_mapper.rb deleted file mode 100644 index 47853353..00000000 --- a/lib/xapian_easy_search/dmsf_folder_mapper.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -# Redmine plugin for Document Management System "Features" -# -# Vít Jonáš , Daniel Munn , 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('xapian_easy_search/base_mapper') if defined?(EasyExtensions) - -module XapianEasySearch - # DmsfFolder mapper - class DmsfFolderMapper < XapianEasySearch::BaseMapper - class << self - def default_index_options - super.merge title: :title, updated_at: :updated_at, content: :description - end - - def extend_query_filter - proc do |query| - # TODO: we filter the results with all folders visible for the user. It's the worst way how to filter them. - ids = DmsfFolder.visible.ids - Xapian::Query.new Xapian::Query::OP_AND, query, boolean_filter_query(:source_id, ids) - end - end - end - end -end