From b66e0df77ebb952f0d35f223c07d7e423fbeb5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 23 Dec 2019 14:41:03 +0100 Subject: [PATCH] #1064 Wrong sorting of Czech characters --- app/controllers/dmsf_controller.rb | 2 +- app/helpers/dmsf_helper.rb | 35 +++++-------------------- app/models/dmsf_folder.rb | 23 ++++++++++++++++ app/views/dmsf/_dmsf_rows.erb | 2 +- test/functional/dmsf_controller_test.rb | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index c859946b..1f7fe1b1 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -674,7 +674,7 @@ class DmsfController < ApplicationController end # Remove system folders you are not allowed to see because you are not allowed to see the issue or you are not # permitted to see system folders - @subfolders = DmsfHelper.visible_folders(@subfolders, @project) + @subfolders = DmsfFolder.visible_folders(@subfolders, @project) end @ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].presence || 100 diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index 4648c9ea..5509fbc1 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -98,32 +98,10 @@ module DmsfHelper ret end - def self.visible_folders(folders, project) - allowed = Setting.plugin_redmine_dmsf['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| - if folder.system - if allowed - issue_id = folder.title.to_i - if issue_id > 0 - issue = Issue.find_by(id: issue_id) - issue && !issue.visible?(User.current) - else - false - end - else - true - end - else - false - end - end - end - - def self.all_children_sorted(parent, pos, ident) + def all_children_sorted(parent, pos, ident) # Folders && files && links - nodes = visible_folders(parent.dmsf_folders.visible.to_a, parent.is_a?(Project) ? parent : parent.project) + parent.dmsf_links.visible + parent.dmsf_files.visible + nodes = DmsfFolder::visible_folders(parent.dmsf_folders.visible.to_a, parent.is_a?(Project) ? parent : parent.project) + + parent.dmsf_links.visible + parent.dmsf_files.visible # Alphabetical and type sort nodes.sort! do |x, y| if (x.is_a?(DmsfFolder) || (x.is_a?(DmsfLink) && x.is_folder?)) && @@ -133,7 +111,7 @@ module DmsfHelper (y.is_a?(DmsfFolder) || (y.is_a?(DmsfLink) && y.is_folder?)) 1 else - x.title.downcase <=> y.title.downcase + clear_title(x.title).downcase <=> clear_title(y.title).downcase end end # Calculate position @@ -154,7 +132,6 @@ module DmsfHelper end def self.dmsf_to_csv(parent, columns) - #Redmine::Export::CSV.generate do |csv| CSV.generate(:force_quotes => true, :encoding => 'UTF-8') do |csv| # Header csv << columns.map { |c| c.capitalize } @@ -194,8 +171,8 @@ module DmsfHelper # Replace specifics characters with their ASCII version + 'z' in order to fix the wrong ordering # e.g. 'č' -> 'cz' def clear_title(title) - title.gsub!(/[ěščřýáíéůúďťňĚŠČŘÝÁÍÉÚŮĎŤŇ]/) { |c| c + 'z' } - title.tr('ěščřýáíéůúďťňĚŠČŘÝÁÍÉÚŮĎŤŇ', 'escryaieuudtnESCRYAIEUUDTN') + str = title.gsub(/[ěščřýáíéůúďťňĚŠČŘÝÁÍÉÚŮĎŤŇ]/) { |c| c + 'z' } + str.tr('ěščřýáíéůúďťňĚŠČŘÝÁÍÉÚŮĎŤŇ', 'escryaieuudtnESCRYAIEUUDTN') end end diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index af1010ea..8250abe6 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -549,6 +549,29 @@ class DmsfFolder < ActiveRecord::Base end end + def self.visible_folders(folders, project) + allowed = Setting.plugin_redmine_dmsf['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| + if folder.system + if allowed + issue_id = folder.title.to_i + if issue_id > 0 + issue = Issue.find_by(id: issue_id) + issue && !issue.visible?(User.current) + else + false + end + else + true + end + else + false + end + end + end + private def self.directory_subtree(tree, folder, level, current_folder) diff --git a/app/views/dmsf/_dmsf_rows.erb b/app/views/dmsf/_dmsf_rows.erb index 9bdd2ca8..89ef2836 100644 --- a/app/views/dmsf/_dmsf_rows.erb +++ b/app/views/dmsf/_dmsf_rows.erb @@ -21,7 +21,7 @@ %> <% parent = @folder ? @folder : @project %> -<% DmsfHelper.all_children_sorted(parent, @pos, @idnt).each do |obj, position| %> +<% all_children_sorted(parent, @pos, @idnt).each do |obj, position| %> <% classes = "dmsf_tree idnt-#{@idnt} hascontextmenu" %> <% if obj.is_a?(DmsfFolder) && ((obj.dmsf_folders.visible.any?) || (obj.dmsf_files.visible.any?) || (obj.dmsf_links.visible.any?)) %> <% classes += ' idnt dmsf_collapsed dmsf-not-loaded' %> diff --git a/test/functional/dmsf_controller_test.rb b/test/functional/dmsf_controller_test.rb index 72b98619..24363eba 100644 --- a/test/functional/dmsf_controller_test.rb +++ b/test/functional/dmsf_controller_test.rb @@ -244,7 +244,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase @role.add_permission! :view_dmsf_folders get :show, :params => {id: @project.id, format: 'csv', :settings => { dmsf_columns: %w(id title) }} assert_response :success - assert_equal 'text/csv', @response.content_type + assert_equal 'text/csv; header=present', @response.content_type end def test_show_folder_doesnt_correspond_the_project