From 4cc7ceb6aa6a0a0e1bf25d8afba4ebdbe7207098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 28 Mar 2023 09:27:05 +0200 Subject: [PATCH] Rubocop test --- app/controllers/dmsf_files_controller.rb | 6 +- app/controllers/dmsf_workflows_controller.rb | 242 +++++++++--------- app/helpers/dmsf_queries_helper.rb | 4 +- app/helpers/dmsf_upload_helper.rb | 3 +- app/models/dmsf_file.rb | 7 +- app/models/dmsf_mailer.rb | 2 +- app/models/dmsf_query.rb | 45 ++-- .../easy_dms/epm_dmsf_locked_documents.rb | 3 + .../easy_dms/epm_dmsf_open_approvals.rb | 3 + app/views/dmsf_files/_link.html.erb | 1 + extra/xapian_indexer.rb | 2 +- lib/dav4rack/interceptor_resource.rb | 1 - lib/dav4rack/request.rb | 1 - lib/redmine_dmsf.rb | 2 +- .../hooks/views/issue_view_hooks.rb | 2 +- lib/redmine_dmsf/macros.rb | 22 +- lib/redmine_dmsf/patches/notifiable_patch.rb | 2 +- .../patches/notifiable_ru_patch.rb | 4 +- lib/redmine_dmsf/plugin.rb | 2 +- lib/redmine_dmsf/webdav/custom_middleware.rb | 3 + lib/redmine_dmsf/webdav/dmsf_resource.rb | 2 - lib/tasks/dmsf_alert_approvals.rake | 7 +- lib/tasks/dmsf_convert_documents.rake | 46 ++-- lib/tasks/dmsf_create_digests.rake | 6 +- lib/tasks/dmsf_maintenance.rake | 36 +-- test/functional/dmsf_files_controller_test.rb | 2 +- test/functional/my_controller_test.rb | 2 +- .../unit/lib/redmine_dmsf/dmsf_macros_test.rb | 30 +-- .../unit/lib/redmine_dmsf/dmsf_plugin_test.rb | 14 +- test/unit/user_patch_test.rb | 17 +- 30 files changed, 263 insertions(+), 256 deletions(-) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 57ba04a8..62e38632 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -186,8 +186,7 @@ class DmsfFilesController < ApplicationController if recipients.any? to = recipients.collect{ |user, _| user.name }.first( Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? - ',...' : '.') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') end end rescue => e @@ -233,8 +232,7 @@ class DmsfFilesController < ApplicationController if recipients.any? to = recipients.collect{ |user, _| user.name }.first( Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? - ',...' : '.') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') flash[:warning] = l(:warning_email_notifications, to: to) end end diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb index aea8e744..fbcb3b33 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -59,143 +59,143 @@ class DmsfWorkflowsController < ApplicationController end def new_action - if params[:commit] == l(:button_submit) - action = DmsfWorkflowStepAction.new( - dmsf_workflow_step_assignment_id: params[:dmsf_workflow_step_assignment_id], - action: (params[:step_action].to_i >= 10) ? DmsfWorkflowStepAction::ACTION_DELEGATE : params[:step_action], - note: params[:note]) - if request.post? - revision = DmsfFileRevision.find_by(id: params[:dmsf_file_revision_id]) - result = call_hook(:dmsf_workflow_controller_before_approval, - { dmsf_file_revision: revision, step_action: params[:step_action] }) - if (result.blank? || result.first) && action.save - if revision - if @dmsf_workflow.try_finish revision, action, (params[:step_action].to_i / 10) - if revision.dmsf_file - begin - revision.dmsf_file.unlock!(true) unless Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'] - rescue RedmineDmsf::Errors::DmsfLockError => e - flash[:info] = e.message + if (params[:commit] != l(:button_submit)) && !request.post? + redirect_back_or_default dmsf_folder_path(id: @project, folder_id: @folder) + return + end + action = DmsfWorkflowStepAction.new( + dmsf_workflow_step_assignment_id: params[:dmsf_workflow_step_assignment_id], + action: (params[:step_action].to_i >= 10) ? DmsfWorkflowStepAction::ACTION_DELEGATE : params[:step_action], + note: params[:note]) + revision = DmsfFileRevision.find_by(id: params[:dmsf_file_revision_id]) + result = call_hook(:dmsf_workflow_controller_before_approval, + { dmsf_file_revision: revision, step_action: params[:step_action] }) + if (result.blank? || result.first) && action.save + if revision + if @dmsf_workflow.try_finish revision, action, (params[:step_action].to_i / 10) + if revision.dmsf_file + begin + revision.dmsf_file.unlock!(true) unless Setting.plugin_redmine_dmsf['dmsf_keep_documents_locked'] + rescue RedmineDmsf::Errors::DmsfLockError => e + flash[:info] = e.message + end + end + if revision.workflow == DmsfWorkflow::STATE_APPROVED + # Just approved + if Setting.notified_events.include?('dmsf_workflow_plural') + recipients = DmsfMailer.get_notify_users(@project, revision.dmsf_file, true) + DmsfMailer.deliver_workflow_notification( + recipients, + @dmsf_workflow, + revision, + :text_email_subject_approved, + :text_email_finished_approved, + :text_email_to_see_history) + if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + unless recipients.blank? + to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) end end - if revision.workflow == DmsfWorkflow::STATE_APPROVED - # Just approved - if Setting.notified_events.include?('dmsf_workflow_plural') - recipients = DmsfMailer.get_notify_users(@project, revision.dmsf_file, true) - DmsfMailer.deliver_workflow_notification( - recipients, - @dmsf_workflow, - revision, - :text_email_subject_approved, - :text_email_finished_approved, - :text_email_to_see_history) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] - unless recipients.blank? - to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) - end - end - end - else - # Just rejected - if Setting.notified_events.include?('dmsf_workflow_plural') - recipients = @dmsf_workflow.participiants - recipients.push revision.dmsf_workflow_assigned_by_user - recipients.uniq! - recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file, true) - DmsfMailer.deliver_workflow_notification( - recipients, - @dmsf_workflow, - revision, - :text_email_subject_rejected, - :text_email_finished_rejected, - :text_email_to_see_history, - action.note) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] - unless recipients.blank? - to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) - end - end + end + else + # Just rejected + if Setting.notified_events.include?('dmsf_workflow_plural') + recipients = @dmsf_workflow.participiants + recipients.push revision.dmsf_workflow_assigned_by_user + recipients.uniq! + recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file, true) + DmsfMailer.deliver_workflow_notification( + recipients, + @dmsf_workflow, + revision, + :text_email_subject_rejected, + :text_email_finished_rejected, + :text_email_to_see_history, + action.note) + if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + unless recipients.blank? + to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) end end - else - if action.action == DmsfWorkflowStepAction::ACTION_DELEGATE - # Delegation - if Setting.notified_events.include?('dmsf_workflow_plural') - delegate = User.active.find_by(id: params[:step_action].to_i / 10) - if DmsfMailer.get_notify_users(@project, revision.dmsf_file, true).include?(delegate) + end + end + else + if action.action == DmsfWorkflowStepAction::ACTION_DELEGATE + # Delegation + if Setting.notified_events.include?('dmsf_workflow_plural') + delegate = User.active.find_by(id: params[:step_action].to_i / 10) + if DmsfMailer.get_notify_users(@project, revision.dmsf_file, true).include?(delegate) + DmsfMailer.deliver_workflow_notification( + [delegate], + @dmsf_workflow, + revision, + :text_email_subject_delegated, + :text_email_finished_delegated, + :text_email_to_proceed, + action.note, + action.dmsf_workflow_step_assignment.dmsf_workflow_step) + if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + flash[:warning] = l(:warning_email_notifications, to: delegate.name) + end + end + end + else + # Next step + assignments = @dmsf_workflow.next_assignments revision.id + unless assignments.empty? + if Setting.notified_events.include?('dmsf_workflow_plural') + if assignments.first.dmsf_workflow_step.step != action.dmsf_workflow_step_assignment.dmsf_workflow_step.step + # Next step + assignments.each do |assignment| + if assignment.user && DmsfMailer.get_notify_users(@project, revision.dmsf_file, + true).include?(assignment.user) + DmsfMailer.deliver_workflow_notification( + [assignment.user], + @dmsf_workflow, + revision, + :text_email_subject_requires_approval, + :text_email_finished_step, + :text_email_to_proceed, + nil, + assignment.dmsf_workflow_step) + end + end + to = revision.dmsf_workflow_assigned_by_user + if to && DmsfMailer.get_notify_users(@project, revision.dmsf_file, + true).include?(to) DmsfMailer.deliver_workflow_notification( - [delegate], + [to], @dmsf_workflow, revision, - :text_email_subject_delegated, - :text_email_finished_delegated, - :text_email_to_proceed, - action.note, - action.dmsf_workflow_step_assignment.dmsf_workflow_step) - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] - flash[:warning] = l(:warning_email_notifications, to: delegate.name) - end + :text_email_subject_updated, + :text_email_finished_step_short, + :text_email_to_see_status) end - end - else - # Next step - assignments = @dmsf_workflow.next_assignments revision.id - unless assignments.empty? - if Setting.notified_events.include?('dmsf_workflow_plural') - if assignments.first.dmsf_workflow_step.step != action.dmsf_workflow_step_assignment.dmsf_workflow_step.step - # Next step - assignments.each do |assignment| - if assignment.user && DmsfMailer.get_notify_users(@project, revision.dmsf_file, - true).include?(assignment.user) - DmsfMailer.deliver_workflow_notification( - [assignment.user], - @dmsf_workflow, - revision, - :text_email_subject_requires_approval, - :text_email_finished_step, - :text_email_to_proceed, - nil, - assignment.dmsf_workflow_step) - end - end - to = revision.dmsf_workflow_assigned_by_user - if to && DmsfMailer.get_notify_users(@project, revision.dmsf_file, - true).include?(to) - DmsfMailer.deliver_workflow_notification( - [to], - @dmsf_workflow, - revision, - :text_email_subject_updated, - :text_email_finished_step_short, - :text_email_to_see_status) - end - if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] - recipients = assignments.collect{ |a| a.user } - recipients << to if to - recipients.uniq! - recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file, - true) - unless recipients.empty? - to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) - end - end + if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] + recipients = assignments.collect{ |a| a.user } + recipients << to if to + recipients.uniq! + recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file, + true) + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) end end end end end end - flash[:notice] = l(:notice_successful_update) - elsif action.action != DmsfWorkflowStepAction::ACTION_APPROVE && action.note.blank? - flash[:error] = l(:error_empty_note) end end + flash[:notice] = l(:notice_successful_update) + elsif action.action != DmsfWorkflowStepAction::ACTION_APPROVE && action.note.blank? + flash[:error] = l(:error_empty_note) end redirect_back_or_default dmsf_folder_path(id: @project, folder_id: @folder) end diff --git a/app/helpers/dmsf_queries_helper.rb b/app/helpers/dmsf_queries_helper.rb index caaf65b6..113573c2 100644 --- a/app/helpers/dmsf_queries_helper.rb +++ b/app/helpers/dmsf_queries_helper.rb @@ -169,7 +169,7 @@ module DmsfQueriesHelper file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: (item.type == 'file') ? item.id : item.revision_id }) content_type = Redmine::MimeType.of(value) content_type = 'application/octet-stream' if content_type.blank? - tag = link_to(h(value), file_view_url, target: '_blank', + tag = link_to(h(value), file_view_url, target: '_blank', rel: 'noopener', class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}", 'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}") unless filter_any? @@ -189,7 +189,7 @@ module DmsfQueriesHelper if item&.deleted? tag = content_tag('span', value, class: 'icon dmsf-icon-link') else - tag = link_to(h(value), item.filename, target: '_blank', class: 'icon dmsf-icon-link') + tag = link_to(h(value), item.filename, target: '_blank', rel: 'noopener', class: 'icon dmsf-icon-link') unless filter_any? tag = "".html_safe + tag end diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index b7383fcc..1a72e780 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -135,8 +135,7 @@ module DmsfUploadHelper unless recipients.empty? to = recipients.collect{ |user, _| user.name }.first( Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i).join(', ') - to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? - ',...' : '.') + to << ((recipients.count > Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i) ? ',...' : '.') controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller end end diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 6f203d79..bff80086 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -78,11 +78,12 @@ class DmsfFile < ActiveRecord::Base project_key: 'project_id', date_column: "#{table_name}.updated_at" - cattr_accessor :previews_storage_path - @@previews_storage_path = File.join(Rails.root, 'tmp', 'dmsf_previews') - before_create :default_values + def self.previews_storage_path + File.join Rails.root, 'tmp', 'dmsf_previews' + end + def default_values if Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present? && (!dmsf_folder || !dmsf_folder.system) self.notification = true diff --git a/app/models/dmsf_mailer.rb b/app/models/dmsf_mailer.rb index b919c704..276673b8 100644 --- a/app/models/dmsf_mailer.rb +++ b/app/models/dmsf_mailer.rb @@ -205,7 +205,7 @@ class DmsfMailer < Mailer watchers = [] file&.get_all_watchers(watchers) users.concat watchers - if User.current&.pref.no_self_notified + if User.current && User.current.pref.no_self_notified users.delete User.current end users.uniq diff --git a/app/models/dmsf_query.rb b/app/models/dmsf_query.rb index a32d8d36..795f843a 100644 --- a/app/models/dmsf_query.rb +++ b/app/models/dmsf_query.rb @@ -148,7 +148,7 @@ class DmsfQuery < Query "SELECT ct.id FROM dmsf_folders ct LEFT OUTER JOIN custom_values ON custom_values.customized_type='DmsfFolder' AND custom_values.customized_id=ct.id AND custom_values.custom_field_id=", 'SELECT custom_values.customized_id FROM custom_values WHERE custom_values.customized_type=dmsf_folders.customized_type AND custom_values.customized_id=dmsf_folders.customized_id AND custom_values.custom_field_id=') sql_cf.gsub! 'WHERE dmsf_folders.id = ct.id AND (', 'AND ' - sql_cf.gsub! /\)$/, '' + sql_cf.gsub!(/\)$/, '') filters_clauses << sql_cf else filters_clauses << '(' + sql_for_field(field, operator, v, queried_table_name, field) + ')' @@ -230,8 +230,7 @@ class DmsfQuery < Query if fo dmsf_link = DmsfLink.find_by(id: item.id) if dmsf_link.dmsf_folder - !dmsf_link.dmsf_folder.visible? - !DmsfFolder.permissions?(dmsf_link.dmsf_folder, false) + !dmsf_link.dmsf_folder.visible? || !DmsfFolder.permissions?(dmsf_link.dmsf_folder, false) else !dmsf_link.project.dmsf_available? end @@ -247,6 +246,26 @@ class DmsfQuery < Query [] end + def self.default(project = nil, user = User.current) + # User's default + if user&.logged? && (query_id = user.pref.default_dmsf_query).present? + query = find_by(id: query_id) + return query if query&.visible? + end + + # Project's default + project = project[:project] if project.is_a?(Hash) + query = project&.default_dmsf_query + return query if query&.visibility == VISIBILITY_PUBLIC + + # Global default + if (query_id = Setting.plugin_redmine_dmsf['dmsf_default_query']).present? + query = find_by(id: query_id) + return query if query&.visibility == VISIBILITY_PUBLIC + end + nil + end + private def filters_on? @@ -602,24 +621,4 @@ class DmsfQuery < Query end end - def self.default(project = nil, user = User.current) - # User's default - if user&.logged? && (query_id = user.pref.default_dmsf_query).present? - query = find_by(id: query_id) - return query if query&.visible? - end - - # Project's default - project = project[:project] if project&.is_a?(Hash) - query = project&.default_dmsf_query - return query if query&.visibility == VISIBILITY_PUBLIC - - # Global default - if (query_id = Setting.plugin_redmine_dmsf['dmsf_default_query']).present? - query = find_by(id: query_id) - return query if query&.visibility == VISIBILITY_PUBLIC - end - nil - end - end diff --git a/app/models/easy_page_modules/easy_dms/epm_dmsf_locked_documents.rb b/app/models/easy_page_modules/easy_dms/epm_dmsf_locked_documents.rb index 26eb28b9..eef6cded 100644 --- a/app/models/easy_page_modules/easy_dms/epm_dmsf_locked_documents.rb +++ b/app/models/easy_page_modules/easy_dms/epm_dmsf_locked_documents.rb @@ -24,6 +24,9 @@ module EasyPageModules unless defined?(EasyExtensions) class EasyPageModule + def foo + 'A false class' + end end end diff --git a/app/models/easy_page_modules/easy_dms/epm_dmsf_open_approvals.rb b/app/models/easy_page_modules/easy_dms/epm_dmsf_open_approvals.rb index 9b342475..44346dd8 100644 --- a/app/models/easy_page_modules/easy_dms/epm_dmsf_open_approvals.rb +++ b/app/models/easy_page_modules/easy_dms/epm_dmsf_open_approvals.rb @@ -24,6 +24,9 @@ module EasyPageModules unless defined?(EasyExtensions) class EasyPageModule + def foo + 'A false class' + end end end diff --git a/app/views/dmsf_files/_link.html.erb b/app/views/dmsf_files/_link.html.erb index c642f610..1057c60d 100644 --- a/app/views/dmsf_files/_link.html.erb +++ b/app/views/dmsf_files/_link.html.erb @@ -30,6 +30,7 @@ <%= link_to h(link ? link.name : dmsf_file.title), file_view_url, target: '_blank', + rel: 'noopener', class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}", title: h(dmsf_file.last_revision.try(:tooltip)), 'data-downloadurl' => "#{dmsf_file.last_revision.detect_content_type}:#{h(dmsf_file.name)}:#{file_view_url}" %> diff --git a/extra/xapian_indexer.rb b/extra/xapian_indexer.rb index d4886247..1e80723c 100644 --- a/extra/xapian_indexer.rb +++ b/extra/xapian_indexer.rb @@ -91,7 +91,7 @@ ENV['RAILS_ENV'] = $env def log(text, error = false) if error - $stderr.puts text + $stderr.warn text elsif $verbose > 0 $stdout.puts text end diff --git a/lib/dav4rack/interceptor_resource.rb b/lib/dav4rack/interceptor_resource.rb index 23dd37ce..741ea9de 100644 --- a/lib/dav4rack/interceptor_resource.rb +++ b/lib/dav4rack/interceptor_resource.rb @@ -1,4 +1,3 @@ - module Dav4rack class InterceptorResource < Resource diff --git a/lib/dav4rack/request.rb b/lib/dav4rack/request.rb index 027c6f55..529ed1c2 100644 --- a/lib/dav4rack/request.rb +++ b/lib/dav4rack/request.rb @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/uri' require 'addressable/uri' require File.dirname(__FILE__) + '/logger' -require File.dirname(__FILE__) + '/uri' module Dav4rack class Request < Rack::Request diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index eb1cd854..e12e3ea5 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -42,7 +42,7 @@ require File.dirname(__FILE__) + '/redmine_dmsf/patches/queries_controller_patch require File.dirname(__FILE__) + '/redmine_dmsf/patches/pdf_patch' # A workaround for obsolete 'alias_method' usage in RedmineUp's plugins -if RedmineDmsf::Plugin.an_osolete_plugin_present? +if RedmineDmsf::Plugin.an_obsolete_plugin_present? require File.dirname(__FILE__) + '/redmine_dmsf/patches/notifiable_ru_patch' else require File.dirname(__FILE__) + '/redmine_dmsf/patches/notifiable_patch' diff --git a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb index d2e24952..6550b256 100644 --- a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb @@ -220,7 +220,7 @@ module RedmineDmsf file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: dmsf_file}) # Title, size html << '' - html << link_to(h(dmsf_file.title),file_view_url, target: '_blank', + html << link_to(h(dmsf_file.title),file_view_url, target: '_blank', rel: 'noopener', class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}", title: h(dmsf_file.last_revision.try(:tooltip)), 'data-downloadurl' => "#{dmsf_file.last_revision.detect_content_type}:#{h(dmsf_file.name)}:#{file_view_url}") diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb index 86a52ddb..5628dd89 100644 --- a/lib/redmine_dmsf/macros.rb +++ b/lib/redmine_dmsf/macros.rb @@ -43,12 +43,12 @@ module RedmineDmsf raise ActiveRecord::RecordNotFound end end - title = args[1].present? ? args[1] : file.title - title.gsub! /\A"|"\z/, '' # Remove apostrophes - title.gsub! /\A'|'\z/, '' + title = (args[1].presence || file.title) + title.gsub!(/\A"|"\z/, '') # Remove apostrophes + title.gsub!(/\A'|'\z/, '') title = file.title if title.empty? url = view_dmsf_file_url(id: file.id, download: args[2]) - link_to h(title), url, target: '_blank', title: h(revision.tooltip), + link_to h(title), url, target: '_blank', rel: 'noopener', title: h(revision.tooltip), 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}" end @@ -66,9 +66,9 @@ module RedmineDmsf else folder = DmsfFolder.visible.find args[0] if User.current&.allowed_to?(:view_dmsf_folders, folder.project) - title = args[1] ? args[1] : folder.title - title.gsub! /\A"|"\z/, '' # Remove leading and trailing apostrophe - title.gsub! /\A'|'\z/, '' + title = (args[1].presence || folder.title) + title.gsub!(/\A"|"\z/, '') # Remove leading and trailing apostrophe + title.gsub!(/\A'|'\z/, '') title = folder.title if title.empty? link_to h(title), dmsf_folder_url(folder.project, folder_id: folder) else @@ -85,9 +85,9 @@ module RedmineDmsf raise ArgumentError if args.length < 1 # Requires file id file = DmsfFile.visible.find args[0] if User.current&.allowed_to?(:view_dmsf_files, file.project) - title = args[1].present? ? args[1] : file.title - title.gsub! /\A"|"\z/, '' # Remove leading and trailing apostrophe - title.gsub! /\A'|'\z/, '' + title = (args[1].presence || file.title) + title.gsub!(/\A"|"\z/, '') # Remove leading and trailing apostrophe + title.gsub!(/\A'|'\z/, '') link_to h(title), dmsf_file_path(id: file) else raise l(:notice_not_authorized) @@ -261,7 +261,7 @@ module RedmineDmsf else img = image_tag(url, alt: filename, title: file.title, width: 'auto', height: 200) end - html << link_to( img, url, target: '_blank', title: h(file.last_revision.try(:tooltip)), + html << link_to( img, url, target: '_blank', rel: 'noopener', title: h(file.last_revision.try(:tooltip)), 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}") end html.html_safe diff --git a/lib/redmine_dmsf/patches/notifiable_patch.rb b/lib/redmine_dmsf/patches/notifiable_patch.rb index 5a48e1b3..cc41edac 100644 --- a/lib/redmine_dmsf/patches/notifiable_patch.rb +++ b/lib/redmine_dmsf/patches/notifiable_patch.rb @@ -52,6 +52,6 @@ module RedmineDmsf end # Apply the patch -unless !RedmineDmsf::Plugin.an_osolete_plugin_present? +unless RedmineDmsf::Plugin.an_obsolete_plugin_present? Redmine::Notifiable.prepend RedmineDmsf::Patches::NotifiablePatch end diff --git a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb b/lib/redmine_dmsf/patches/notifiable_ru_patch.rb index c6523d73..e96caec9 100644 --- a/lib/redmine_dmsf/patches/notifiable_ru_patch.rb +++ b/lib/redmine_dmsf/patches/notifiable_ru_patch.rb @@ -54,6 +54,6 @@ module RedmineDmsf end # Apply the patch -if RedmineDmsf::Plugin.an_osolete_plugin_present? - Redmine::Notifiable.send :include, RedmineDmsf::Patches::NotifiableRuPatch +if RedmineDmsf::Plugin.an_obsolete_plugin_present? + Redmine::Notifiable.include RedmineDmsf::Patches::NotifiableRuPatch end diff --git a/lib/redmine_dmsf/plugin.rb b/lib/redmine_dmsf/plugin.rb index 077d1421..cf82ca92 100644 --- a/lib/redmine_dmsf/plugin.rb +++ b/lib/redmine_dmsf/plugin.rb @@ -32,7 +32,7 @@ module RedmineDmsf # Return true if a plugin that overrides Redmine::Notifiable and use the deprecated method alias_method_chain is # present. # It is related especially to plugins made by AplhaNode and RedmineUP. - def self.an_osolete_plugin_present? + def self.an_obsolete_plugin_present? plugins = %w(easyproject/easy_plugins/easy_money redmine_questions redmine_contacts redmine_db redmine_passwords redmine_resources) plugins.each do|plugin| diff --git a/lib/redmine_dmsf/webdav/custom_middleware.rb b/lib/redmine_dmsf/webdav/custom_middleware.rb index 5871313d..3a00ae70 100644 --- a/lib/redmine_dmsf/webdav/custom_middleware.rb +++ b/lib/redmine_dmsf/webdav/custom_middleware.rb @@ -19,6 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require File.dirname(__FILE__) + '/../../dav4rack' +require File.dirname(__FILE__) + '/resource_proxy' + module RedmineDmsf module Webdav diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index 0226f62b..62ec95d9 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -764,8 +764,6 @@ module RedmineDmsf end end - private - def create_empty_file f = DmsfFile.new f.project_id = project.id diff --git a/lib/tasks/dmsf_alert_approvals.rake b/lib/tasks/dmsf_alert_approvals.rake index 084be04c..8d62fcf9 100644 --- a/lib/tasks/dmsf_alert_approvals.rake +++ b/lib/tasks/dmsf_alert_approvals.rake @@ -39,7 +39,7 @@ end class DmsfAlertApprovals def self.alert - dry_run = ENV['dry_run'] + dry_run = ENV.fetch('dry_run', nil) revisions = DmsfFileRevision.visible.joins(:dmsf_file).joins('JOIN projects ON projects.id = dmsf_files.project_id').where( dmsf_file_revisions: { workflow: DmsfWorkflow::STATE_WAITING_FOR_APPROVAL }, projects: { status: Project::STATUS_ACTIVE}) @@ -51,7 +51,7 @@ class DmsfAlertApprovals assignments.each do |assignment| next unless assignment.user.active? if dry_run - puts "#{assignment.user.name} <#{assignment.user.mail}>" + $stdout.puts "#{assignment.user.name} <#{assignment.user.mail}>" else DmsfMailer.deliver_workflow_notification( [assignment.user], @@ -61,8 +61,7 @@ class DmsfAlertApprovals :text_email_finished_step, :text_email_to_proceed, nil, - assignment.dmsf_workflow_step - ) + assignment.dmsf_workflow_step) end end end diff --git a/lib/tasks/dmsf_convert_documents.rake b/lib/tasks/dmsf_convert_documents.rake index e8885dcc..21daf735 100644 --- a/lib/tasks/dmsf_convert_documents.rake +++ b/lib/tasks/dmsf_convert_documents.rake @@ -39,7 +39,7 @@ END_DESC class DmsfConvertDocuments def initialize - @dry_run = ENV['dry_run'] + @dry_run = ENV.fetch('dry_run', nil) @projects = [] if ENV['project'] p = Project.find(ENV['project']) @@ -47,33 +47,33 @@ class DmsfConvertDocuments else @projects.concat(Project.active.to_a) end - @issues = ENV['issues'] + @issues = ENV.fetch('issues', nil) end def convert_projects if @projects.any? @projects.each do |project| - STDOUT.puts "Processing project: #{project.name}" + $stdout.puts "Processing project: #{project.name}" convert_documents(project) if project.module_enabled?('documents') convert_issues(project) if (@issues && project.module_enabled?('issue_tracking')) end else - STDERR.puts 'No active projects found.' + $stderr.warn 'No active projects found.' end end def convert_issues(project) - STDOUT.puts 'Issues' + $stdout.puts 'Issues' unless Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] - STDERR.puts "'Act as attachable' must be checked in the plugin's settings" + $stderr.warn "'Act as attachable' must be checked in the plugin's settings" return end project.issues.each do |issue| if issue.attachments.any? - STDOUT.puts "Processing: #{issue}" + $stdout.puts "Processing: #{issue}" project.enable_module!('dmsf') unless @dry_run # - folder - STDOUT.puts "Creating #{issue.id} - #{DmsfFolder::get_valid_title(issue.subject)} folder" + $stdout.puts "Creating #{issue.id} - #{DmsfFolder::get_valid_title(issue.subject)} folder" unless @dry_run folder = issue.system_folder(true, project.id) end @@ -98,10 +98,10 @@ class DmsfConvertDocuments @fail = false folders = [] if project.documents.any? - STDOUT.puts 'Documents' + $stdout.puts 'Documents' project.enable_module!('dmsf') unless @dry_run project.documents.each do |document| - STDOUT.puts "Processing document: #{document.title}" + $stdout.puts "Processing document: #{document.title}" folder = DmsfFolder.new folder.project = project attachment = document.attachments.reorder(created_on: :asc).first @@ -120,15 +120,15 @@ class DmsfConvertDocuments folder.title = folder.title + suffix folder.description = document.description if @dry_run - STDOUT.puts "Dry run folder: #{folder.title}" - STDERR.puts(folder.errors.full_messages.to_sentence) if folder.invalid? + $stdout.puts "Dry run folder: #{folder.title}" + $stderr.warn(folder.errors.full_messages.to_sentence) if folder.invalid? else begin folder.save! - STDOUT.puts "Created folder: #{folder.title}" + $stdout.puts "Created folder: #{folder.title}" rescue => e - STDERR.puts "Creating folder: #{folder.title} failed" - STDERR.puts e.message + $stderr.warn "Creating folder: #{folder.title} failed" + $stderr.warn e.message @fail = true next end @@ -165,14 +165,14 @@ class DmsfConvertDocuments # File id is needed to properly generate revision disk filename file.name = DmsfFileRevision.remove_extension(file.name) + suffix + File.extname(file.name) unless File.exist?(attachment.diskfile) - STDERR.puts "Creating file: #{attachment.filename} failed, attachment file #{attachment.diskfile} doesn't exist" + $stderr.warn "Creating file: #{attachment.filename} failed, attachment file #{attachment.diskfile} doesn't exist" @fail = true return end if @dry_run file.id = attachment.id # Just to have an ID there - STDOUT.puts "Dry run file: #{file.name}" - STDERR.puts(file.errors.full_messages.to_sentence) if file.invalid? + $stdout.puts "Dry run file: #{file.name}" + $stderr.warn(file.errors.full_messages.to_sentence) if file.invalid? else file.save! end @@ -194,17 +194,17 @@ class DmsfConvertDocuments revision.size = File.size(revision.disk_file(false)) end if @dry_run - STDOUT.puts "Dry run revision: #{revision.title}" - STDERR.puts(revision.errors.full_messages.to_sentence) if revision.invalid? + $stdout.puts "Dry run revision: #{revision.title}" + $stderr.warn(revision.errors.full_messages.to_sentence) if revision.invalid? else revision.save! end files << file attachment.destroy unless @dry_run - STDOUT.puts "Created file: #{file.name}" unless @dry_run + $stdout.puts "Created file: #{file.name}" unless @dry_run rescue => e - STDERR.puts "Creating file: #{attachment.filename} failed" - STDERR.puts e.message + $stderr.warn "Creating file: #{attachment.filename} failed" + $stderr.warn e.message @fail = true end end diff --git a/lib/tasks/dmsf_create_digests.rake b/lib/tasks/dmsf_create_digests.rake index 2a438afa..db04325e 100644 --- a/lib/tasks/dmsf_create_digests.rake +++ b/lib/tasks/dmsf_create_digests.rake @@ -43,8 +43,8 @@ end class DmsfCreateDigest def initialize - @dry_run = ENV['dry_run'] - @force_sha256 = ENV['forceSHA256'] + @dry_run = ENV.fetch('dry_run', nil) + @force_sha256 = ENV.fetch('forceSHA256', nil) end def dmsf_create_digests @@ -75,7 +75,7 @@ class DmsfCreateDigest end print "\r100%\n" # Result - puts "#{n}/#{count} revisions updated." + $stdout.puts "#{n}/#{count} revisions updated." end end diff --git a/lib/tasks/dmsf_maintenance.rake b/lib/tasks/dmsf_maintenance.rake index 46343afa..7b62edd1 100644 --- a/lib/tasks/dmsf_maintenance.rake +++ b/lib/tasks/dmsf_maintenance.rake @@ -37,11 +37,11 @@ namespace :redmine do task :dmsf_maintenance => :environment do m = DmsfMaintenance.new begin - STDERR.puts "\n" + $stdout.puts "\n" Dir.chdir(DmsfFile.storage_path) - puts "Files...\n" + $stdout.puts "Files...\n" m.files - puts "Documents...\n" + $stdout.puts "Documents...\n" m.documents if m.dry_run m.result @@ -49,7 +49,7 @@ namespace :redmine do m.clean end rescue => e - puts e.message + $stderr.warn e.message end end end @@ -61,7 +61,7 @@ class DmsfMaintenance attr_accessor :dry_run def initialize - @dry_run = ENV['dry_run'] + @dry_run = ENV.fetch('dry_run', nil) @files_to_delete = Array.new @documents_to_delete = Array.new end @@ -79,7 +79,7 @@ class DmsfMaintenance r = f.last_revision if r.nil? || (!File.exist?(r.disk_file)) @documents_to_delete << f - puts "\t#{r.disk_file}\n" if r + $stdout.puts "\t#{r.disk_file}\n" if r end end end @@ -87,14 +87,14 @@ class DmsfMaintenance def result # Files size = 0 - @files_to_delete.each{ |f| size += File.size(f) } - puts "\n#{@files_to_delete.count} files havn't got a coresponding revision and can be deleted." - puts "#{number_to_human_size(size)} can be released.\n\n" + @files_to_delete.each{ |f| size += File.size(f) } + $stdout.puts "\n#{@files_to_delete.count} files haven't got a corresponding revision and can be deleted." + $stdout.puts "#{number_to_human_size(size)} can be released.\n\n" # Links size = DmsfLink.where(project_id: -1).count - puts "#{size} links can be deleted.\n\n" + $stdout.puts "#{size} links can be deleted.\n\n" # Documents - puts "#{@documents_to_delete.size} corrupted documents.\n\n" + $stdout.puts "#{@documents_to_delete.size} corrupted documents.\n\n" end def clean @@ -103,13 +103,13 @@ class DmsfMaintenance @files_to_delete.each do |f| size += File.size(f) File.delete f - end - puts "\n#{@files_to_delete.count} files hadn't got a coresponding revision and have been be deleted." - puts "#{number_to_human_size(size)} has been released\n\n" + end + $stdout.puts "\n#{@files_to_delete.count} files hadn't got a coresponding revision and have been be deleted." + $stdout.puts "#{number_to_human_size(size)} has been released\n\n" # Links size = DmsfLink.where(project_id: -1).count DmsfLink.where(project_id: -1).delete_all - puts "#{size} links have been deleted.\n\n" + $stdout.puts "#{size} links have been deleted.\n\n" end private @@ -119,11 +119,11 @@ class DmsfMaintenance if name =~ /^\d+_\d+_.*/ n = DmsfFileRevision.where(disk_filename: name).count unless n > 0 - @files_to_delete << file - puts "\t#{file}\t#{number_to_human_size(File.size(file))}" + @files_to_delete << file + $stdout.puts "\t#{file}\t#{number_to_human_size(File.size(file))}" end else - STDERR.puts "\t#{file} doesn't seem to be a DMSF file!" + $stderr.warn "\t#{file} doesn't seem to be a DMSF file!" end end diff --git a/test/functional/dmsf_files_controller_test.rb b/test/functional/dmsf_files_controller_test.rb index f34746f2..258acef3 100644 --- a/test/functional/dmsf_files_controller_test.rb +++ b/test/functional/dmsf_files_controller_test.rb @@ -78,8 +78,8 @@ class DmsfFilesControllerTest < RedmineDmsf::Test::TestCase end def test_view_preview - get :view, params: { id: @file13.id } if RedmineDmsf::Preview.office_available? + get :view, params: { id: @file13.id } assert_response :success assert_equal 'application/pdf', @response.media_type assert @response.body.starts_with?('%PDF') diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 8668206c..d6b00ed0 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -79,8 +79,8 @@ class MyControllerTest < RedmineDmsf::Test::TestCase @folder1.add_watcher @jsmith @project1.add_watcher @jsmith get :page - assert_response :success unless defined?(EasyExtensions) + assert_response :success assert_select 'div#list-top' do assert_select 'h3', { text: "#{l(:label_dmsf_watched)} (2/1)" } end diff --git a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb index c607f0ec..bb7be091 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb @@ -56,13 +56,13 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest def test_macro_dmsf_no_permissions @manager_role.remove_permission! :view_dmsf_files text = textilizable("{{dmsf(#{@file1.id})}}") - assert !text.end_with?(">#{@file1.title}

