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

add project phase dependent service for project copying

ulferts5ea62e818d21
diff --git a/app/services/projects/copy/phases_dependent_service.rb b/app/services/projects/copy/phases_dependent_service.rb
new file mode 100644
index 00000000000..3170f4a905d
--- /dev/null
+++ b/app/services/projects/copy/phases_dependent_service.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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
+ module Copy
+ class PhasesDependentService < Dependency
+ def self.human_name
+ I18n.t("label_life_cycle_step_plural")
+ end
+
+ def source_count
+ source.phases.count
+ end
+
+ def copy_dependency(_params)
+ # TODO: check if upsert can be used here
+ source.phases.each do |source_phase|
+ target.phases.create! **source_phase.attributes.slice(
+ "definition_id",
+ "start_date",
+ "finish_date",
+ "active",
+ "duration"
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rb
index 869b70e5e18..766533bbc65 100644
--- a/app/services/projects/copy_service.rb
+++ b/app/services/projects/copy_service.rb
@@ -43,6 +43,7 @@ module Projects
::Projects::Copy::QueriesDependentService,
::Projects::Copy::BoardsDependentService,
::Projects::Copy::OverviewDependentService,
+ ::Projects::Copy::PhasesDependentService,
::Projects::Copy::StoragesDependentService
]
end
diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb
index 5b1a01a4546..a127a2fd196 100644
--- a/spec/services/projects/copy_service_integration_spec.rb
+++ b/spec/services/projects/copy_service_integration_spec.rb
@@ -55,6 +55,12 @@ RSpec.describe(
shared_let(:source_child_wiki_page) { create(:wiki_page, wiki: source.wiki, parent: source_wiki_page) }
shared_let(:source_forum) { create(:forum, project: source) }
shared_let(:source_topic) { create(:message, forum: source_forum) }
+ shared_let(:source_project_phase) do
+ create(:project_phase,
+ project: source,
+ start_date: Time.zone.today,
+ finish_date: Time.zone.today + 5.days)
+ end
let(:current_user) do
create(:user,
@@ -104,6 +110,7 @@ RSpec.describe(
queries
boards
overview
+ phases
storages
storage_project_folders
file_links
@@ -267,6 +274,7 @@ RSpec.describe(
expect(project_copy.wiki.pages.root.text).to eq source_wiki_page.text
expect(project_copy.wiki.pages.leaves.first.text).to eq source_child_wiki_page.text
expect(project_copy.wiki.start_page).to eq "Wiki"
+ expect(project_copy.phases.count).to eq 1
# Cleared attributes
expect(project_copy).to be_persisted
@@ -381,7 +389,7 @@ RSpec.describe(
end
end
- context "with memeber" do
+ context "with member" do
let(:only_args) { %w[members] }
let!(:user) { create(:user) }
@@ -920,6 +928,29 @@ RSpec.describe(
end
end
end
+
+ context "with project phases" do
+ let(:only_args) { %i[phases] }
+
+ let!(:inactive_source_project_phase) do
+ create(:project_phase,
+ project: source,
+ active: false,
+ start_date: Time.zone.today + 10.days,
+ finish_date: Time.zone.today + 15.days)
+ end
+
+ it "copies the phases" do
+ expect(subject).to be_success
+ expect(project_copy.phases.count).to eq 2
+
+ [source_project_phase, inactive_source_project_phase].each do |source_phase|
+ copied_phase = project_copy.phases.find_by(definition_id: source_phase.definition_id)
+ expect(copied_phase.attributes.slice("definition_id", "active", "start_date", "finish_date", "duration"))
+ .to eql source_phase.attributes.slice("definition_id", "active", "start_date", "finish_date", "duration")
+ end
+ end
+ end
end
context "without anything selected" do
@@ -940,6 +971,7 @@ RSpec.describe(
expect(project_copy.wiki.wiki_menu_items.count).to eq 1
expect(project_copy.queries.count).to eq 0
expect(project_copy.versions.count).to eq 0
+ expect(project_copy.phases.count).to eq 0
# Cleared attributes
expect(project_copy).to be_persisted