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

Retain the public attribute AFTER the SetAttributeservice

Oliver Günther582e9dce07d8
diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rb
index 1888c2e3020..0f821d7b295 100644
--- a/app/services/projects/copy_service.rb
+++ b/app/services/projects/copy_service.rb
@@ -61,6 +61,7 @@ module Projects
target_project_params = params[:target_project_params].with_indifferent_access
cleanup_target_project_params(source, target, target_project_params)
+ cleanup_target_project_attributes(source, target, target_project_params)
# Assign additional params from user
call = Projects::SetAttributesService
@@ -70,11 +71,19 @@ module Projects
contract_options: { copied_from: source })
.call(target_project_params)
- cleanup_target_project_attributes(source, target, target_project_params)
+ # Retain values after the set attributes service
+ retain_attributes(source, target, target_project_params)
call
end
+ def retain_attributes(source, target, target_project_params)
+ # Ensure we keep the public value of the source project
+ # which might get overridden by the SetAttributesService
+ # unless the user provided a different value
+ target.public = source.public unless target_project_params.key?(:public)
+ end
+
def cleanup_target_project_params(_source, _target, target_project_params)
if (parent_id = target_project_params[:parent_id]) && (parent = Project.find_by(id: parent_id))
target_project_params.delete(:parent_id) unless user.allowed_to?(:add_subprojects, parent)
@@ -82,10 +91,6 @@ module Projects
end
def cleanup_target_project_attributes(source, target, target_project_params)
- # Ensure we keep the public value of the source project
- # which might get overridden by the SetAttributesService
- target.public = source.public unless target_project_params.key?(:public)
-
if target.parent
target.parent = nil unless user.allowed_to?(:add_subprojects, target.parent)
end