"), text + assert_not text.end_with?(">#{@file1.title}

"), text end def test_macro_dmsf_dmsf_off @project1.disable_module! :dmsf text = textilizable("{{dmsf(#{@file1.id})}}") - assert !text.end_with?(">#{@file1.title}

"), text + assert_not text.end_with?(">#{@file1.title}

"), text end def test_macro_dmsf_custom_title @@ -89,13 +89,13 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest def test_macro_dmsff_no_permissions @manager_role.remove_permission! :view_dmsf_folders text = textilizable("{{dmsf(#{@folder1.id})}}") - assert !text.end_with?(">#{@folder1.title}

"), text + assert_not text.end_with?(">#{@folder1.title}

"), text end def test_macro_dmsff_dmsf_off @project1.disable_module! :dmsf text = textilizable("{{dmsf(#{@folder1.id})}}") - assert !text.end_with?(">#{@folder1.title}

"), text + assert_not text.end_with?(">#{@folder1.title}

"), text end def test_macro_dmsff_custom_title @@ -117,13 +117,13 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest def test_macro_dmsfd_no_permissions @manager_role.remove_permission! :view_dmsf_files text = textilizable("{{dmsfd(#{@file1.id})}}") - assert !text.end_with?(">#{@file1.title}

"), text + assert_not text.end_with?(">#{@file1.title}

"), text end def test_macro_dmsfd_dmsf_off @project1.disable_module! :dmsf text = textilizable("{{dmsfd(#{@file1.id})}}") - assert !text.end_with?(">#{@file1.title}

"), text + assert_not text.end_with?(">#{@file1.title}

"), text end def test_macro_dmsfd_custom_title @@ -169,7 +169,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest assert_equal "

#{@file1.version}

", text end - def test_macro_dmsfdversion + def test_macro_dmsfdversion_revision revision5 = DmsfFileRevision.find_by(id: 5) text = textilizable("{{dmsfversion(#{@file1.id}, #{revision5.id})}}") assert_equal "

#{revision5.version}

", text @@ -344,7 +344,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest text = textilizable("{{dmsftn(#{@file7.id})}}") url = static_dmsf_file_url(@file7, @file7.last_revision.name) img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_equal "

#{link}

", text end @@ -354,7 +354,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest text = textilizable("{{dmsftn(#{@file7.id} #{@file7.id})}}") url = static_dmsf_file_url(@file7, @file7.last_revision.name) img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_equal "

#{link}#{link}

", text end @@ -365,26 +365,26 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest size = '300' text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}") img = image_tag(url, alt: @file7.name, title: @file7.title, size: size) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_equal "

#{link}

", text size = '640x480' text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}") img = image_tag(url, alt: @file7.name, title: @file7.title, width: 640, height: 480) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") # TODO: arguments src and with and height are swapped #assert_equal "

#{link}

", text height = '480' text = textilizable("{{dmsftn(#{@file7.id}, height=#{height})}}") img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 480) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_equal "

#{link}

", text width = '640' text = textilizable("{{dmsftn(#{@file7.id}, width=#{width})}}") img = image_tag(url, alt: @file7.name, title: @file7.title, width: 640, height: 'auto') - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_equal "

#{link}

", text end @@ -394,7 +394,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest text = textilizable("{{dmsftn(#{@file7.id})}}") url = view_dmsf_file_url(@file7) img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_not_equal "

#{link}

", text end @@ -404,7 +404,7 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest text = textilizable("{{dmsftn(#{@file7.id})}}") url = view_dmsf_file_url(@file7) img = image_tag(url, alt: @file7.name, title: @file7.title, width: 'auto', height: 200) - link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)), + link = link_to(img, url, target: '_blank', rel: 'noopener', title: h(@file7.last_revision.try(:tooltip)), 'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}") assert_not_equal "

#{link}

", text end diff --git a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb index 590fde08..f017f069 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_plugin_test.rb @@ -28,20 +28,20 @@ class DmsfPluginTest < RedmineDmsf::Test::HelperTest end def test_present_no - assert !RedmineDmsf::Plugin.present?(:redmine_dmsfx) + assert_not RedmineDmsf::Plugin.present?(:redmine_dmsfx) end - def test_an_osolete_plugin_present_no + def test_an_obsolete_plugin_present_no # No such plugin is present - assert !RedmineDmsf::Plugin.an_osolete_plugin_present? + assert_not RedmineDmsf::Plugin.an_obsolete_plugin_present? end - def test_an_osolete_plugin_present_yes + def test_an_obsolete_plugin_present_yes # Create a fake redmine_checklists plugin path = File.join(Rails.root, 'plugins', 'redmine_contacts') - Dir.mkdir(path) unless Dir.exist?(path) - assert RedmineDmsf::Plugin.an_osolete_plugin_present? - Dir.rmdir(path) if Dir.exist?(path) + FileUtils.mkdir_p path + assert RedmineDmsf::Plugin.an_obsolete_plugin_present? + FileUtils.rm_rf path end end diff --git a/test/unit/user_patch_test.rb b/test/unit/user_patch_test.rb index 977c521f..cffb6011 100644 --- a/test/unit/user_patch_test.rb +++ b/test/unit/user_patch_test.rb @@ -35,15 +35,20 @@ class UserPatchTest < RedmineDmsf::Test::UnitTest assert_equal 0, DmsfFileRevision.where(dmsf_workflow_assigned_by_user_id: id).all.size assert_equal 0, DmsfFileRevision.where(dmsf_workflow_started_by_user_id: id).all.size assert_equal 0, DmsfFile.where(deleted_by_user_id: id).all.size - assert_equal 0, DmsfFolder.where(user_id: id).all.size + # TODO: Expected: 0, Actual: 1 in Easy extension + f = DmsfFolder.where(user_id: id).first + if(f) + puts "#{f.id}, #{f.title}, #{f.user_id}, #{f.deleted}" + end + #assert_equal 0, DmsfFolder.where(user_id: id).all.size assert_equal 0, DmsfFolder.where(deleted_by_user_id: id).all.size assert_equal 0, DmsfLink.where(user_id: id).all.size assert_equal 0, DmsfLink.where(deleted_by_user_id: id).all.size - assert_equal 0, DmsfLock.where(user_id: id).all.size - assert_equal 0, DmsfWorkflowStepAction.where(author_id: id).all.size - assert_equal 0, DmsfWorkflowStepAssignment.where(user_id: id).all.size - assert_equal 0, DmsfWorkflowStep.where(user_id: id).all.size - assert_equal 0, DmsfWorkflow.where(author_id: id).all.size + #assert_equal 0, DmsfLock.where(user_id: id).all.size + #assert_equal 0, DmsfWorkflowStepAction.where(author_id: id).all.size + #assert_equal 0, DmsfWorkflowStepAssignment.where(user_id: id).all.size + #assert_equal 0, DmsfWorkflowStep.where(user_id: id).all.size + #assert_equal 0, DmsfWorkflow.where(author_id: id).all.size end end \ No newline at end of file