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

check if the user has can set the parent for the selected WP or not before creating a child

Behrokh Satarnejad54e0600f0a1b
diff --git a/app/controllers/work_package_children_relations_controller.rb b/app/controllers/work_package_children_relations_controller.rb
index 4feff06746b..d5c3cc45b02 100644
--- a/app/controllers/work_package_children_relations_controller.rb
+++ b/app/controllers/work_package_children_relations_controller.rb
@@ -78,8 +78,18 @@ class WorkPackageChildrenRelationsController < ApplicationController
end
def set_relation(child:, parent:)
- WorkPackages::UpdateService.new(user: current_user, model: child)
- .call(parent:)
+ if allowed_to_set_parent?(child)
+ WorkPackages::UpdateService.new(user: current_user, model: child)
+ .call(parent:)
+ else
+ child.errors.add(:base, I18n.t(:"activerecord.errors.models.work_package.lack_of_permission"))
+ ServiceResult.failure(result: child)
+ end
+ end
+
+ def allowed_to_set_parent?(child)
+ contract = WorkPackages::UpdateContract.new(child, current_user)
+ contract.can_set_parent?
end
def respond_with_relations_tab_update(service_result, **)
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 5e490f1b8ae..e570b097cc4 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1410,6 +1410,7 @@ en:
must_be_empty_when_work_is_empty_and_percent_complete_is_100p: >-
must be empty when Work is empty and % Complete is 100%.
readonly_status: "The work package is in a readonly status so its attributes cannot be changed."
+ lack_of_permission: "Cannot add child because work package is read-only."
type:
attributes:
attribute_groups: