From 48da1908d763515d9dd6c5ac6b2ea8a0c21f1f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 25 Nov 2024 17:51:01 +0100 Subject: [PATCH] Plugin settings 'Display notified recipients' does not apply! #1565 --- after_init.rb | 2 +- .../dmsf_context_menus_controller.rb | 2 +- app/controllers/dmsf_controller.rb | 15 +- app/controllers/dmsf_files_controller.rb | 11 +- app/controllers/dmsf_state_controller.rb | 4 +- app/controllers/dmsf_workflows_controller.rb | 18 +- app/helpers/dmsf_upload_helper.rb | 4 +- app/models/dmsf_file.rb | 29 +-- app/models/dmsf_file_revision.rb | 2 +- app/models/dmsf_folder.rb | 9 +- app/models/dmsf_query.rb | 2 +- app/models/dmsf_upload.rb | 4 +- app/models/dmsf_workflow.rb | 4 +- app/views/dmsf/_main.html.erb | 4 +- app/views/dmsf/email_entries.html.erb | 2 +- app/views/dmsf_context_menus/_file.html.erb | 2 +- app/views/dmsf_public_urls/_new.html.erb | 2 +- app/views/dmsf_state/_user_pref.html.erb | 2 +- .../redmine_dmsf/_view_my_account.html.erb | 2 +- extra/xapian_indexer.rb | 2 +- init.rb | 2 +- lib/redmine_dmsf.rb | 174 ++++++++++++++++++ .../errors/dmsf_email_max_file_size_error.rb | 2 +- .../errors/dmsf_zip_max_files_error.rb | 2 +- .../controllers/account_controller_hooks.rb | 2 +- .../hooks/views/issue_view_hooks.rb | 4 +- .../patches/access_control_patch.rb | 2 +- lib/redmine_dmsf/patches/search_patch.rb | 2 +- lib/redmine_dmsf/webdav/base_resource.rb | 4 +- lib/redmine_dmsf/webdav/dmsf_controller.rb | 4 +- lib/redmine_dmsf/webdav/dmsf_resource.rb | 14 +- lib/redmine_dmsf/webdav/project_resource.rb | 4 +- lib/redmine_dmsf/webdav/resource_proxy.rb | 2 +- test/functional/dmsf_controller_test.rb | 4 +- 34 files changed, 247 insertions(+), 97 deletions(-) diff --git a/after_init.rb b/after_init.rb index 410a5042..5535ed1a 100644 --- a/after_init.rb +++ b/after_init.rb @@ -55,7 +55,7 @@ def dmsf_init if: proc { User.current.allowed_to?(:view_dmsf_folders, nil, global: true) && ActiveRecord::Base.connection.data_source_exists?('settings') && - Setting.plugin_redmine_dmsf['dmsf_global_menu_disabled'].blank? + !RedmineDmsf.dmsf_global_menu_disabled? } end diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb index 49c8e356..8c2be6e3 100644 --- a/app/controllers/dmsf_context_menus_controller.rb +++ b/app/controllers/dmsf_context_menus_controller.rb @@ -37,7 +37,7 @@ class DmsfContextMenusController < ApplicationController @unlockable = @allowed && @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) @email_allowed = User.current.allowed_to?(:email_documents, @project) - @preview = RedmineDmsf::Preview.office_available? && Setting.plugin_redmine_dmsf['office_bin'].blank? + @preview = RedmineDmsf.office_bin.present? && RedmineDmsf::Preview.office_available? elsif @dmsf_folder @locked = @dmsf_folder.locked? @project = @dmsf_folder.project diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 550c7756..9dabb3a3 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -83,7 +83,7 @@ class DmsfController < ApplicationController @notifications = Setting.notified_events.include?('dmsf_legacy_notifications') @query.dmsf_folder_id = @folder ? @folder.id : nil @query.deleted = false - @query.sub_projects |= Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'].present? + @query.sub_projects |= RedmineDmsf.dmsf_projects_as_subfolders? if @folder&.deleted? || (params[:folder_title].present? && !@folder) render_404 return @@ -501,7 +501,7 @@ class DmsfController < ApplicationController zip_entries(zip, selected_folders, selected_files) zipped_content = zip.finish - max_filesize = Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_f + max_filesize = RedmineDmsf.dmsf_max_email_filesize if max_filesize.positive? && File.size(zipped_content) > max_filesize * 1_048_576 raise RedmineDmsf::Errors::DmsfEmailMaxFileSizeError end @@ -527,9 +527,8 @@ class DmsfController < ApplicationController folders: selected_folders, files: selected_files, subject: "#{@project.name} #{l(:label_dmsf_file_plural).downcase}", - from: Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].presence || - "#{User.current.name} <#{User.current.mail}>", - reply_to: Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] + from: RedmineDmsf.dmsf_documents_email_from, + reply_to: RedmineDmsf.dmsf_documents_email_reply_to } @back_url = params[:back_url] render action: 'email_entries' @@ -583,7 +582,7 @@ class DmsfController < ApplicationController zip.add_dmsf_file file, member, file.dmsf_folder&.dmsf_path_str end - max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i + max_files = RedmineDmsf.dmsf_max_file_download raise RedmineDmsf::Errors::DmsfZipMaxFilesError if max_files.positive? && zip.dmsf_files.length > max_files zip @@ -647,8 +646,8 @@ class DmsfController < ApplicationController unless deleted_files.empty? begin recipients = DmsfMailer.deliver_files_deleted(@project, deleted_files) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? - max_receivers = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.any? + max_receivers = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect { |user, _| user.name }.first(max_receivers).join(', ') if to.present? to << (recipients.count > max_receivers ? ',...' : '.') diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 3918f79f..6651b426 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -77,8 +77,7 @@ class DmsfFilesController < ApplicationController # PDF preview pdf_preview = (params[:disposition] != 'attachment') && params[:filename].blank? && @file.pdf_preview filename = filename_for_content_disposition(@revision.formatted_name(member)) - if !api_request? && pdf_preview.present? && (Setting.plugin_redmine_dmsf['office_bin'].present? || - params[:preview].present?) + if !api_request? && pdf_preview.present? && (RedmineDmsf.office_bin.present? || params[:preview].present?) basename = File.basename(filename, '.*') send_file pdf_preview, filename: "#{basename}.pdf", type: 'application/pdf', disposition: 'inline' # Text preview @@ -181,8 +180,8 @@ class DmsfFilesController < ApplicationController call_hook :dmsf_helper_upload_after_commit, { file: @file } begin recipients = DmsfMailer.deliver_files_updated(@project, [@file]) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? - max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.any? + max_notifications = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect { |user, _| user.name }.first(max_notifications).join(', ') if to.present? to << (recipients.count > max_notifications ? ',...' : '.') @@ -224,8 +223,8 @@ class DmsfFilesController < ApplicationController else begin recipients = DmsfMailer.deliver_files_deleted(@project, [@file]) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? - max_notification = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.any? + max_notification = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect { |user, _| user.name }.first(max_notification).join(', ') if to.present? to << (recipients.count > max_notification ? ',...' : '.') diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index 51f239ec..ca043388 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -39,9 +39,7 @@ class DmsfStateController < ApplicationController else flash[:warning] = l(:user_is_not_project_member) end - if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] - @project.update dmsf_act_as_attachable: params[:act_as_attachable] - end + @project.update(dmsf_act_as_attachable: params[:act_as_attachable]) if RedmineDmsf.dmsf_act_as_attachable? @project.update default_dmsf_query_id: params[:default_dmsf_query] redirect_to settings_project_path(@project, tab: 'dmsf') end diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb index c4aaf7a3..a058b954 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -80,9 +80,7 @@ class DmsfWorkflowsController < ApplicationController if @dmsf_workflow.try_finish revision, action, (params[:step_action].to_i / 10) if revision.dmsf_file begin - unless Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'] - revision.dmsf_file.unlock!(force_file_unlock_allowed: true) - end + revision.dmsf_file.unlock!(force_file_unlock_allowed: true) unless RedmineDmsf.dmsf_keep_documents_locked? rescue RedmineDmsf::Errors::DmsfLockError => e flash[:info] = e.message end @@ -99,8 +97,8 @@ class DmsfWorkflowsController < ApplicationController :text_email_finished_approved, :text_email_to_see_history ) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.present? - max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.present? + max_notifications = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect(&:name).first(max_notifications).join(', ') if to.present? to << (recipients.count > max_notifications ? ',...' : '.') @@ -122,8 +120,8 @@ class DmsfWorkflowsController < ApplicationController :text_email_to_see_history, action.note ) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.present? - max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.present? + max_notifications = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect(&:name).first(max_notifications).join(', ') if to.present? to << (recipients.count > max_notifications ? ',...' : '.') @@ -146,7 +144,7 @@ class DmsfWorkflowsController < ApplicationController action.note, action.dmsf_workflow_step_assignment.dmsf_workflow_step ) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + if RedmineDmsf.dmsf_display_notified_recipients? flash[:warning] = l(:warning_email_notifications, to: delegate.name) end end @@ -186,13 +184,13 @@ class DmsfWorkflowsController < ApplicationController :text_email_to_see_status ) end - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + if RedmineDmsf.dmsf_display_notified_recipients? recipients = assignments.collect(&:user) recipients << to if to recipients.uniq! recipients &= DmsfMailer.get_notify_users(@project, revision.dmsf_file, force_notification: true) unless recipients.empty? - max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + max_notifications = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect(&:name).first(max_notifications).join(', ') if to.present? to << (recipients.count > max_notifications ? ',...' : '.') diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index 0c0a472d..26671e24 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -140,8 +140,8 @@ module DmsfUploadHelper # Notifications begin recipients = DmsfMailer.deliver_files_updated(project, files) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? - max_recipients = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + if RedmineDmsf.dmsf_display_notified_recipients? && recipients.any? + max_recipients = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect { |user, _| user.name }.first(max_recipients).join(', ') if to.present? to << (recipients.count > max_recipients ? ',...' : '.') diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 7e4967a8..8c25534b 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -101,13 +101,10 @@ class DmsfFile < ApplicationRecord end def self.storage_path - path = Setting.plugin_redmine_dmsf['dmsf_storage_directory'].try(:strip) - if path.blank? - path = Pathname.new('files').join('dmsf').to_s - else - pn = Pathname.new(path) - return pn if pn.absolute? - end + path = RedmineDmsf.dmsf_storage_directory + pn = Pathname.new(path) + return pn if pn.absolute? + Rails.root.join path end @@ -120,7 +117,7 @@ class DmsfFile < ApplicationRecord end def approval_allowed_zero_minor - Setting.plugin_redmine_dmsf['only_approval_zero_minor_version'] ? last_revision.minor_version&.zero? : true + RedmineDmsf.only_approval_zero_minor_version? ? last_revision.minor_version&.zero? : true end def last_revision @@ -369,16 +366,8 @@ class DmsfFile < ApplicationRecord if !options[:titles_only] && RedmineDmsf::Plugin.xapian_available? database = nil begin - unless Setting.plugin_redmine_dmsf['dmsf_stemming_lang'] - raise StandardError, "'dmsf_stemming_lang' option is not set" - end - - lang = Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].strip - unless Setting.plugin_redmine_dmsf['dmsf_index_database'] - raise StandardError, "'dmsf_index_database' option is not set" - end - - databasepath = File.join(Setting.plugin_redmine_dmsf['dmsf_index_database'].strip, lang) + lang = RedmineDmsf.dmsf_stemming_lang.strip + databasepath = File.join(RedmineDmsf.dmsf_index_database.strip, lang) database = Xapian::Database.new(databasepath) rescue StandardError => e Rails.logger.error "REDMINE_XAPIAN ERROR: Xapian database is not properly set, initiated or it's corrupted." @@ -397,7 +386,7 @@ class DmsfFile < ApplicationRecord qp.stemmer = stemmer qp.database = database - case Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip + case RedmineDmsf.dmsf_stemming_strategy.strip when 'STEM_NONE' qp.stemming_strategy = Xapian::QueryParser::STEM_NONE when 'STEM_SOME' @@ -413,7 +402,7 @@ class DmsfFile < ApplicationRecord end flags = Xapian::QueryParser::FLAG_WILDCARD - flags |= Xapian::QueryParser::FLAG_CJK_NGRAM if Setting.plugin_redmine_dmsf['dmsf_enable_cjk_ngrams'] + flags |= Xapian::QueryParser::FLAG_CJK_NGRAM if RedmineDmsf.dmsf_enable_cjk_ngrams? query = qp.parse_query(query_string, flags) diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index bb0c399b..b0ee7478 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -325,7 +325,7 @@ class DmsfFileRevision < ApplicationRecord format = if member&.dmsf_title_format.present? member.dmsf_title_format else - Setting.plugin_redmine_dmsf['dmsf_global_title_format'] + RedmineDmsf.dmsf_global_title_format end return name if format.blank? diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index de00bcd9..90639737 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -371,9 +371,7 @@ class DmsfFolder < ApplicationRecord end def self.column_on?(column) - dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns'] - dmsf_columns ||= DmsfFolder::DEFAULT_COLUMNS - dmsf_columns.include? column + RedmineDmsf.dmsf_columns.include? column end def custom_value(custom_field) @@ -385,8 +383,7 @@ class DmsfFolder < ApplicationRecord end def self.get_column_position(column) - dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns'] - dmsf_columns ||= DmsfFolder::DEFAULT_COLUMNS + dmsf_columns = RedmineDmsf.dmsf_columns pos = 0 # 0 - checkbox # 1 - id @@ -545,7 +542,7 @@ class DmsfFolder < ApplicationRecord end def self.visible_folders(folders, project) - allowed = Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + allowed = RedmineDmsf.dmsf_act_as_attachable? && (project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) && User.current.allowed_to?(:display_system_folders, project) folders.reject do |folder| diff --git a/app/models/dmsf_query.rb b/app/models/dmsf_query.rb index d7d32622..cd9935c4 100644 --- a/app/models/dmsf_query.rb +++ b/app/models/dmsf_query.rb @@ -258,7 +258,7 @@ class DmsfQuery < Query return query if query&.visibility == VISIBILITY_PUBLIC # Global default - if (query_id = Setting.plugin_redmine_dmsf['dmsf_default_query']).present? + if (query_id = RedmineDmsf.dmsf_default_query).present? query = find_by(id: query_id) return query if query&.visibility == VISIBILITY_PUBLIC end diff --git a/app/models/dmsf_upload.rb b/app/models/dmsf_upload.rb index d7abd1fb..e2f5fdfd 100644 --- a/app/models/dmsf_upload.rb +++ b/app/models/dmsf_upload.rb @@ -56,7 +56,7 @@ class DmsfUpload @tempfile_path = '' @token = '' @digest = '' - if Setting.plugin_redmine_dmsf['empty_minor_version_by_default'] + if RedmineDmsf.empty_minor_version_by_default? @major_version = 1 @minor_version = nil else @@ -92,7 +92,7 @@ class DmsfUpload if file.nil? || file.last_revision.nil? @title = DmsfFileRevision.filename_to_title(@name) @description = uploaded[:comment] - if Setting.plugin_redmine_dmsf['empty_minor_version_by_default'] + if RedmineDmsf.empty_minor_version_by_default? @major_version = 1 @minor_version = nil else diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb index d620f7fb..f192ee86 100644 --- a/app/models/dmsf_workflow.rb +++ b/app/models/dmsf_workflow.rb @@ -249,9 +249,9 @@ class DmsfWorkflow < ApplicationRecord nil, assignments.first&.dmsf_workflow_step ) - return unless Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && controller && recipients.present? + return unless RedmineDmsf.dmsf_display_notified_recipients? && controller && recipients.present? - max_recipients = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i + max_recipients = RedmineDmsf.dmsf_max_notification_receivers_info to = recipients.collect(&:name).first(max_recipients).join(', ') return if to.blank? diff --git a/app/views/dmsf/_main.html.erb b/app/views/dmsf/_main.html.erb index b9dbe00f..ebc8030c 100644 --- a/app/views/dmsf/_main.html.erb +++ b/app/views/dmsf/_main.html.erb @@ -80,12 +80,12 @@ <%= context_menu %> -<% if !@folder&.system && (@project || Setting.plugin_redmine_dmsf['dmsf_webdav'].present?) %> +<% if !@folder&.system && (@project || RedmineDmsf.dmsf_webdav?) %> <% other_formats_links do |f| %> <% if @project %> <%= f.link_to 'CSV', url: { action: :show, id: @project, folder_id: @folder, encoding: Encoding::UTF_8 } %> <% end %> - <% if Setting.plugin_redmine_dmsf['dmsf_webdav'].present? %> + <% if RedmineDmsf.dmsf_webdav? %> <%= link_to 'WebDAV', webdav_url(@project, @folder), class: 'webdav' %> diff --git a/app/views/dmsf/email_entries.html.erb b/app/views/dmsf/email_entries.html.erb index 6adea8ea..7c35561c 100644 --- a/app/views/dmsf/email_entries.html.erb +++ b/app/views/dmsf/email_entries.html.erb @@ -56,7 +56,7 @@ <%= link_to 'Documents.zip', download_email_entries_path(id: @project, folder_id: @folder, path: @email_params[:zipped_content]) %> <%= l(:label_or) %> - <%= check_box_tag('email[links_only]', 1, Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'], + <%= check_box_tag('email[links_only]', 1, RedmineDmsf.dmsf_documents_email_links_only?, onchange: "$('#public_url').toggle($('#email_links_only').prop('checked'))") %> <%= l(:label_links_only) %> diff --git a/app/views/dmsf_context_menus/_file.html.erb b/app/views/dmsf_context_menus/_file.html.erb index 2dd41979..853a0a01 100644 --- a/app/views/dmsf_context_menus/_file.html.erb +++ b/app/views/dmsf_context_menus/_file.html.erb @@ -83,7 +83,7 @@ method: :post, class: 'icon icon-email', data: { cy: "icon__email--dmsf_file_#{dmsf_file.id}" }, disabled: !email_allowed %> -<% if Setting.plugin_redmine_dmsf['dmsf_webdav'].present? %> +<% if RedmineDmsf.dmsf_webdav? %>
  • <% if dmsf_file.last_revision && dmsf_file.last_revision.protocol %> <% url = "#{dmsf_file.last_revision.protocol}:ofe|u|#{Setting.protocol.strip}://#{Setting.host_name.strip}/dmsf/webdav/#{Addressable::URI.escape(RedmineDmsf::Webdav::ProjectResource.create_project_name(dmsf_file.project))}/" %> diff --git a/app/views/dmsf_public_urls/_new.html.erb b/app/views/dmsf_public_urls/_new.html.erb index d7c8206d..142b98f5 100644 --- a/app/views/dmsf_public_urls/_new.html.erb +++ b/app/views/dmsf_public_urls/_new.html.erb @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> -<% classes = 'hol' unless Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'] %> +<% classes = 'hol' unless RedmineDmsf.dmsf_documents_email_links_only? %> <%= check_box_tag 'email[public_urls]', 1, false %> <%= l(:label_public_urls) %> <%= date_field_tag('email[expired_at]', '', value: (DateTime.current + 3.days).to_date, size: 10) + diff --git a/app/views/dmsf_state/_user_pref.html.erb b/app/views/dmsf_state/_user_pref.html.erb index 63de4c15..09018daa 100644 --- a/app/views/dmsf_state/_user_pref.html.erb +++ b/app/views/dmsf_state/_user_pref.html.erb @@ -49,7 +49,7 @@
    <%= l(:field_project) %> <%= l(:label_preferences) %> - <% if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] %> + <% if RedmineDmsf.dmsf_act_as_attachable? %>

    <%= content_tag(:label, "#{l(:label_act_as_attachable)}:") %> <%= select_tag 'act_as_attachable', diff --git a/app/views/hooks/redmine_dmsf/_view_my_account.html.erb b/app/views/hooks/redmine_dmsf/_view_my_account.html.erb index e15939dd..a11ac9d4 100644 --- a/app/views/hooks/redmine_dmsf/_view_my_account.html.erb +++ b/app/views/hooks/redmine_dmsf/_view_my_account.html.erb @@ -28,7 +28,7 @@

    <%= pref_fields.check_box :receive_download_notification %>

    <% end %> -<% if Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' %> +<% if RedmineDmsf.dmsf_webdav_authentication == 'Digest' %>

    <% token = Token.find_by(user_id: @user.id, action: 'dmsf_webdav_digest') %> diff --git a/extra/xapian_indexer.rb b/extra/xapian_indexer.rb index 2b05f26f..901a3bc5 100644 --- a/extra/xapian_indexer.rb +++ b/extra/xapian_indexer.rb @@ -141,7 +141,7 @@ begin # Indexing documents stem_langs.each do |lang| - filespath = Setting.plugin_redmine_dmsf['dmsf_storage_directory'] || File.join(REDMINE_ROOT, FILES) + filespath = RedmineDmsf.dmsf_storage_directory unless File.directory?(filespath) warn "'#{filespath}' doesn't exist." exit 1 diff --git a/init.rb b/init.rb index a2cb52d4..0602e313 100644 --- a/init.rb +++ b/init.rb @@ -56,7 +56,7 @@ Redmine::Plugin.register :redmine_dmsf do 'dmsf_webdav_use_project_names' => use_project_names, 'dmsf_webdav_ignore_1b_file_for_authentication' => '1', 'dmsf_projects_as_subfolders' => nil, - 'only_approval_zero_minor_version' => '0', + 'only_approval_zero_minor_version' => nil, 'dmsf_max_notification_receivers_info' => 10, 'office_bin' => 'libreoffice', 'dmsf_global_menu_disabled' => nil, diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 4527f734..a2ecd8d5 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -18,6 +18,180 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Main module +module RedmineDmsf + # Settings + class << self + def dmsf_max_file_download + Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i + end + + def dmsf_max_email_filesize + Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_i + end + + def dmsf_storage_directory + Setting.plugin_redmine_dmsf['dmsf_storage_directory'].presence || 'files/dmsf' + end + + def dmsf_index_database + Setting.plugin_redmine_dmsf['dmsf_index_database'].presence || File.expand_path('dmsf_index', Rails.root) + end + + def dmsf_stemming_lang + Setting.plugin_redmine_dmsf['dmsf_stemming_lang'].presence || 'english' + end + + def dmsf_stemming_strategy + Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].presence || 'STEM_NONE' + end + + def dmsf_webdav? + if Setting.plugin_redmine_dmsf['dmsf_webdav'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_webdav'] + else + Setting.plugin_redmine_dmsf['dmsf_webdav'].to_i.positive? + end + end + + def dmsf_display_notified_recipients? + if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + else + Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'].to_i.positive? + end + end + + def dmsf_global_title_format + Setting.plugin_redmine_dmsf['dmsf_global_title_format'].presence || '' + end + + def dmsf_columns + Setting.plugin_redmine_dmsf['dmsf_columns'].presence || DmsfFolder::DEFAULT_COLUMNS + end + + def dmsf_webdav_ignore + Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'].presence || '^(\._|\.DS_Store$|Thumbs.db$)' + end + + def dmsf_webdav_disable_versioning + Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'].presence || '^\~\$|\.tmp$' + end + + def dmsf_keep_documents_locked? + if Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'] + else + Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'].to_i.positive? + end + end + + def dmsf_act_as_attachable? + if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable?'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_act_as_attachable?'] + else + Setting.plugin_redmine_dmsf['dmsf_act_as_attachable?'].to_i.positive? + end + end + + def dmsf_documents_email_from + Setting.plugin_redmine_dmsf['dmsf_documents_email_from'].presence || "#{User.current.name} <#{User.current.mail}>" + end + + def dmsf_documents_email_reply_to + Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'].presence || '' + end + + def dmsf_documents_email_links_only? + if Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'] + else + Setting.plugin_redmine_dmsf['dmsf_documents_email_links_only'].to_i.positive? + end + end + + def dmsf_enable_cjk_ngrams? + if Setting.plugin_redmine_dmsf['dmsf_enable_cjk_ngrams'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_enable_cjk_ngrams'] + else + Setting.plugin_redmine_dmsf['dmsf_enable_cjk_ngrams'].to_i.positive? + end + end + + def dmsf_webdav_use_project_names? + if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] + else + Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'].to_i.positive? + end + end + + def dmsf_webdav_ignore_1b_file_for_authentication? + if Setting.plugin_redmine_dmsf['dmsf_webdav_ignore_1b_file_for_authentication'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_webdav_ignore_1b_file_for_authentication'] + else + Setting.plugin_redmine_dmsf['dmsf_webdav_ignore_1b_file_for_authentication'].to_i.positive? + end + end + + def dmsf_projects_as_subfolders? + if Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'] + else + Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'].to_i.positive? + end + end + + def only_approval_zero_minor_version? + if Setting.plugin_redmine_dmsf['only_approval_zero_minor_version'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['only_approval_zero_minor_version'] + else + Setting.plugin_redmine_dmsf['only_approval_zero_minor_version'].to_i.positive? + end + end + + def dmsf_max_notification_receivers_info + Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].positive? + end + + def office_bin + Setting.plugin_redmine_dmsf['office_bin'].presence || '' + end + + def dmsf_global_menu_disabled? + if Setting.plugin_redmine_dmsf['dmsf_global_menu_disabled'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['dmsf_global_menu_disabled'] + else + Setting.plugin_redmine_dmsf['dmsf_global_menu_disabled'].to_i.positive? + end + end + + def dmsf_default_query + Setting.plugin_redmine_dmsf['dmsf_default_query'].presence || '' + end + + def empty_minor_version_by_default? + if Setting.plugin_redmine_dmsf['empty_minor_version_by_default'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['empty_minor_version_by_default'] + else + Setting.plugin_redmine_dmsf['empty_minor_version_by_default'].to_i.positive? + end + end + + def remove_original_documents_module? + if Setting.plugin_redmine_dmsf['remove_original_documents_module'].is_a?(TrueClass) + Setting.plugin_redmine_dmsf['remove_original_documents_module'] + else + Setting.plugin_redmine_dmsf['remove_original_documents_module'].to_i.positive? + end + end + + def dmsf_webdav_authentication + Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'].presence || 'Basic' + end + end +end + # DMSF libraries # Validators diff --git a/lib/redmine_dmsf/errors/dmsf_email_max_file_size_error.rb b/lib/redmine_dmsf/errors/dmsf_email_max_file_size_error.rb index 1e232d15..3224199a 100644 --- a/lib/redmine_dmsf/errors/dmsf_email_max_file_size_error.rb +++ b/lib/redmine_dmsf/errors/dmsf_email_max_file_size_error.rb @@ -28,7 +28,7 @@ module RedmineDmsf if message.present? super else - super(l(:error_max_email_filesize_exceeded, number: Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'])) + super(l(:error_max_email_filesize_exceeded, number: RedmineDmsf.dmsf_max_email_filesize)) end end end diff --git a/lib/redmine_dmsf/errors/dmsf_zip_max_files_error.rb b/lib/redmine_dmsf/errors/dmsf_zip_max_files_error.rb index f076492e..b715097a 100644 --- a/lib/redmine_dmsf/errors/dmsf_zip_max_files_error.rb +++ b/lib/redmine_dmsf/errors/dmsf_zip_max_files_error.rb @@ -28,7 +28,7 @@ module RedmineDmsf if message.present? super else - super(l(:error_max_files_exceeded, number: Setting.plugin_redmine_dmsf['dmsf_max_file_download'])) + super(l(:error_max_files_exceeded, number: RedmineDmsf.dmsf_max_file_download)) end end end diff --git a/lib/redmine_dmsf/hooks/controllers/account_controller_hooks.rb b/lib/redmine_dmsf/hooks/controllers/account_controller_hooks.rb index 61bd8e36..a4c12a02 100644 --- a/lib/redmine_dmsf/hooks/controllers/account_controller_hooks.rb +++ b/lib/redmine_dmsf/hooks/controllers/account_controller_hooks.rb @@ -32,7 +32,7 @@ module RedmineDmsf user = context[:user] return unless user - return unless Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' + return unless RedmineDmsf.dmsf_webdav_authentication == 'Digest' # Updates user's DMSF WebDAV digest if controller.params[:password].present? diff --git a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb index eb90059f..3bbdd6fb 100644 --- a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb @@ -114,7 +114,7 @@ module RedmineDmsf def allowed_to_attach_documents(container) container.respond_to?(:saved_dmsf_attachments) && container.project && User.current.allowed_to?(:file_manipulation, container.project) && - Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + RedmineDmsf.dmsf_act_as_attachable? && (container.project&.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) end @@ -128,7 +128,7 @@ module RedmineDmsf links = [] if defined?(container.dmsf_files) && User.current.allowed_to?(:view_dmsf_files, container.project) && - Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + RedmineDmsf.dmsf_act_as_attachable? && container.project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS container.dmsf_files.each do |dmsf_file| links << [dmsf_file, nil, dmsf_file.created_at] if dmsf_file.last_revision diff --git a/lib/redmine_dmsf/patches/access_control_patch.rb b/lib/redmine_dmsf/patches/access_control_patch.rb index 9012bf94..5eb019bb 100644 --- a/lib/redmine_dmsf/patches/access_control_patch.rb +++ b/lib/redmine_dmsf/patches/access_control_patch.rb @@ -34,7 +34,7 @@ module RedmineDmsf 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'] + if RedmineDmsf.remove_original_documents_module? super.reject { |m| m == :documents } else super diff --git a/lib/redmine_dmsf/patches/search_patch.rb b/lib/redmine_dmsf/patches/search_patch.rb index 987d2386..7ed0daa7 100644 --- a/lib/redmine_dmsf/patches/search_patch.rb +++ b/lib/redmine_dmsf/patches/search_patch.rb @@ -34,7 +34,7 @@ module RedmineDmsf module ClassMethods def available_search_types # Removes the original Documents from searching (replaced with DMSF) - if Setting.plugin_redmine_dmsf['remove_original_documents_module'] + if RedmineDmsf.remove_original_documents_module? super.reject { |t| t == 'documents' } else super diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb index bca65725..35a9823b 100644 --- a/lib/redmine_dmsf/webdav/base_resource.rb +++ b/lib/redmine_dmsf/webdav/base_resource.rb @@ -39,7 +39,7 @@ module RedmineDmsf ) def initialize(path, request, response, options) - raise NotFound if Setting.plugin_redmine_dmsf['dmsf_webdav'].blank? + raise NotFound unless RedmineDmsf.dmsf_webdav? @project = nil @public_path = "#{options[:root_uri_path]}#{path}" @@ -162,7 +162,7 @@ module RedmineDmsf def get_project(scope, name, parent_project) prj = nil scope = scope.where(parent_id: parent_project.id) if parent_project - if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] + if RedmineDmsf.dmsf_webdav_use_project_names? if name =~ /^\[?.+ (\d+)\]?$/ prj = scope.find_by(id: Regexp.last_match(1)) # Check again whether it's really the project and not a folder with a number as a suffix diff --git a/lib/redmine_dmsf/webdav/dmsf_controller.rb b/lib/redmine_dmsf/webdav/dmsf_controller.rb index bd82aec7..45d09bbc 100644 --- a/lib/redmine_dmsf/webdav/dmsf_controller.rb +++ b/lib/redmine_dmsf/webdav/dmsf_controller.rb @@ -33,7 +33,7 @@ module RedmineDmsf end def process - return super unless Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' + return super unless RedmineDmsf.dmsf_webdav_authentication == 'Digest' status = skip_authorization? || authenticate ? process_action || OK : Dav4rack::HttpStatus::Unauthorized rescue Dav4rack::HttpStatus::Status => e @@ -52,7 +52,7 @@ module RedmineDmsf end def authenticate - return super unless Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' + return super unless RedmineDmsf.dmsf_webdav_authentication == 'Digest' auth_header = request.authorization.to_s scheme = auth_header.split(' ', 2).first&.downcase diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 4064dd9e..eb42ddf3 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -199,11 +199,11 @@ module RedmineDmsf end raise Locked if file.locked_for_user? - pattern = Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'] + pattern = RedmineDmsf.dmsf_webdav_disable_versioning # Files that are not versioned should be destroyed # Zero-sized files should be destroyed b = !file.last_revision || file.last_revision.size.zero? - destroy = (pattern.present? && basename.match(pattern)) || b + destroy = basename.match(pattern) || b if file.delete(commit: destroy) DmsfMailer.deliver_files_deleted project, [file] NoContent @@ -551,8 +551,7 @@ module RedmineDmsf if exist? # We're over-writing something, so ultimately a new revision f = file # Disable versioning for file name patterns given in the plugin settings. - pattern = Setting.plugin_redmine_dmsf['dmsf_webdav_disable_versioning'] - if pattern.present? && basename.match(pattern) + if basename.match(RedmineDmsf.dmsf_webdav_disable_versioning) Rails.logger.info "Versioning disabled for #{basename}" reuse_revision = true end @@ -611,8 +610,7 @@ module RedmineDmsf end # Ignore 1b files sent for authentication - if Setting.plugin_redmine_dmsf['dmsf_webdav_ignore_1b_file_for_authentication'].present? && - new_revision.size == 1 + if RedmineDmsf.dmsf_webdav_ignore_1b_file_for_authentication? && new_revision.size == 1 Rails.logger.warn "1b file '#{basename}' sent for authentication ignored" return NoContent end @@ -797,9 +795,7 @@ module RedmineDmsf def ignore? # Ignore file name patterns given in the plugin settings - pattern = Setting.plugin_redmine_dmsf['dmsf_webdav_ignore'] - pattern = /^(\._|\.DS_Store$|Thumbs.db$)/ if pattern.blank? - if basename.match(pattern) + if basename.match(RedmineDmsf.dmsf_webdav_ignore) Rails.logger.info "#{basename} ignored" return true end diff --git a/lib/redmine_dmsf/webdav/project_resource.rb b/lib/redmine_dmsf/webdav/project_resource.rb index 0d1d1435..55e87683 100644 --- a/lib/redmine_dmsf/webdav/project_resource.rb +++ b/lib/redmine_dmsf/webdav/project_resource.rb @@ -31,7 +31,7 @@ module RedmineDmsf return @children unless project # Sub-projects - load_projects(project.children) if Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'] + load_projects(project.children) if RedmineDmsf.dmsf_projects_as_subfolders? return @children unless project.module_enabled?(:dmsf) # Folders @@ -118,7 +118,7 @@ module RedmineDmsf def self.create_project_name(prj) return unless prj - if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] + if RedmineDmsf.dmsf_webdav_use_project_names? "[#{DmsfFolder.get_valid_title(prj.name)} #{prj.id}]" else "[#{prj.identifier}]" diff --git a/lib/redmine_dmsf/webdav/resource_proxy.rb b/lib/redmine_dmsf/webdav/resource_proxy.rb index 79224adf..17ccc2e7 100644 --- a/lib/redmine_dmsf/webdav/resource_proxy.rb +++ b/lib/redmine_dmsf/webdav/resource_proxy.rb @@ -32,7 +32,7 @@ module RedmineDmsf # Check the settings cache for each request Setting.check_cache # Return 404 - NotFound if WebDAV is not enabled - raise NotFound unless Setting.plugin_redmine_dmsf['dmsf_webdav'] + raise NotFound unless RedmineDmsf.dmsf_webdav? super rc = get_resource_class(path) diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index a25ac74a..096fe18b 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -344,7 +344,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_from' => 'karel.picman@kontron.com' } do post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :success - assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_from'] + assert_select "input:match('value', ?)", RedmineDmsf.dmsf_documents_email_from end end @@ -353,7 +353,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase with_settings plugin_redmine_dmsf: { 'dmsf_documents_email_reply_to' => 'karel.picman@kontron.com' } do post "/projects/#{@project1.id}/dmsf/entries", params: { email_entries: true, ids: ["file-#{@file1.id}"] } assert_response :success - assert_select "input:match('value', ?)", Setting.plugin_redmine_dmsf['dmsf_documents_email_reply_to'] + assert_select "input:match('value', ?)", RedmineDmsf.dmsf_documents_email_reply_to end end