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")
|
.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
|
.where(deleted: STATUS_DELETED).where(DmsfFolder.visible_condition).distinct
|
||||||
}
|
}
|
||||||
scope :issystem, -> { where(system: true) }
|
scope :issystem, -> { where(system: true, deleted: STATUS_ACTIVE) }
|
||||||
scope :notsystem, -> { where(system: false) }
|
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
acts_as_searchable columns: ["#{table_name}.title", "#{table_name}.description"],
|
acts_as_searchable columns: ["#{table_name}.title", "#{table_name}.description"],
|
||||||
@ -119,7 +118,7 @@ class DmsfFolder < ApplicationRecord
|
|||||||
# System folder?
|
# System folder?
|
||||||
if folder&.system
|
if folder&.system
|
||||||
return false unless allow_system || User.current.allowed_to?(:display_system_folders, folder.project)
|
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
|
end
|
||||||
# Permissions to the folder?
|
# Permissions to the folder?
|
||||||
if folder.dmsf_folder_permissions.any?
|
if folder.dmsf_folder_permissions.any?
|
||||||
|
|||||||
@ -71,10 +71,14 @@ class DmsfConvertDocuments
|
|||||||
next unless issue.attachments.any?
|
next unless issue.attachments.any?
|
||||||
|
|
||||||
$stdout.puts "Processing: #{issue}"
|
$stdout.puts "Processing: #{issue}"
|
||||||
project.enable_module!('dmsf') unless @dry_run
|
|
||||||
# <issue.id> - <issue.subject> folder
|
# <issue.id> - <issue.subject> folder
|
||||||
|
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"
|
$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
|
folder = issue.system_folder(create: true, prj_id: project.id)
|
||||||
|
end
|
||||||
files = []
|
files = []
|
||||||
attachments = []
|
attachments = []
|
||||||
issue.attachments.each do |attachment|
|
issue.attachments.each do |attachment|
|
||||||
@ -82,7 +86,7 @@ class DmsfConvertDocuments
|
|||||||
create_document_from_attachment(project, folder, attachment, files, issue)
|
create_document_from_attachment(project, folder, attachment, files, issue)
|
||||||
attachments << attachment unless @fail
|
attachments << attachment unless @fail
|
||||||
end
|
end
|
||||||
next unless @dry_run
|
next if @dry_run
|
||||||
|
|
||||||
attachments.each do |attachment|
|
attachments.each do |attachment|
|
||||||
issue.init_journal User.anonymous
|
issue.init_journal User.anonymous
|
||||||
@ -181,19 +185,19 @@ class DmsfConvertDocuments
|
|||||||
revision.comment = "Converted from #{container.class.name}"
|
revision.comment = "Converted from #{container.class.name}"
|
||||||
revision.mime_type = attachment.content_type
|
revision.mime_type = attachment.content_type
|
||||||
revision.disk_filename = revision.new_storage_filename
|
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
|
if @dry_run
|
||||||
$stdout.puts "Dry run revision: #{revision.title}"
|
$stdout.puts "Dry run revision: #{revision.title}"
|
||||||
warn(revision.errors.full_messages.to_sentence) if revision.invalid?
|
warn(revision.errors.full_messages.to_sentence) if revision.invalid?
|
||||||
else
|
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!
|
revision.save!
|
||||||
end
|
end
|
||||||
files << file
|
files << file
|
||||||
attachment.destroy unless @dry_run
|
unless @dry_run
|
||||||
$stdout.puts "Created file: #{file.name}" unless @dry_run
|
attachment.destroy
|
||||||
|
$stdout.puts "Created file: #{file.name}"
|
||||||
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
warn "Creating file: #{attachment.filename} failed"
|
warn "Creating file: #{attachment.filename} failed"
|
||||||
warn e.message
|
warn e.message
|
||||||
|
|||||||
@ -55,6 +55,11 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_not DmsfFolder.permissions?(@folder7)
|
assert_not DmsfFolder.permissions?(@folder7)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_permissions_to_system_folder
|
||||||
|
User.current = @jsmith
|
||||||
|
assert DmsfFolder.permissions?(@folder8)
|
||||||
|
end
|
||||||
|
|
||||||
def test_delete
|
def test_delete
|
||||||
assert @folder6.delete(commit: false), @folder6.errors.full_messages.to_sentence
|
assert @folder6.delete(commit: false), @folder6.errors.full_messages.to_sentence
|
||||||
assert @folder6.deleted?, "Folder #{@folder6} hasn't been deleted"
|
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.title
|
||||||
assert_equal invalid_string_sequence.scrub, @folder1.description
|
assert_equal invalid_string_sequence.scrub, @folder1.description
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@ -57,6 +57,7 @@ module RedmineDmsf
|
|||||||
@folder2 = DmsfFolder.find 2
|
@folder2 = DmsfFolder.find 2
|
||||||
@folder6 = DmsfFolder.find 6
|
@folder6 = DmsfFolder.find 6
|
||||||
@folder7 = DmsfFolder.find 7
|
@folder7 = DmsfFolder.find 7
|
||||||
|
@folder8 = DmsfFolder.find 8
|
||||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.join('files', ['dmsf'])
|
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
|
FileUtils.cp_r File.join(File.expand_path('../fixtures/files', __FILE__), '.'), DmsfFile.storage_path
|
||||||
User.current = nil
|
User.current = nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user