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

Merge branch 'dev' into merge-release/15.2-20250110091205

Christophe Bliardd45c960df4fc
diff --cc app/controllers/work_package_children_relations_controller.rb
index 539961766bb,1b54ea0c28f..6fecc9b2a93
--- a/app/controllers/work_package_children_relations_controller.rb
+++ b/app/controllers/work_package_children_relations_controller.rb
@@@ -43,43 -46,42 +43,41 @@@ class WorkPackageChildrenRelationsContr
end
def create
- target_work_package_id = params[:work_package][:id]
- target_child_work_package = WorkPackage.find(target_work_package_id)
+ child = WorkPackage.find(params[:work_package][:id])
+ service_result = set_relation(child:, parent: @work_package)
- target_child_work_package.parent = @work_package
+ respond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)
+ end
- if target_child_work_package.save
- @children = @work_package.children.visible
- @relations = @work_package.relations.visible
+ def destroy
+ child = WorkPackage.find(params[:id])
+ service_result = set_relation(child:, parent: nil)
- component = WorkPackageRelationsTab::IndexComponent.new(
- work_package: @work_package,
- relations: @relations,
- children: @children,
- scroll_to_id: target_work_package_id
- )
- replace_via_turbo_stream(component:)
- render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))
- respond_with_turbo_streams
- end
+ respond_with_relations_tab_update(service_result)
end
- def destroy
- @child.parent = nil
+ private
- if @child.save
+ def set_relation(child:, parent:)
+ WorkPackages::UpdateService.new(user: current_user, model: child)
+ .call(parent:)
+ end
+
+ def respond_with_relations_tab_update(service_result, **)
+ if service_result.success?
@work_package.reload
- @children = @work_package.children.visible
component = WorkPackageRelationsTab::IndexComponent.new(
work_package: @work_package,
- relations: @relations,
- children: @children
+ relations: @work_package.relations.visible,
+ children: @work_package.children.visible,
+ **
)
replace_via_turbo_stream(component:)
- update_flash_message_via_turbo_stream(
- message: I18n.t(:notice_successful_update), scheme: :success
- )
+ render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))
respond_with_turbo_streams
+ else
+ respond_with_turbo_streams(status: :unprocessable_entity)
end
end