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

Add tests for limited permissions on relations tab

Henriette Darge93c9fbe1c648
diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
index 693d5e86b47..8b4cd4dee87 100644
--- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb
+++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
@@ -230,4 +230,67 @@ RSpec.describe "Primerized work package relations tab",
tabs.expect_counter("relations", 5)
end
end
+
+ describe "with limited permissions" do
+ let(:no_permissions_role) { create(:project_role, permissions: %i[view_work_packages]) }
+ let(:user_without_permissions) do
+ create(:user,
+ member_with_roles: { project => no_permissions_role })
+ end
+ let(:current_user) { user_without_permissions }
+
+ it "does not show options to add or edit relations" do
+ scroll_to_element relations_panel
+
+ tabs.expect_counter("relations", 4)
+
+ relations_tab.expect_no_add_relation_button
+ relations_tab.expect_no_relatable_action_menu(wp_related)
+ relations_tab.expect_no_relatable_action_menu(child_wp)
+ end
+
+ context "with manage_relations permissions" do
+ let(:no_permissions_role) do
+ create(:project_role, permissions: %i(view_work_packages edit_work_packages manage_work_package_relations))
+ end
+
+ it "does not show the option to delete the child" do
+ scroll_to_element relations_panel
+
+ tabs.expect_counter("relations", 4)
+
+ # The menu is shown as the user can add a relation
+ relations_tab.expect_add_relation_button
+
+ # The relation can be edited and deleted
+ relations_tab.expect_relatable_action_menu(wp_related)
+ relations_tab.relatable_action_menu(wp_related).click
+ relations_tab.expect_relatable_delete_button(wp_related)
+
+ # The child cannot be changed
+ relations_tab.expect_no_relatable_action_menu(child_wp)
+ end
+ end
+
+ context "with manage_subtasks permissions" do
+ let(:no_permissions_role) { create(:project_role, permissions: %i(view_work_packages edit_work_packages manage_subtasks)) }
+
+ it "does not show the option to edit the relation but only the child" do
+ scroll_to_element relations_panel
+
+ tabs.expect_counter("relations", 4)
+
+ # The menu is shown as the user can add a child
+ relations_tab.expect_add_relation_button
+
+ # The relation cannot be edited
+ relations_tab.expect_no_relatable_action_menu(wp_related)
+
+ # The child can be removed
+ relations_tab.expect_relatable_action_menu(child_wp)
+ relations_tab.relatable_action_menu(child_wp).click
+ relations_tab.expect_relatable_delete_button(child_wp)
+ end
+ end
+ end
end
diff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rb
index 9e5510797a4..5fff5daf77e 100644
--- a/spec/support/components/work_packages/relations.rb
+++ b/spec/support/components/work_packages/relations.rb
@@ -54,6 +54,10 @@ module Components
end
end
+ def expect_add_relation_button
+ expect(page).to have_test_selector("new-relation-action-menu")
+ end
+
def expect_no_add_relation_button
expect(page).not_to have_test_selector("new-relation-action-menu")
end
@@ -97,11 +101,31 @@ module Components
page.find_test_selector("op-relation-row-#{actual_relatable.id}-action-menu")
end
+ def expect_relatable_action_menu(relatable)
+ actual_relatable = find_relatable(relatable)
+ expect(page).to have_test_selector("op-relation-row-#{actual_relatable.id}-action-menu")
+ end
+
+ def expect_no_relatable_action_menu(relatable)
+ actual_relatable = find_relatable(relatable)
+ expect(page).not_to have_test_selector("op-relation-row-#{actual_relatable.id}-action-menu")
+ end
+
def relatable_delete_button(relatable)
actual_relatable = find_relatable(relatable)
page.find_test_selector("op-relation-row-#{actual_relatable.id}-delete-button")
end
+ def expect_relatable_delete_button(relatable)
+ actual_relatable = find_relatable(relatable)
+ expect(page).to have_test_selector("op-relation-row-#{actual_relatable.id}-delete-button")
+ end
+
+ def expect_no_relatable_delete_button(relatable)
+ actual_relatable = find_relatable(relatable)
+ expect(page).not_to have_test_selector("op-relation-row-#{actual_relatable.id}-delete-button")
+ end
+
def add_relation(type:, relatable:, description: nil)
i18n_namespace = "#{WorkPackageRelationsTab::IndexComponent::I18N_NAMESPACE}.relations"
# Open create form
@@ -225,8 +249,8 @@ module Components
def expect_parent(work_package)
expect(page).to have_test_selector "op-wp-breadcrumb-parent",
- text: work_package.subject,
- wait: 10
+ text: work_package.subject,
+ wait: 10
end
def expect_no_parent
@@ -244,7 +268,7 @@ module Components
SeleniumHubWaiter.wait
page.find_test_selector("op-wp-inline-create-reference",
- text: I18n.t("js.relation_buttons.add_existing_child")).click
+ text: I18n.t("js.relation_buttons.add_existing_child")).click
# Security check to be sure that the autocompleter has finished loading
page.find ".wp-relations--children .ng-input input"