Skip to content

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

introduce NoCreate dependent jobs

ulferts480ce720a34e
diff --git a/app/services/projects/copy/no_create.rb b/app/services/projects/copy/no_create.rb
new file mode 100644
index 00000000000..fa3c398d614
--- /dev/null
+++ b/app/services/projects/copy/no_create.rb
@@ -0,0 +1,42 @@
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 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 Projects::Copy
+ # Can be included in case the dependent service needs to be listed in the copy_dependency section for:
+ # * Being an option in the UI
+ # * Calculating the count
+ # but does not really need to do anything beyond that.
+ #
+ # This is currently employed to turn the attachment dependent services into NoCreate services as attachment
+ # handling has been moved into the create services e.g. of WorkPackage and WikiPage.
+ module NoCreate
+ protected
+
+ def copy_dependency(params:)
+ # Not actually doing any copying.
+ end
+ end
+end
diff --git a/app/services/projects/copy/work_package_attachments_dependent_service.rb b/app/services/projects/copy/work_package_attachments_dependent_service.rb
index 15379744eea..050195106b5 100644
--- a/app/services/projects/copy/work_package_attachments_dependent_service.rb
+++ b/app/services/projects/copy/work_package_attachments_dependent_service.rb
@@ -1,6 +1,6 @@
-#-- copyright
+#--copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
+# Copyright (C) 2010-2022 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.
@@ -28,7 +28,7 @@
module Projects::Copy
class WorkPackageAttachmentsDependentService < Dependency
- include ::Copy::Concerns::CopyAttachments
+ include ::Projects::Copy::NoCreate
def self.human_name
I18n.t(:label_work_package_attachments)
@@ -37,16 +37,5 @@ module Projects::Copy
def source_count
source.work_packages.joins(:attachments).count('attachments.id')
end
-
- protected
-
- def copy_dependency(params:)
- # 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|
- copy_attachments('WorkPackage', from_id: old_wp_id, to_id: new_wp_id)
- end
- end
end
end
diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rb
index c9df1355e9a..050fde94330 100644
--- a/app/services/projects/copy_service.rb
+++ b/app/services/projects/copy_service.rb
@@ -36,6 +36,7 @@ module Projects
::Projects::Copy::VersionsDependentService,
::Projects::Copy::CategoriesDependentService,
::Projects::Copy::WorkPackagesDependentService,
+ ::Projects::Copy::WorkPackageAttachmentsDependentService,
::Projects::Copy::WikiDependentService,
::Projects::Copy::WikiPageAttachmentsDependentService,
::Projects::Copy::ForumsDependentService,
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index ec10e2e36bc..51dadf85ae7 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -105,7 +105,8 @@ describe 'Projects copy',
category:,
version:,
description: 'Some description',
- custom_field_values: { wp_custom_field.id => 'Some wp cf text' })
+ custom_field_values: { wp_custom_field.id => 'Some wp cf text' },
+ attachments: [build(:attachment, filename: 'work_package_attachment.pdf')])
end
let!(:wiki) { project.wiki }
@@ -113,7 +114,7 @@ describe 'Projects copy',
create :wiki_page_with_content,
title: 'Attached',
wiki:,
- attachments: [build(:attachment, container: nil, filename: 'attachment.pdf')]
+ attachments: [build(:attachment, container: nil, filename: 'wiki_page_attachment.pdf')]
end
let(:parent_field) { ::FormFields::SelectFormField.new :parent }
@@ -201,8 +202,8 @@ describe 'Projects copy',
expect(copied_project.wiki.pages.count).to eq(project.wiki.pages.count)
copied_page = copied_project.wiki.find_page 'Attached'
expect(copied_page).not_to be_nil
- expect(copied_page.attachments.count).to eq 1
- expect(copied_page.attachments.first.filename).to eq 'attachment.pdf'
+ expect(copied_page.attachments.map(&:filename))
+ .to eq ['wiki_page_attachment.pdf']
# Expect ProjectStores and their FileLinks were copied
expect(copied_project.projects_storages.count).to eq(project.projects_storages.count)
@@ -237,6 +238,8 @@ describe 'Projects copy',
.to eql copied_project.versions.find_by(name: version.name)
expect(copied_work_package.custom_value_attributes)
.to eql(wp_custom_field.id => 'Some wp cf text')
+ expect(copied_work_package.attachments.map(&:filename))
+ .to eq ['work_package_attachment.pdf']
expect(ActionMailer::Base.deliveries.count)
.to eql(1)