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

Allow writable attributes on the Projects::Create contract when the user has copy_projects permission

Dombi Attila4ba63551ebab
diff --git a/app/contracts/projects/create_contract.rb b/app/contracts/projects/create_contract.rb
index 1c65de38364..abed5b72947 100644
--- a/app/contracts/projects/create_contract.rb
+++ b/app/contracts/projects/create_contract.rb
@@ -50,7 +50,14 @@ module Projects
private
def allowed_to_write_custom_fields?
- user.admin? || user.allowed_globally?(:add_project) || user.allowed_in_any_project?(:edit_project_attributes)
+ # Writable attributes are already restricted based on their visibility in the
+ # ProjectCustomField.visible scope. Here it is enough to check whether the user
+ # has permission to copy_projects or edit_project_attributes in any project.
+ user.admin? ||
+ user.allowed_globally?(:add_project) ||
+ (model.parent && user.allowed_in_project?(:add_subprojects, model.parent)) ||
+ user.allowed_in_any_project?(:copy_projects) ||
+ user.allowed_in_any_project?(:edit_project_attributes)
end
def without_custom_fields(changes) = changes.grep_v(/^custom_field_/)