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

[#57817] replaced record destroy with persistence service

Eric Schubert63fbdbdb049c
diff --git a/app/components/admin/custom_fields/hierarchy/item_component.html.erb b/app/components/admin/custom_fields/hierarchy/item_component.html.erb
index 5ff3bf6cf6a..a1f98921953 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.html.erb
@@ -50,10 +50,9 @@ See COPYRIGHT and LICENSE files for more details.
menu.with_show_button(icon: "kebab-horizontal",
scheme: :invisible,
"aria-label": I18n.t("custom_fields.admin.items.actions"))
- delete_item(menu)
+ deletion_action_item(menu)
end
end
end
end
-
%>
diff --git a/app/components/admin/custom_fields/hierarchy/item_component.rb b/app/components/admin/custom_fields/hierarchy/item_component.rb
index c9f06cb11dd..2a22a4b7d53 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.rb
@@ -45,7 +45,7 @@ module Admin
"(#{@hierarchy_item.short})"
end
- def delete_item(menu)
+ def deletion_action_item(menu)
menu.with_item(label: I18n.t(:button_delete),
scheme: :danger,
tag: :a,
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index b9dbaf383d3..542b2c80563 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -66,9 +66,14 @@ module Admin
end
def destroy
- # TODO: user persistence service
- @hierarchy_item.destroy
- update_via_turbo_stream(component: ItemsComponent.new(custom_field: @custom_field))
+ ::CustomFields::Hierarchy::HierarchicalItemService
+ .new
+ .delete_branch(item: @hierarchy_item)
+ .either(
+ ->(_) { update_via_turbo_stream(component: ItemsComponent.new(custom_field: @custom_field)) },
+ ->(errors) { update_flash_message_via_turbo_stream(message: errors.full_messages, scheme: :danger) }
+ )
+
respond_with_turbo_streams
end