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

Feature 50849, reduce_by_writable_permissions shortcut for new models

Richard "Virgo" Richter234c0a750dc6
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index cd7f9cb728a..43ad792a4d8 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -242,6 +242,13 @@ class BaseContract < Disposable::Twin
def reduce_by_writable_permissions(attributes) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
attribute_permissions = collect_ancestor_attributes(:attribute_permissions)
+ # For new models we don't go to per-field checks if the user has any of the default permissions.
+ permissions = attribute_permissions[:default_permission]
+ if model.new_record? && permissions
+ return attributes if model.project.present? && permissions.any? { |perm| user.allowed_in_project?(perm, model.project) }
+ return attributes if model.project.blank? && permissions.any? { |perm| user.allowed_in_any_project?(perm) }
+ end
+
attributes.reject do |attribute|
canonical_attribute = attribute.delete_suffix('_id')
diff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rb
index 6a5d0b39d2d..88aa3f2d351 100644
--- a/app/services/work_packages/copy_service.rb
+++ b/app/services/work_packages/copy_service.rb
@@ -78,6 +78,8 @@ class WorkPackages::CopyService
.attributes
.slice(*writable_work_package_attributes(work_package))
.merge('parent_id' => work_package.parent_id,
+ # status would be omitted without :change_work_package_status, but we want it for copy
+ 'status_id' => work_package.status_id,
'custom_field_values' => work_package.custom_value_attributes)
.merge(overwritten_attributes)