OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Added copying of ::Storages::FileLinks to Projects::CopyService
Frank Bergmannb3c78ce1af6b
diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rbindex 08023d72436..2f9a5cae232 100644--- a/app/services/projects/copy_service.rb+++ b/app/services/projects/copy_service.rb@@ -43,7 +43,8 @@ module Projects::Projects::Copy::QueriesDependentService,::Projects::Copy::BoardsDependentService,::Projects::Copy::OverviewDependentService,- ::Projects::Copy::StoragesDependentService+ ::Projects::Copy::StoragesDependentService,+ ::Projects::Copy::FileLinksDependentService]enddiff --git a/modules/storages/app/services/projects/copy/file_links_dependent_service.rb b/modules/storages/app/services/projects/copy/file_links_dependent_service.rbindex 6c7cee3fd0f..976cb97412d 100644--- a/modules/storages/app/services/projects/copy/file_links_dependent_service.rb+++ b/modules/storages/app/services/projects/copy/file_links_dependent_service.rb@@ -33,7 +33,37 @@ module Projects::Copyenddef source_count- source.storages.count+ source.work_packages.joins(:file_links).count('file_links.id')+ end++ protected++ def copy_dependency(*)+ # If no work packages were copied, we cannot copy their attachments+ return unless state.work_package_id_lookup++ state.work_package_id_lookup.each do |old_wp_id, new_wp_id|+ create_work_package_file_links(old_wp_id, new_wp_id)+ end+ end++ def create_work_package_file_links(old_wp_id, new_wp_id)+ Storages::FileLink.where(container_id: old_wp_id).each do |file_link|+ create_file_link(file_link, new_wp_id)+ end+ end++ def create_file_link(file_link, new_wp_id)+ attributes = file_link+ .attributes.dup.except('id', 'container_id', 'created_at', 'updated_at')+ .merge('container_id' => new_wp_id)++ service_result = Storages::FileLinks::CreateService+ .new(user: User.current)+ .call(attributes)++ copied_file_link = service_result.result+ copied_file_link.saveendendenddiff --git a/modules/storages/app/services/projects/copy/storages_dependent_service.rb b/modules/storages/app/services/projects/copy/storages_dependent_service.rbindex b9ac5866458..66fbc2928f5 100644--- a/modules/storages/app/services/projects/copy/storages_dependent_service.rb+++ b/modules/storages/app/services/projects/copy/storages_dependent_service.rb@@ -46,15 +46,15 @@ module Projects::Copydef create_project_storage(project_storage)attributes = project_storage- .attributes.dup.except('id', 'project_id', 'created_at', 'updated_at')- .merge('project_id' => target.id) # Symbols don't work here+ .attributes.dup.except('id', 'project_id', 'created_at', 'updated_at')+ .merge('project_id' => target.id)service_result = ::Storages::ProjectStorages::CreateService.new(user: User.current).call(attributes)copied_storage = service_result.result- copied_storage.save # ToDo: is this necessary?+ copied_storage.saveendendenddiff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rbindex 3b98cf3db2c..ec10e2e36bc 100644--- a/spec/features/projects/copy_spec.rb+++ b/spec/features/projects/copy_spec.rb@@ -204,6 +204,10 @@ describe 'Projects copy',expect(copied_page.attachments.count).to eq 1expect(copied_page.attachments.first.filename).to eq 'attachment.pdf'+ # Expect ProjectStores and their FileLinks were copied+ expect(copied_project.projects_storages.count).to eq(project.projects_storages.count)+ expect(copied_project.work_packages[0].file_links.count).to eq(project.work_packages[0].file_links.count)+# custom field is copied over where the author is the current user# Using the db directly due to performance and claritycopied_work_packages = copied_project.work_packages