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

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.rb
new file mode 100644
index 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
+end
diff --git a/app/services/projects/copy/no_create.rb b/app/services/projects/copy/no_copier.rb
similarity index 98%
rename from app/services/projects/copy/no_create.rb
rename to app/services/projects/copy/no_copier.rb
index 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 NoCopier
protected
def copy_dependency(params:)
diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rb
index 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::Copy
class WikiDependentService < Dependency
+ include AttachmentCopier
+
def self.human_name
I18n.t(:label_wiki_page_plural)
end
@@ -126,9 +128,5 @@ module Projects::Copy
end
end
end
-
- def copy_attachments?
- (params.dig(:params, :only) || []).any? { |k| k.to_sym == :wiki_page_attachments }
- end
end
end
diff --git a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb b/app/services/projects/copy/wiki_page_attachments_dependent_service.rb
index 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::Copy
class WikiPageAttachmentsDependentService < Dependency
- include ::Projects::Copy::NoCreate
+ include ::Projects::Copy::NoCopier
def self.human_name
I18n.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.rb
index 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::Copy
class WorkPackageAttachmentsDependentService < Dependency
- include ::Projects::Copy::NoCreate
+ include ::Projects::Copy::NoCopier
def self.human_name
I18n.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.rb
index 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::Copy
class WorkPackagesDependentService < Dependency
+ include AttachmentCopier
+
def self.human_name
I18n.t(:label_work_package_plural)
end
@@ -175,9 +177,5 @@ module Projects::Copy
new_wp_id]
end
end
-
- def copy_attachments?
- (params.dig(:params, :only) || []).any? { |k| k.to_sym == :work_package_attachments }
- end
end
end