From df7cf6e7520e1e759606fcfb3c092a6c66ed424b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 6 Jun 2023 12:13:40 +0200 Subject: [PATCH] After file convert view permissions missing #1454 --- app/models/dmsf_folder.rb | 5 ++--- lib/tasks/dmsf_convert_documents.rake | 24 ++++++++++++++---------- test/unit/dmsf_folder_test.rb | 12 ++++++++++++ test/unit_test.rb | 1 + 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index d9ee9da8..36d8bfce 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -78,8 +78,7 @@ class DmsfFolder < ApplicationRecord .joins("LEFT JOIN #{DmsfFolderPermission.table_name} dfp ON #{DmsfFolder.table_name}.id = dfp.dmsf_folder_id") .where(deleted: STATUS_DELETED).where(DmsfFolder.visible_condition).distinct } - scope :issystem, -> { where(system: true) } - scope :notsystem, -> { where(system: false) } + scope :issystem, -> { where(system: true, deleted: STATUS_ACTIVE) } acts_as_customizable acts_as_searchable columns: ["#{table_name}.title", "#{table_name}.description"], @@ -119,7 +118,7 @@ class DmsfFolder < ApplicationRecord # System folder? if folder&.system return false unless allow_system || User.current.allowed_to?(:display_system_folders, folder.project) - return false unless folder.issue&.visible?(User.current) + return false if folder.title != '.Issues' && !folder.issue&.visible?(User.current) end # Permissions to the folder? if folder.dmsf_folder_permissions.any? diff --git a/lib/tasks/dmsf_convert_documents.rake b/lib/tasks/dmsf_convert_documents.rake index 6a11ce40..d3ee927e 100644 --- a/lib/tasks/dmsf_convert_documents.rake +++ b/lib/tasks/dmsf_convert_documents.rake @@ -71,10 +71,14 @@ class DmsfConvertDocuments next unless issue.attachments.any? $stdout.puts "Processing: #{issue}" - project.enable_module!('dmsf') unless @dry_run # - folder - $stdout.puts "Creating #{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)} folder" - folder = issue.system_folder(create: true, prj_id: project.id) unless @dry_run + if @dry_run + $stdout.puts "Dry run #{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)} folder" + else + project.enable_module!('dmsf') + $stdout.puts "Creating #{issue.id} - #{DmsfFolder.get_valid_title(issue.subject)} folder" + folder = issue.system_folder(create: true, prj_id: project.id) + end files = [] attachments = [] issue.attachments.each do |attachment| @@ -82,7 +86,7 @@ class DmsfConvertDocuments create_document_from_attachment(project, folder, attachment, files, issue) attachments << attachment unless @fail end - next unless @dry_run + next if @dry_run attachments.each do |attachment| issue.init_journal User.anonymous @@ -181,19 +185,19 @@ class DmsfConvertDocuments revision.comment = "Converted from #{container.class.name}" revision.mime_type = attachment.content_type revision.disk_filename = revision.new_storage_filename - unless @dry_run - FileUtils.cp attachment.diskfile, revision.disk_file(search_if_not_exists: false) - revision.size = File.size(revision.disk_file(search_if_not_exists: false)) - end if @dry_run $stdout.puts "Dry run revision: #{revision.title}" warn(revision.errors.full_messages.to_sentence) if revision.invalid? else + FileUtils.cp attachment.diskfile, revision.disk_file(search_if_not_exists: false) + revision.size = File.size(revision.disk_file(search_if_not_exists: false)) revision.save! end files << file - attachment.destroy unless @dry_run - $stdout.puts "Created file: #{file.name}" unless @dry_run + unless @dry_run + attachment.destroy + $stdout.puts "Created file: #{file.name}" + end rescue StandardError => e warn "Creating file: #{attachment.filename} failed" warn e.message diff --git a/test/unit/dmsf_folder_test.rb b/test/unit/dmsf_folder_test.rb index a4e24cf4..67e1b7c4 100644 --- a/test/unit/dmsf_folder_test.rb +++ b/test/unit/dmsf_folder_test.rb @@ -55,6 +55,11 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest assert_not DmsfFolder.permissions?(@folder7) end + def test_permissions_to_system_folder + User.current = @jsmith + assert DmsfFolder.permissions?(@folder8) + end + def test_delete assert @folder6.delete(commit: false), @folder6.errors.full_messages.to_sentence assert @folder6.deleted?, "Folder #{@folder6} hasn't been deleted" @@ -269,4 +274,11 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest assert_equal invalid_string_sequence.scrub, @folder1.title assert_equal invalid_string_sequence.scrub, @folder1.description end + + def test_issystem + assert DmsfFolder.where(id: @folder8.id).issystem.exists? + @folder8.deleted = DmsfFolder::STATUS_DELETED + assert @folder8.save + assert_not DmsfFolder.where(id: @folder8.id).issystem.exists? + end end diff --git a/test/unit_test.rb b/test/unit_test.rb index 533cb6dd..9bd45d1b 100644 --- a/test/unit_test.rb +++ b/test/unit_test.rb @@ -57,6 +57,7 @@ module RedmineDmsf @folder2 = DmsfFolder.find 2 @folder6 = DmsfFolder.find 6 @folder7 = DmsfFolder.find 7 + @folder8 = DmsfFolder.find 8 Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.join('files', ['dmsf']) FileUtils.cp_r File.join(File.expand_path('../fixtures/files', __FILE__), '.'), DmsfFile.storage_path User.current = nil