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
extract attachment dependent job behaviour into module
ulfertsc449fc12569e
diff --git a/app/services/projects/copy/attachment_copier.rb b/app/services/projects/copy/attachment_copier.rbnew file mode 100644index 00000000000..8a87008d73d--- /dev/null+++ b/app/services/projects/copy/attachment_copier.rb@@ -0,0 +1,45 @@+# 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 AttachmentCopier+ protected++ def copy_attachments?+ attachment_dependent_service = self.class.name.gsub('sDependentService', 'AttachmentsDependentService').constantize++ (params.dig(:params, :only) || [])+ .any? { |k| k.to_s == attachment_dependent_service.identifier }+ end+ end+enddiff --git a/app/services/projects/copy/no_create.rb b/app/services/projects/copy/no_copier.rbsimilarity index 98%rename from app/services/projects/copy/no_create.rbrename to app/services/projects/copy/no_copier.rbindex fa3c398d614..be64abd95aa 100644--- a/app/services/projects/copy/no_create.rb+++ b/app/services/projects/copy/no_copier.rb@@ -32,7 +32,7 @@ module Projects::Copy## 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+ module NoCopierprotecteddef copy_dependency(params:)diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rbindex 88c1f336e00..d14947eaa03 100644--- a/app/services/projects/copy/wiki_dependent_service.rb+++ b/app/services/projects/copy/wiki_dependent_service.rb@@ -28,6 +28,8 @@module Projects::Copyclass WikiDependentService < Dependency+ include AttachmentCopier+def self.human_nameI18n.t(:label_wiki_page_plural)end@@ -126,9 +128,5 @@ module Projects::Copyendendend-- def copy_attachments?- (params.dig(:params, :only) || []).any? { |k| k.to_sym == :wiki_page_attachments }- endendenddiff --git a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb b/app/services/projects/copy/wiki_page_attachments_dependent_service.rbindex 8429b203a55..2d416806887 100644--- a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb+++ b/app/services/projects/copy/wiki_page_attachments_dependent_service.rb@@ -28,7 +28,7 @@module Projects::Copyclass WikiPageAttachmentsDependentService < Dependency- include ::Projects::Copy::NoCreate+ include ::Projects::Copy::NoCopierdef self.human_nameI18n.t(:label_wiki_page_attachments)diff --git a/app/services/projects/copy/work_package_attachments_dependent_service.rb b/app/services/projects/copy/work_package_attachments_dependent_service.rbindex 050195106b5..bc3b27e0918 100644--- a/app/services/projects/copy/work_package_attachments_dependent_service.rb+++ b/app/services/projects/copy/work_package_attachments_dependent_service.rb@@ -28,7 +28,7 @@module Projects::Copyclass WorkPackageAttachmentsDependentService < Dependency- include ::Projects::Copy::NoCreate+ include ::Projects::Copy::NoCopierdef self.human_nameI18n.t(:label_work_package_attachments)diff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rbindex 7b0187b8b49..b786aa4b07c 100644--- a/app/services/projects/copy/work_packages_dependent_service.rb+++ b/app/services/projects/copy/work_packages_dependent_service.rb@@ -28,6 +28,8 @@module Projects::Copyclass WorkPackagesDependentService < Dependency+ include AttachmentCopier+def self.human_nameI18n.t(:label_work_package_plural)end@@ -175,9 +177,5 @@ module Projects::Copynew_wp_id]endend-- def copy_attachments?- (params.dig(:params, :only) || []).any? { |k| k.to_sym == :work_package_attachments }- endendend