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 permissions to render CRUD actions on tab

Aaron Contreras495a68f54dc2
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erb
index 2ebe50fd0ac..9af2c747848 100644
--- a/app/components/work_package_relations_tab/index_component.html.erb
+++ b/app/components/work_package_relations_tab/index_component.html.erb
@@ -1,43 +1,76 @@
<%= component_wrapper(tag: "turbo-frame") do %>
- <%=
- 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")
+ <%=
+ if should_render_add_relations?
+ 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
+ action_bar.with_column 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
+ 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"))
+ end
+ end
+
+ if should_render_add_child?
+ 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
end
end
- action_bar.with_column 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)
+ 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
- Relation::TYPES.each do |relation_type, type_configuration_hash|
- label_key = "#{I18N_NAMESPACE}.relations.#{type_configuration_hash[:name]}_singular"
+ end
+ action_bar.with_column 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(label_key).capitalize,
- href: new_relation_path(relation_type:),
- test_selector: new_button_test_selector(relation_type:),
+ 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.#{relation_type}_description"))
+ item.with_description.with_content(t("#{I18N_NAMESPACE}.relations.child_description"))
end
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
end
diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb
index ecbadf5823c..98431404fd1 100644
--- a/app/components/work_package_relations_tab/index_component.rb
+++ b/app/components/work_package_relations_tab/index_component.rb
@@ -26,6 +26,18 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
private
+ def should_render_add_child?
+ helpers.current_user.allowed_in_project?(:manage_subtasks, @work_package.project)
+ end
+
+ def should_render_add_relations?
+ helpers.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?
+ end
+
def group_relations_by_directional_context
relations.group_by do |relation|
relation.relation_type_for(work_package)