From 6bf778d72decf5310c4397301f29c0cc824c26b3 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Mon, 30 Oct 2023 17:20:56 -0400 Subject: [PATCH] Fixes #36878 - Override host bulk destroy --- .../concerns/api/v2/hosts_controller_extensions.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb b/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb index a35c17394f8..2c41b88c2b5 100644 --- a/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb +++ b/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb @@ -3,6 +3,7 @@ module Concerns module Api::V2::HostsControllerExtensions extend ActiveSupport::Concern include ForemanTasks::Triggers + require 'active_support/core_ext/string/inflections' module Overrides def action_permission @@ -24,6 +25,14 @@ def destroy process_response(:object => @host) end + def bulk_destroy + destroyed_count = @hosts.count + @hosts.in_batches.each_record do |host| + Katello::RegistrationManager.unregister_host(host, :unregistering => false) + end + process_response(true, { :message => _("Deleted %{host_count} %{hosts}") % { :host_count => destroyed_count, :hosts => 'host'.pluralize(destroyed_count) }}) + end + api :PUT, "/hosts/:host_id/host_collections", N_("Alter a host's host collections") param :host_id, :number, :required => true, :desc => N_("The id of the host to alter") param :host_collection_ids, Array, :required => true, :desc => N_("List of host collection ids to update")