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
Skip the job if no File link or project folder copy is requested
Marcello Rocha984ff7f57f91
diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rbindex 90baf52fd2d..cbd8098ae8e 100644--- a/app/services/projects/copy_service.rb+++ b/app/services/projects/copy_service.rb@@ -47,6 +47,18 @@ module Projects]end+ # Project Folders and File Links aren't dependent services anymore,+ # so we need to amend the services for the form Representer+ def self.copyable_dependencies+ super + [{ identifier: "storage_project_folders",+ name_source: -> { I18n.t(:label_project_storage_project_folder) },+ count_source: ->(source, _) { source.storages.count } },++ { identifier: "file_links",+ name_source: -> { I18n.t("projects.copy.work_package_file_links") },+ count_source: ->(source, _) { source.work_packages.joins(:file_links).count("file_links.id") } }]+ end+protected##diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rbindex f5a1e0586cc..3b285cf312d 100644--- a/app/workers/copy_project_job.rb+++ b/app/workers/copy_project_job.rb@@ -146,17 +146,20 @@ class CopyProjectJob < ApplicationJobcopy_service = ::Projects::CopyService.new(source: source_project, user:)result = copy_service.call({ target_project_params:, send_notifications:, only: Array(associations_to_copy) })- enqueue_copy_project_folder_jobs(copy_service.state.copied_project_storages, copy_service.state.work_package_id_lookup)+ enqueue_copy_project_folder_jobs(copy_service.state.copied_project_storages,+ copy_service.state.work_package_id_lookup,+ associations_to_copy)resultend- def enqueue_copy_project_folder_jobs(copied_storages, work_packages_map)+ def enqueue_copy_project_folder_jobs(copied_storages, work_packages_map, only)+ return unless only.intersect?("file_links", "storage_project_folders").any?+Array(copied_storages).each do |storage_pair|batch.enqueue do- Storages::CopyProjectFoldersJob.perform_later(source: storage_pair[:source],- target: storage_pair[:target],- work_packages_map:)+ Storages::CopyProjectFoldersJob+ .perform_later(source: storage_pair[:source], target: storage_pair[:target], work_packages_map:)endendenddiff --git a/modules/storages/app/contracts/storages/file_links/copy_contract.rb b/modules/storages/app/contracts/storages/file_links/copy_contract.rbnew file mode 100644index 00000000000..402d243130f--- /dev/null+++ b/modules/storages/app/contracts/storages/file_links/copy_contract.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Storages+ module FileLinks+ class CopyContract < CreateContract+ private++ def validate_user_allowed_to_manage = true+ end+ end+enddiff --git a/modules/storages/app/contracts/storages/project_storages/copy_contract.rb b/modules/storages/app/contracts/storages/project_storages/copy_contract.rbnew file mode 100644index 00000000000..ecffc0f6f6a--- /dev/null+++ b/modules/storages/app/contracts/storages/project_storages/copy_contract.rb@@ -0,0 +1,37 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Storages+ module ProjectStorages+ class CopyContract < CreateContract+ private++ def validate_user_allowed_to_manage = true+ end+ end+enddiff --git a/modules/storages/app/services/projects/copy/storages_dependent_service.rb b/modules/storages/app/services/projects/copy/storages_dependent_service.rbindex 66b1de6ca06..552aa166ccf 100644--- a/modules/storages/app/services/projects/copy/storages_dependent_service.rb+++ b/modules/storages/app/services/projects/copy/storages_dependent_service.rb@@ -47,7 +47,7 @@ module Projects::Copystate.copied_project_storages = source.project_storages.each_with_object([]) do |source_project_storage, array|project_storage_copy =::Storages::ProjectStorages::CreateService- .new(user: User.current)+ .new(user: User.current, contract_class: ::Storages::ProjectStorages::CopyContract).call(storage_id: source_project_storage.storage_id,project_id: target.id,project_folder_mode: "inactive")diff --git a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb b/modules/storages/app/services/storages/file_links/copy_file_links_service.rbindex 8f80da2c7b2..e282fe9ea35 100644--- a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb+++ b/modules/storages/app/services/storages/file_links/copy_file_links_service.rb@@ -74,7 +74,8 @@ module Storages"origin_id" => location_map[source_link.origin_id])- CreateService.new(user: @user).call(attributes).on_failure { |failed| log_errors(failed) }+ CreateService.new(user: @user, contract_class: CopyContract)+ .call(attributes).on_failure { |failed| log_errors(failed) }endend@@ -108,7 +109,8 @@ module Storagesattributes["creator_id"] = @user.idattributes["container_id"] = @work_packages_map[source_file_link.container_id]- FileLinks::CreateService.new(user: @user).call(attributes).on_failure { |failed| log_errors(failed) }+ FileLinks::CreateService.new(user: @user, contract_class: CopyContract)+ .call(attributes).on_failure { |failed| log_errors(failed) }endend