\Author should be kept when moving a folder #1484

This commit is contained in:
Karel Pičman 2023-10-24 09:58:37 +02:00
parent 90fb2a0989
commit fc141b7e3b
6 changed files with 48 additions and 0 deletions

View File

@ -258,6 +258,7 @@ class DmsfFile < ApplicationRecord
self.project = project
self.dmsf_folder = folder
new_revision = last_revision.clone
new_revision.user_id = last_revision.user_id
new_revision.workflow = nil
new_revision.dmsf_workflow_id = nil
new_revision.dmsf_workflow_assigned_by_user_id = nil

View File

@ -109,6 +109,7 @@ class DmsfLink < ApplicationRecord
link.external_url = external_url
link.project_id = project.id
link.dmsf_folder_id = folder ? folder.id : nil
link.user = User.current
link.save!
link
end

View File

@ -24,6 +24,7 @@ file_link:
deleted_by_user_id: NULL
created_at: <%= DateTime.current %>
updated_at: <%= DateTime.current %>
user_id: 1
folder_link2:
id: 3

View File

@ -290,4 +290,19 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
assert_not_empty(@file13.pdf_preview) if RedmineDmsf::Preview.office_available?
assert_empty @file1.pdf_preview
end
def test_move_to_author
assert_equal @admin.id, @file1.last_revision.user_id
User.current = @jsmith
assert @file1.move_to(@folder1.project, @folder1)
assert_equal @admin.id, @file1.last_revision.user_id, "Author mustn't be updated when moving"
end
def test_copy_to_author
assert_equal @admin.id, @file1.last_revision.user_id
User.current = @jsmith
f = @file1.copy_to(@folder1.project, @folder1)
assert f
assert_equal @jsmith.id, f.last_revision.user_id, 'Author must be updated when copying'
end
end

View File

@ -252,6 +252,21 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
assert DmsfFolder.find_by(project_id: @project2.id, title: @folder1.title)
end
def test_move_to_author
assert_equal @admin.id, @folder1.user_id
User.current = @jsmith
assert @folder1.move_to(@folder6.project, @folder6)
assert_equal @admin.id, @folder1.user_id, "Author mustn't be updated when moving"
end
def test_copy_to_author
assert_equal @admin.id, @folder1.user_id
User.current = @jsmith
f = @folder1.copy_to(@folder6.project, @folder6)
assert f
assert_equal @jsmith.id, f.user_id, 'Author must be updated when copying'
end
def test_valid_parent
@folder2.dmsf_folder = @folder1
assert @folder2.save

View File

@ -184,6 +184,21 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest
assert_equal folder_link_copy.dmsf_folder_id, @folder2.id
end
def test_move_to_author
assert_equal @admin.id, @file_link.user_id
User.current = @jsmith
assert @file_link.move_to(@project1, @folder1)
assert_equal @admin.id, @file_link.user_id, "Author mustn't be updated when moving"
end
def test_copy_to_author
assert_equal @admin.id, @file_link.user_id
User.current = @jsmith
l = @file_link.copy_to(@project1, @folder1)
assert l
assert_equal @jsmith.id, l.user_id, 'Author must be updated when copying'
end
def test_delete_file_link
assert @file_link.delete(commit: false), @file_link.errors.full_messages.to_sentence
assert @file_link.deleted?, "File link hasn't been deleted"