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 @@