Document Location - Folder Structure #543
This commit is contained in:
parent
659427b81d
commit
1a14bae5ce
@ -254,34 +254,20 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
errors[:base] << l(:error_file_is_locked)
|
errors[:base] << l(:error_file_is_locked)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
project = container.is_a?(Project) ? container : container.project
|
|
||||||
# If the target project differs from the source project we must physically move the disk files
|
|
||||||
if self.project != project
|
|
||||||
self.dmsf_file_revisions.all.each do |rev|
|
|
||||||
if File.exist? rev.disk_file(self.project)
|
|
||||||
FileUtils.mv rev.disk_file(self.project), rev.disk_file(project)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Must invalidate source parent folder cache before moving
|
# Must invalidate source parent folder cache before moving
|
||||||
RedmineDmsf::Webdav::Cache.invalidate_item(propfind_cache_key)
|
RedmineDmsf::Webdav::Cache.invalidate_item(propfind_cache_key)
|
||||||
|
|
||||||
self.container_type = self.container_type
|
self.container_type = self.container_type
|
||||||
self.container_id = container.id
|
self.container_id = container.id
|
||||||
self.dmsf_folder = folder
|
self.dmsf_folder = folder
|
||||||
new_revision = self.last_revision.clone
|
new_revision = self.last_revision.clone
|
||||||
new_revision.dmsf_file = self
|
new_revision.dmsf_file = self
|
||||||
|
project = container.is_a?(Project) ? container : container.project
|
||||||
new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}")
|
new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}")
|
||||||
new_revision.custom_values = []
|
new_revision.custom_values = []
|
||||||
|
|
||||||
self.last_revision.custom_values.each do |cv|
|
self.last_revision.custom_values.each do |cv|
|
||||||
new_revision.custom_values << CustomValue.new({:custom_field => cv.custom_field, :value => cv.value})
|
new_revision.custom_values << CustomValue.new({:custom_field => cv.custom_field, :value => cv.value})
|
||||||
end
|
end
|
||||||
|
|
||||||
self.set_last_revision(new_revision)
|
self.set_last_revision(new_revision)
|
||||||
|
|
||||||
self.save && new_revision.save
|
self.save && new_revision.save
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -290,13 +276,6 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy_to_filename(container, folder=nil, filename)
|
def copy_to_filename(container, folder=nil, filename)
|
||||||
project = container.is_a?(Project) ? container : container.project
|
|
||||||
# If the target project differs from the source project we must physically move the disk files
|
|
||||||
if (self.project != project) && self.last_revision
|
|
||||||
if File.exist? self.last_revision.disk_file(self.project)
|
|
||||||
FileUtils.cp self.last_revision.disk_file(self.project), self.last_revision.disk_file(project)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
file = DmsfFile.new
|
file = DmsfFile.new
|
||||||
file.dmsf_folder = folder
|
file.dmsf_folder = folder
|
||||||
file.container_type = self.container_type
|
file.container_type = self.container_type
|
||||||
@ -306,6 +285,11 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
if file.save && self.last_revision
|
if file.save && self.last_revision
|
||||||
new_revision = self.last_revision.clone
|
new_revision = self.last_revision.clone
|
||||||
new_revision.dmsf_file = file
|
new_revision.dmsf_file = file
|
||||||
|
new_revision.disk_filename = new_revision.new_storage_filename
|
||||||
|
if File.exist? self.last_revision.disk_file
|
||||||
|
FileUtils.cp self.last_revision.disk_file, new_revision.disk_file
|
||||||
|
end
|
||||||
|
project = container.is_a?(Project) ? container : container.project
|
||||||
new_revision.comment = l(:comment_copied_from, :source => "#{project.identifier}: #{self.dmsf_path_str}")
|
new_revision.comment = l(:comment_copied_from, :source => "#{project.identifier}: #{self.dmsf_path_str}")
|
||||||
new_revision.custom_values = []
|
new_revision.custom_values = []
|
||||||
self.last_revision.custom_values.each do |cv|
|
self.last_revision.custom_values.each do |cv|
|
||||||
|
|||||||
@ -132,22 +132,28 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
"#{self.major_version}.#{self.minor_version}"
|
"#{self.major_version}.#{self.minor_version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def storage_base_path(project = nil)
|
def storage_base_path
|
||||||
project = self.dmsf_file.project unless project
|
time = self.created_at || DateTime.now
|
||||||
path = DmsfFile.storage_path.dup
|
path = time.strftime('%Y/%m')
|
||||||
if self.dmsf_file && project
|
"#{DmsfFile.storage_path}/#{path}"
|
||||||
project_base = project.identifier.gsub(/[^\w\.\-]/,'_')
|
|
||||||
path << "/p_#{project_base}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def disk_file(project = nil)
|
def disk_file
|
||||||
project = self.dmsf_file.project unless project
|
path = self.storage_base_path
|
||||||
path = storage_base_path(project)
|
|
||||||
FileUtils.mkdir_p(path) unless File.exist?(path)
|
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||||
"#{path}/#{self.disk_filename}"
|
"#{path}/#{self.disk_filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_storage_filename
|
||||||
|
raise DmsfAccessError, 'File id is not set' unless self.dmsf_file.id
|
||||||
|
filename = DmsfHelper.sanitize_filename(self.name)
|
||||||
|
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
||||||
|
while File.exist?(File.join(storage_base_path, "#{timestamp}_#{self.dmsf_file.id}_#{filename}"))
|
||||||
|
timestamp.succ!
|
||||||
|
end
|
||||||
|
"#{timestamp}_#{self.dmsf_file.id}_#{filename}"
|
||||||
|
end
|
||||||
|
|
||||||
def detect_content_type
|
def detect_content_type
|
||||||
content_type = self.mime_type
|
content_type = self.mime_type
|
||||||
content_type = Redmine::MimeType.of(self.disk_filename) if content_type.blank?
|
content_type = Redmine::MimeType.of(self.disk_filename) if content_type.blank?
|
||||||
@ -228,16 +234,6 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_storage_filename
|
|
||||||
raise DmsfAccessError, 'File id is not set' unless self.dmsf_file.id
|
|
||||||
filename = DmsfHelper.sanitize_filename(self.name)
|
|
||||||
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
|
|
||||||
while File.exist?(File.join(storage_base_path, "#{timestamp}_#{self.dmsf_file.id}_#{filename}"))
|
|
||||||
timestamp.succ!
|
|
||||||
end
|
|
||||||
"#{timestamp}_#{self.dmsf_file.id}_#{filename}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def copy_file_content(open_file)
|
def copy_file_content(open_file)
|
||||||
File.open(self.disk_file, 'wb') do |f|
|
File.open(self.disk_file, 'wb') do |f|
|
||||||
while (buffer = open_file.read(8192))
|
while (buffer = open_file.read(8192))
|
||||||
|
|||||||
@ -297,6 +297,10 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
l.copy_to project, new_folder
|
l.copy_to project, new_folder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.dmsf_folder_permissions.each do |p|
|
||||||
|
p.copy_to new_folder
|
||||||
|
end
|
||||||
|
|
||||||
return new_folder
|
return new_folder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,4 +25,14 @@ class DmsfFolderPermission < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :users, -> { where(:object_type => User.model_name.to_s) }
|
scope :users, -> { where(:object_type => User.model_name.to_s) }
|
||||||
scope :roles, -> { where(:object_type => Role.model_name.to_s) }
|
scope :roles, -> { where(:object_type => Role.model_name.to_s) }
|
||||||
|
|
||||||
|
def copy_to(folder)
|
||||||
|
permission = DmsfFolderPermission.new
|
||||||
|
permission.dmsf_folder_id = folder.id
|
||||||
|
permission.object_id = self.object_id
|
||||||
|
permission.object_type = self.object_type
|
||||||
|
permission.save
|
||||||
|
permission
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -110,14 +110,14 @@ class DmsfLink < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def copy_to(project, folder)
|
def copy_to(project, folder)
|
||||||
link = DmsfLink.new(
|
link = DmsfLink.new
|
||||||
:target_project_id => self.target_project_id,
|
link.target_project_id = self.target_project_id
|
||||||
:target_id => self.target_id,
|
link.target_id = self.target_id
|
||||||
:target_type => self.target_type,
|
link.target_type = self.target_type
|
||||||
:name => self.name,
|
link.name = self.name
|
||||||
:external_url => self.external_url,
|
link.external_url = self.external_url
|
||||||
:project_id => project.id,
|
link.project_id = project.id
|
||||||
:dmsf_folder_id => folder ? folder.id : nil)
|
link.dmsf_folder_id = folder ? folder.id : nil
|
||||||
link.save
|
link.save
|
||||||
link
|
link
|
||||||
end
|
end
|
||||||
|
|||||||
120
db/migrate/20170418104901_migrate_documents.rb
Normal file
120
db/migrate/20170418104901_migrate_documents.rb
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine plugin for Document Management System "Features"
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
class MigrateDocuments < ActiveRecord::Migration
|
||||||
|
|
||||||
|
def up
|
||||||
|
# Migrate all documents from dmsf/p_{project identifier} to dmsf/{year}/{month}
|
||||||
|
DmsfFileRevision.find_each do |dmsf_file_revision|
|
||||||
|
if dmsf_file_revision.dmsf_file
|
||||||
|
if dmsf_file_revision.dmsf_file.project
|
||||||
|
origin = self.disk_file(dmsf_file_revision)
|
||||||
|
if origin
|
||||||
|
if File.exist?(origin)
|
||||||
|
target = dmsf_file_revision.disk_file
|
||||||
|
if target
|
||||||
|
unless File.exist?(target)
|
||||||
|
begin
|
||||||
|
FileUtils.mv origin, target, :verbose => true
|
||||||
|
folder = self.storage_base_path(dmsf_file_revision)
|
||||||
|
Dir.rmdir(folder) if (folder && (Dir.entries(folder).size == 2))
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: #{e.message}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: Target '#{target}' exists"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: target = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: Origin '#{origin}' doesn't exist"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: disk_file = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFile ID #{dmsf_file_revision.dmsf_file.id}: project = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: dmsf_file = nil"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
# Migrate all documents from dmsf/p_{project identifier} to dmsf/{year}/{month}
|
||||||
|
DmsfFileRevision.find_each do |dmsf_file_revision|
|
||||||
|
if dmsf_file_revision.dmsf_file
|
||||||
|
if dmsf_file_revision.dmsf_file.project
|
||||||
|
origin = dmsf_file_revision.disk_file
|
||||||
|
if origin
|
||||||
|
if File.exist?(origin)
|
||||||
|
target = self.disk_file(dmsf_file_revision)
|
||||||
|
if target
|
||||||
|
unless File.exist?(target)
|
||||||
|
begin
|
||||||
|
FileUtils.mv origin, target, :verbose => true
|
||||||
|
folder = dmsf_file_revision.storage_base_path
|
||||||
|
Dir.rmdir(folder) if (folder && (Dir.entries(folder).size == 2))
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: #{e.message}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: Target '#{target}' exists"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: target = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: Origin '#{origin}' doesn't exist"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: disk_file = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFile ID #{dmsf_file_revision.dmsf_file.id}: project = nil"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Rails.logger.error "DmsfFileRevisions ID #{dmsf_file_revision.id}: dmsf_file = nil"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def storage_base_path(dmsf_file_revision)
|
||||||
|
if dmsf_file_revision.dmsf_file
|
||||||
|
if dmsf_file_revision.dmsf_file.project
|
||||||
|
project_base = dmsf_file_revision.dmsf_file.project.identifier.gsub(/[^\w\.\-]/,'_')
|
||||||
|
return "#{DmsfFile.storage_path}/p_#{project_base}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def disk_file(dmsf_file_revision)
|
||||||
|
path = storage_base_path(dmsf_file_revision)
|
||||||
|
if path
|
||||||
|
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||||
|
return "#{path}/#{dmsf_file_revision.disk_filename}"
|
||||||
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
9
test/fixtures/dmsf_file_revisions.yml
vendored
9
test/fixtures/dmsf_file_revisions.yml
vendored
@ -18,6 +18,7 @@ dmsf_file_revisions_001:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: 1
|
dmsf_workflow_assigned_by: 1
|
||||||
dmsf_workflow_started_by: 1
|
dmsf_workflow_started_by: 1
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
#revision for file on non-enabled project
|
#revision for file on non-enabled project
|
||||||
dmsf_file_revisions_002:
|
dmsf_file_revisions_002:
|
||||||
@ -39,6 +40,7 @@ dmsf_file_revisions_002:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: 1
|
dmsf_workflow_assigned_by: 1
|
||||||
dmsf_workflow_started_by: 1
|
dmsf_workflow_started_by: 1
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
#revision for deleted file on dmsf-enabled project
|
#revision for deleted file on dmsf-enabled project
|
||||||
dmsf_file_revisions_003:
|
dmsf_file_revisions_003:
|
||||||
@ -60,6 +62,7 @@ dmsf_file_revisions_003:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: 1
|
dmsf_workflow_assigned_by: 1
|
||||||
dmsf_workflow_started_by: 1
|
dmsf_workflow_started_by: 1
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_004:
|
dmsf_file_revisions_004:
|
||||||
id: 4
|
id: 4
|
||||||
@ -80,6 +83,7 @@ dmsf_file_revisions_004:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_005:
|
dmsf_file_revisions_005:
|
||||||
id: 5
|
id: 5
|
||||||
@ -100,6 +104,7 @@ dmsf_file_revisions_005:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_006:
|
dmsf_file_revisions_006:
|
||||||
id: 6
|
id: 6
|
||||||
@ -120,6 +125,7 @@ dmsf_file_revisions_006:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_007:
|
dmsf_file_revisions_007:
|
||||||
id: 7
|
id: 7
|
||||||
@ -140,6 +146,7 @@ dmsf_file_revisions_007:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_008:
|
dmsf_file_revisions_008:
|
||||||
id: 8
|
id: 8
|
||||||
@ -160,6 +167,7 @@ dmsf_file_revisions_008:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
dmsf_file_revisions_009:
|
dmsf_file_revisions_009:
|
||||||
id: 9
|
id: 9
|
||||||
@ -180,5 +188,6 @@ dmsf_file_revisions_009:
|
|||||||
user_id: 1
|
user_id: 1
|
||||||
dmsf_workflow_assigned_by: NULL
|
dmsf_workflow_assigned_by: NULL
|
||||||
dmsf_workflow_started_by: NULL
|
dmsf_workflow_started_by: NULL
|
||||||
|
created_at: 2017-04-18 14:52:27 +02:00
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
1
test/fixtures/files/p_onlinestore/test.txt
vendored
1
test/fixtures/files/p_onlinestore/test.txt
vendored
@ -1 +0,0 @@
|
|||||||
1234
|
|
||||||
@ -21,7 +21,17 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
require File.expand_path('../../test_helper', __FILE__)
|
||||||
|
|
||||||
class DmsfFolderPermissionTest < RedmineDmsf::Test::UnitTest
|
class DmsfFolderPermissionTest < RedmineDmsf::Test::UnitTest
|
||||||
fixtures :dmsf_folder_permissions
|
fixtures :dmsf_folder_permissions, :dmsf_folders
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@folder1 = DmsfFolder.find 1
|
||||||
|
@permission1 = DmsfFolderPermission.find 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_truth
|
||||||
|
assert_kind_of DmsfFolder, @folder1
|
||||||
|
assert_kind_of DmsfFolderPermission, @permission1
|
||||||
|
end
|
||||||
|
|
||||||
def test_scope
|
def test_scope
|
||||||
assert_equal 2, DmsfFolderPermission.count
|
assert_equal 2, DmsfFolderPermission.count
|
||||||
@ -35,4 +45,12 @@ class DmsfFolderPermissionTest < RedmineDmsf::Test::UnitTest
|
|||||||
assert_equal 1, DmsfFolderPermission.roles.count
|
assert_equal 1, DmsfFolderPermission.roles.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_copy_to
|
||||||
|
permission = @permission1.copy_to(@folder1)
|
||||||
|
assert permission
|
||||||
|
assert_equal @folder1.id, permission.dmsf_folder_id
|
||||||
|
assert_equal @permission1.object_id, permission.object_id
|
||||||
|
assert_equal @permission1.object_type, permission.object_type
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,6 +34,10 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
|
|||||||
@folder7 = DmsfFolder.find_by_id 7
|
@folder7 = DmsfFolder.find_by_id 7
|
||||||
@manager = User.find_by_id 2
|
@manager = User.find_by_id 2
|
||||||
@developer = User.find_by_id 3
|
@developer = User.find_by_id 3
|
||||||
|
manager_role = Role.find 1
|
||||||
|
manager_role.add_permission! :view_dmsf_folders
|
||||||
|
developer_role = Role.find 2
|
||||||
|
developer_role.add_permission! :view_dmsf_folders
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truth
|
def test_truth
|
||||||
@ -49,13 +53,14 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
|
|||||||
def test_visiblity
|
def test_visiblity
|
||||||
# The role has got permissions
|
# The role has got permissions
|
||||||
User.current = @manager
|
User.current = @manager
|
||||||
assert_equal 6, DmsfFolder.visible.where(:project_id => 1).count
|
assert_equal 5, DmsfFolder.where(:project_id => 1).count
|
||||||
|
assert_equal 5, DmsfFolder.visible.where(:project_id => 1).count
|
||||||
# The user has got permissions
|
# The user has got permissions
|
||||||
User.current = @developer
|
User.current = @developer
|
||||||
assert_equal 6, DmsfFolder.visible.where(:project_id => 1).count
|
assert_equal 5, DmsfFolder.visible.where(:project_id => 1).count
|
||||||
# Hasn't got permissions for @folder7
|
# Hasn't got permissions for @folder7
|
||||||
@folder7.dmsf_folder_permissions.where(:object_type => 'User').delete_all
|
@folder7.dmsf_folder_permissions.where(:object_type => 'User').delete_all
|
||||||
assert_equal 5, DmsfFolder.visible.where(:project_id => 1).count
|
assert_equal 4, DmsfFolder.visible.where(:project_id => 1).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_permissions
|
def test_permissions
|
||||||
|
|||||||
@ -27,6 +27,8 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
|||||||
@project1 = Project.find_by_id 1
|
@project1 = Project.find_by_id 1
|
||||||
@project2 = Project.find_by_id 2
|
@project2 = Project.find_by_id 2
|
||||||
@project3 = Project.find_by_id 3
|
@project3 = Project.find_by_id 3
|
||||||
|
admin = User.find 1
|
||||||
|
User.current = admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_truth
|
def test_truth
|
||||||
@ -66,7 +68,7 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
|||||||
def test_dmsf_count
|
def test_dmsf_count
|
||||||
hash = @project1.dmsf_count
|
hash = @project1.dmsf_count
|
||||||
assert_equal 7, hash[:files]
|
assert_equal 7, hash[:files]
|
||||||
assert_equal 7, hash[:folders]
|
assert_equal 6, hash[:folders]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_copy_approval_workflows
|
def test_copy_approval_workflows
|
||||||
@ -78,18 +80,18 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
|||||||
|
|
||||||
def test_copy_dmsf
|
def test_copy_dmsf
|
||||||
assert_equal 3, @project1.dmsf_files.visible.count
|
assert_equal 3, @project1.dmsf_files.visible.count
|
||||||
assert_equal 4, @project1.dmsf_folders.visible.count
|
assert_equal 3, @project1.dmsf_folders.visible.count
|
||||||
assert_equal 1, @project1.file_links.visible.count
|
assert_equal 1, @project1.file_links.visible.count
|
||||||
assert_equal 1, @project1.folder_links.visible.count
|
assert_equal 1, @project1.folder_links.visible.count
|
||||||
assert_equal 1, @project1.url_links.visible.count
|
assert_equal 1, @project1.url_links.visible.count
|
||||||
assert_equal 0, @project3.dmsf_files.visible.count
|
assert_equal 0, @project3.dmsf_files.visible.count
|
||||||
assert_equal 0, @project3.dmsf_folders.visible.count
|
assert_equal 0, @project3.dmsf_folders.count
|
||||||
assert_equal 0, @project3.file_links.visible.count
|
assert_equal 0, @project3.file_links.visible.count
|
||||||
assert_equal 0, @project3.folder_links.visible.count
|
assert_equal 0, @project3.folder_links.visible.count
|
||||||
assert_equal 0, @project3.url_links.visible.count
|
assert_equal 0, @project3.url_links.visible.count
|
||||||
@project3.copy_dmsf(@project1)
|
@project3.copy_dmsf(@project1)
|
||||||
assert_equal 3, @project3.dmsf_files.visible.count
|
assert_equal 3, @project3.dmsf_files.visible.count
|
||||||
assert_equal 3, @project3.dmsf_folders.visible.count # Folder if 7 is not visible due to folder permissions
|
assert_equal 3, @project3.dmsf_folders.count
|
||||||
assert_equal 1, @project3.file_links.visible.count
|
assert_equal 1, @project3.file_links.visible.count
|
||||||
assert_equal 1, @project3.folder_links.visible.count
|
assert_equal 1, @project3.folder_links.visible.count
|
||||||
assert_equal 1, @project3.url_links.visible.count
|
assert_equal 1, @project3.url_links.visible.count
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user