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

Ensure we set templated to false when copying

Oliver Günther6c6a05c7845c
diff --git a/app/services/projects/instantiate_template_service.rb b/app/services/projects/instantiate_template_service.rb
index b8301e3597c..298bb848a29 100644
--- a/app/services/projects/instantiate_template_service.rb
+++ b/app/services/projects/instantiate_template_service.rb
@@ -44,7 +44,7 @@ module Projects
::CopyProjectJob.perform_later(
user_id: user.id,
source_project_id: template_id,
- target_project_params: params,
+ target_project_params: project_params(params),
# Copy all associations
associations_to_copy: nil,
# Send mails for now until we send our own mails
@@ -59,5 +59,16 @@ module Projects
def persist(call)
call
end
+
+ private
+
+ ##
+ # Modifies params to ensure we unset
+ # the templated option
+ def project_params(params)
+ params.to_h.merge(
+ templated: false
+ )
+ end
end
end
diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb
index 5dfde5f6fb9..2825269743b 100644
--- a/app/workers/copy_project_job.rb
+++ b/app/workers/copy_project_job.rb
@@ -91,7 +91,8 @@ class CopyProjectJob < ApplicationJob
if service_call.success? && target_project.save
errors = copy_project_associations(target_project)
else
- errors = service_call.errors.merge(target_project.errors).full_messages
+ service_call.errors.merge!(target_project.errors, nil)
+ errors = service_call.errors.full_messages
target_project = nil
logger.error("Copying project fails with validation errors: #{errors.join("\n")}")
end
diff --git a/spec/features/projects/project_status_administration_spec.rb b/spec/features/projects/project_status_administration_spec.rb
index c7c2e727666..e27be61170c 100644
--- a/spec/features/projects/project_status_administration_spec.rb
+++ b/spec/features/projects/project_status_administration_spec.rb
@@ -45,8 +45,8 @@ describe 'Projects status administration', type: :feature, js: true do
.and_return(r.id.to_s)
end
end
- let(:create_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(6)') }
- let(:edit_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(7)') }
+ let(:create_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(5)') }
+ let(:edit_status_description) { Components::WysiwygEditor.new('.form--field:nth-of-type(6)') }
before do
login_as current_user
diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb
index a820a453e72..0ebf13f4de9 100644
--- a/spec/features/projects/template_spec.rb
+++ b/spec/features/projects/template_spec.rb
@@ -94,6 +94,7 @@ describe 'Project templates', type: :feature, js: true do
project = Project.find_by identifier: 'foo'
expect(project.name).to eq 'Foo bar'
+ expect(project).not_to be_templated
expect(project.users.first).to eq current_user
expect(project.enabled_module_names.sort).to eq(template.enabled_module_names.sort)