Skip to content

Commit

Permalink
Plugin settings 'Display notified recipients' does not apply! #1565
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Nov 25, 2024
1 parent acde546 commit 48da190
Show file tree
Hide file tree
Showing 34 changed files with 247 additions and 97 deletions.
2 changes: 1 addition & 1 deletion after_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dmsf_context_menus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def dmsf
@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
Expand Down
15 changes: 7 additions & 8 deletions app/controllers/dmsf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def show
@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
Expand Down Expand Up @@ -501,7 +501,7 @@ def email_entries(selected_folders, selected_files)
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
Expand All @@ -527,9 +527,8 @@ def email_entries(selected_folders, selected_files)
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'
Expand Down Expand Up @@ -583,7 +582,7 @@ def zip_entries(zip, selected_folders, selected_files)

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
Expand Down Expand Up @@ -647,8 +646,8 @@ def delete_entries(selected_folders, selected_files, selected_links, commit)
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 ? ',...' : '.')
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/dmsf_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def view
# 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
Expand Down Expand Up @@ -181,8 +180,8 @@ def create_revision
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 ? ',...' : '.')
Expand Down Expand Up @@ -224,8 +223,8 @@ def delete
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 ? ',...' : '.')
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/dmsf_state_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def user_pref_save
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
Expand Down
18 changes: 8 additions & 10 deletions app/controllers/dmsf_workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def new_action
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
Expand All @@ -99,8 +97,8 @@ def new_action
: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 ? ',...' : '.')
Expand All @@ -122,8 +120,8 @@ def new_action
: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 ? ',...' : '.')
Expand All @@ -146,7 +144,7 @@ def new_action
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
Expand Down Expand Up @@ -186,13 +184,13 @@ def new_action
: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 ? ',...' : '.')
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/dmsf_upload_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def self.commit_files_internal(committed_files, project, folder, controller = ni
# 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 ? ',...' : '.')
Expand Down
29 changes: 9 additions & 20 deletions app/models/dmsf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,10 @@ def initialize(*args)
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

Expand All @@ -120,7 +117,7 @@ def self.findn_file_by_name(project_id, folder, name)
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
Expand Down Expand Up @@ -369,16 +366,8 @@ def self.search(tokens, projects = nil, options = {}, user = User.current)
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."
Expand All @@ -397,7 +386,7 @@ def self.search(tokens, projects = nil, options = {}, user = User.current)
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'
Expand All @@ -413,7 +402,7 @@ def self.search(tokens, projects = nil, options = {}, user = User.current)
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)

Expand Down
2 changes: 1 addition & 1 deletion app/models/dmsf_file_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def formatted_name(member)
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?

Expand Down
9 changes: 3 additions & 6 deletions app/models/dmsf_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,7 @@ def items
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)
Expand All @@ -385,8 +383,7 @@ def custom_value(custom_field)
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
Expand Down Expand Up @@ -545,7 +542,7 @@ def inherited_permissions_from
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|
Expand Down
2 changes: 1 addition & 1 deletion app/models/dmsf_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def self.default(project = nil, user = User.current)
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/dmsf_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize(project, folder = nil, uploaded = nil)
@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
Expand Down Expand Up @@ -92,7 +92,7 @@ def initialize(project, folder = nil, uploaded = nil)
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/dmsf_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ def notify_users(project, revision, controller)
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?

Expand Down
4 changes: 2 additions & 2 deletions app/views/dmsf/_main.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
<span>
<%= link_to 'WebDAV', webdav_url(@project, @folder), class: 'webdav' %>
</span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/dmsf/email_entries.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/dmsf_context_menus/_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
method: :post, class: 'icon icon-email',
data: { cy: "icon__email--dmsf_file_#{dmsf_file.id}" }, disabled: !email_allowed %>
</li>
<% if Setting.plugin_redmine_dmsf['dmsf_webdav'].present? %>
<% if RedmineDmsf.dmsf_webdav? %>
<li>
<% 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))}/" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/dmsf_public_urls/_new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
<span id="public_url" class="<%= classes %>">
<%= 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) +
Expand Down
2 changes: 1 addition & 1 deletion app/views/dmsf_state/_user_pref.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<fieldset class="box tabular">
<legend><%= l(:field_project) %> <%= l(:label_preferences) %></legend>
<% if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] %>
<% if RedmineDmsf.dmsf_act_as_attachable? %>
<p>
<%= content_tag(:label, "#{l(:label_act_as_attachable)}:") %>
<%= select_tag 'act_as_attachable',
Expand Down
2 changes: 1 addition & 1 deletion app/views/hooks/redmine_dmsf/_view_my_account.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</p>
<p><%= pref_fields.check_box :receive_download_notification %></p>
<% end %>
<% if Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' %>
<% if RedmineDmsf.dmsf_webdav_authentication == 'Digest' %>
<p>
<label for='webdav_digest_reset'><%= l(:label_dmsf_webdav_digest) %></label>
<% token = Token.find_by(user_id: @user.id, action: 'dmsf_webdav_digest') %>
Expand Down
2 changes: 1 addition & 1 deletion extra/xapian_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def system_or_raise(command, verbose)

# 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
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'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,
Expand Down
Loading

0 comments on commit 48da190

Please sign in to comment.