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 for add_work_packages permission to add new children

Oliver Günther931028453571
diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb
index e4a813ed0cf..811a6efb8bc 100644
--- a/app/components/work_package_relations_tab/index_component.rb
+++ b/app/components/work_package_relations_tab/index_component.rb
@@ -108,14 +108,16 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
def render_child_items(menu) # rubocop:disable Metrics/AbcSize
return unless should_render_add_child?
- menu.with_item(
- label: t("work_package_relations_tab.relations.new_child"),
- href: new_project_work_packages_dialog_path(work_package.project, parent_id: work_package.id),
- content_arguments: {
- data: { turbo_stream: true }
- }
- ) do |item|
- item.with_description.with_content(t("work_package_relations_tab.relations.new_child_text"))
+ if helpers.current_user.allowed_in_project?(:add_work_packages, @work_package.project)
+ menu.with_item(
+ label: t("work_package_relations_tab.relations.new_child"),
+ href: new_project_work_packages_dialog_path(work_package.project, parent_id: work_package.id),
+ content_arguments: {
+ data: { turbo_stream: true }
+ }
+ ) do |item|
+ item.with_description.with_content(t("work_package_relations_tab.relations.new_child_text"))
+ end
end
menu.with_item(
diff --git a/spec/features/work_packages/tabs/relations_children_spec.rb b/spec/features/work_packages/tabs/relations_children_spec.rb
index 5882b07476b..e2b3ea74398 100644
--- a/spec/features/work_packages/tabs/relations_children_spec.rb
+++ b/spec/features/work_packages/tabs/relations_children_spec.rb
@@ -35,6 +35,9 @@ RSpec.describe "Relations children tab", :js, :with_cuprite do
it "can add a new child" do
wp_page.visit_tab!("relations")
relations_tab.expect_add_relation_button
+ relations_tab.expect_new_relation_type("New child")
+ relations_tab.expect_new_relation_type("Existing child")
+
relations_tab.select_relation_type "New child"
create_dialog.select_type "Task"
@@ -79,4 +82,17 @@ RSpec.describe "Relations children tab", :js, :with_cuprite do
relations_tab.expect_no_add_relation_button
end
end
+
+ context "with permission to manage_subtasks, but not add_work_packages" do
+ let!(:user) do
+ create(:user, member_with_permissions: { project => %i[view_work_packages manage_subtasks] })
+ end
+
+ it "does not show the action" do
+ wp_page.visit_tab!("relations")
+ relations_tab.expect_add_relation_button
+ relations_tab.expect_new_relation_type("Existing child")
+ relations_tab.expect_no_new_relation_type("New child")
+ end
+ end
end