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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Hide action menus inside the relations tab when the according permissions are lacking
Henriette Darge6284d4b958b0
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erbindex 7c62f19b301..09d2f649427 100644--- a/app/components/work_package_relations_tab/index_component.html.erb+++ b/app/components/work_package_relations_tab/index_component.html.erb@@ -1,6 +1,6 @@<%= component_wrapper(tag: "turbo-frame") do %><%=- if should_render_add_relations?+ if should_render_create_button?flex_layout(justify_content: :space_between,align_items: :center,mb: 4,@@ -10,26 +10,30 @@t("#{I18N_NAMESPACE}.index.action_bar_title")endend+# Prevent the menu from overflowing on Safariaction_bar.with_column(style: "flex: 0 0 auto;") dorender(Primer::Alpha::ActionMenu.new(test_selector: NEW_RELATION_ACTION_MENU,- menu_id: NEW_RELATION_ACTION_MENU)) do |menu|+ menu_id: NEW_RELATION_ACTION_MENU)) do |menu|menu.with_show_button do |button|button.with_leading_visual_icon(icon: :"plus")button.with_trailing_action_icon(icon: :"triangle-down")t(:label_relation)end- Relation::TYPES.each do |relation_type, type_configuration_hash|- label_key = "#{I18N_NAMESPACE}.relations.#{type_configuration_hash[:name]}_singular"- menu.with_item(- label: t(label_key).capitalize,- href: new_relation_path(relation_type:),- test_selector: new_button_test_selector(relation_type:),- content_arguments: {- data: { turbo_stream: true }- }- ) do |item|- item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.#{relation_type}_description"))++ if should_render_add_relations?+ Relation::TYPES.each do |relation_type, type_configuration_hash|+ label_key = "#{I18N_NAMESPACE}.relations.#{type_configuration_hash[:name]}_singular"+ menu.with_item(+ label: t(label_key).capitalize,+ href: new_relation_path(relation_type:),+ test_selector: new_button_test_selector(relation_type:),+ content_arguments: {+ data: { turbo_stream: true }+ }+ ) do |item|+ item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.#{relation_type}_description"))+ endendend@@ -48,38 +52,9 @@endendend- elsif should_only_render_add_child?- flex_layout(justify_content: :space_between, align_items: :center, mb: 4) do |action_bar|- action_bar.with_column do- render(Primer::Beta::Text.new(color: :muted)) do- t("#{I18N_NAMESPACE}.index.action_bar_title")- end- end- # Prevent the menu from overflowing on Safari- action_bar.with_column(style: "flex: 0 0 auto;") do- render(Primer::Alpha::ActionMenu.new(test_selector: NEW_RELATION_ACTION_MENU,- menu_id: NEW_RELATION_ACTION_MENU)) do |menu|- menu.with_show_button do |button|- button.with_leading_visual_icon(icon: :"plus")- button.with_trailing_action_icon(icon: :"triangle-down")- t(:label_relation)- end-- menu.with_item(- label: t("#{I18N_NAMESPACE}.relations.label_child_singular").capitalize,- href: new_work_package_child_path(@work_package),- test_selector: new_button_test_selector(relation_type: :child),- content_arguments: {- data: { turbo_stream: true }- }- ) do |item|- item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.child_description"))- end- end- end- endend%>+<%=flex_layout(classes: "work-package-relations-tab--list-container", mb: 3) do |flex|if any_relations?diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rbindex 98431404fd1..ac30b1eae35 100644--- a/app/components/work_package_relations_tab/index_component.rb+++ b/app/components/work_package_relations_tab/index_component.rb@@ -34,8 +34,8 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponenthelpers.current_user.allowed_in_project?(:manage_work_package_relations, @work_package.project)end- def should_only_render_add_child?- should_render_add_child? && !should_render_add_relations?+ def should_render_create_button?+ should_render_add_child? || should_render_add_relations?enddef group_relations_by_directional_contextdiff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erbindex 2bfb5c94d18..5628eb711b7 100644--- a/app/components/work_package_relations_tab/relation_component.html.erb+++ b/app/components/work_package_relations_tab/relation_component.html.erb@@ -25,36 +25,38 @@ flex_layout(direction: :column, style: "gap: 0.25rem;") do |flex|target: "_blank")) { related_work_package.subject }end- subject_line_row.with_column do- render(Primer::Alpha::ActionMenu.new(test_selector: action_menu_test_selector)) do |menu|- menu.with_show_button(icon: "kebab-horizontal",- "aria-label": I18n.t(:label_agenda_item_actions),- scheme: :invisible,- ml: 2)- # Children have nothing to edit as it's not a relation.- unless parent_child_relationship?- menu.with_item(label: "Edit relation",- href: edit_path,- test_selector: edit_button_test_selector,- content_arguments: {- data: { turbo_stream: true }- }) do |item|- item.with_leading_visual_icon(icon: :pencil)+ if should_render_action_menu?+ subject_line_row.with_column do+ render(Primer::Alpha::ActionMenu.new(test_selector: action_menu_test_selector)) do |menu|+ menu.with_show_button(icon: "kebab-horizontal",+ "aria-label": I18n.t(:label_agenda_item_actions),+ scheme: :invisible,+ ml: 2)++ if should_render_edit_option?+ menu.with_item(label: "Edit relation",+ href: edit_path,+ test_selector: edit_button_test_selector,+ content_arguments: {+ data: { turbo_stream: true }+ }) do |item|+ item.with_leading_visual_icon(icon: :pencil)+ endend- end- menu.with_item(label: "Delete relation",- scheme: :danger,- href: destroy_path,- form_arguments: {- method: :delete,- data: {- confirm: t("text_are_you_sure"),- turbo_stream: true- }- },- test_selector: delete_button_test_selector) do |item|- item.with_leading_visual_icon(icon: :trash)+ menu.with_item(label: "Delete relation",+ scheme: :danger,+ href: destroy_path,+ form_arguments: {+ method: :delete,+ data: {+ confirm: t("text_are_you_sure"),+ turbo_stream: true+ }+ },+ test_selector: delete_button_test_selector) do |item|+ item.with_leading_visual_icon(icon: :trash)+ endendendenddiff --git a/app/components/work_package_relations_tab/relation_component.rb b/app/components/work_package_relations_tab/relation_component.rbindex 35590f7c6f2..efed86f893f 100644--- a/app/components/work_package_relations_tab/relation_component.rb+++ b/app/components/work_package_relations_tab/relation_component.rb@@ -26,6 +26,27 @@ class WorkPackageRelationsTab::RelationComponent < ApplicationComponentdef parent_child_relationship? = @child.present?+ def should_render_edit_option?+ # Children have nothing to edit as it's not a relation.+ !parent_child_relationship? && allowed_to_manage_relations?+ end++ def should_render_action_menu?+ if parent_child_relationship?+ allowed_to_manage_subtasks?+ else+ allowed_to_manage_relations?+ end+ end++ def allowed_to_manage_subtasks?+ helpers.current_user.allowed_in_project?(:manage_subtasks, @work_package.project)+ end++ def allowed_to_manage_relations?+ helpers.current_user.allowed_in_project?(:manage_work_package_relations, @work_package.project)+ end+def underlying_resource_id@underlying_resource_id ||= if parent_child_relationship?@child.id