After file convert view permissions missing #1454
This commit is contained in:
parent
2a2ef8ba60
commit
df7cf6e752
@ -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?
|
||||
|
||||
@ -71,10 +71,14 @@ class DmsfConvertDocuments
|
||||
next unless issue.attachments.any?
|
||||
|
||||
$stdout.puts "Processing: #{issue}"
|
||||
project.enable_module!('dmsf') unless @dry_run
|
||||
# <issue.id> - <issue.subject> 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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user