app/lib/actions/katello/host/attach_subscriptions.rb in katello-3.1.0.1 vs app/lib/actions/katello/host/attach_subscriptions.rb in katello-3.2.0.rc1

- old
+ new

@@ -2,28 +2,35 @@ module Katello module Host class AttachSubscriptions < Actions::EntryAction middleware.use Actions::Middleware::KeepCurrentUser - def plan(host, pools_with_quantities) + def plan(host, pools_with_quantities_params) action_subject(host) - sequence do pool_ids = [] + pools_with_quantities = pools_with_quantities_params.map do |pool_with_quantity| + ::Katello::PoolWithQuantities.fetch(pool_with_quantity) + end + existing_pool_ids = host.subscription_facet.candlepin_consumer.pool_ids pools_with_quantities.each do |pool_with_quantities| - pool_ids << pool_with_quantities.pool.id - pool_with_quantities.quantities.each do |quantity| - plan_action(::Actions::Candlepin::Consumer::AttachSubscription, :uuid => host.subscription_facet.uuid, - :pool_uuid => pool_with_quantities.pool.cp_id, :quantity => quantity) + unless existing_pool_ids.include?(pool_with_quantities.pool.cp_id.to_s) + pool_ids << pool_with_quantities.pool.id + pool_with_quantities.quantities.each do |quantity| + plan_action(::Actions::Candlepin::Consumer::AttachSubscription, :uuid => host.subscription_facet.uuid, + :pool_uuid => pool_with_quantities.pool.cp_id, :quantity => quantity) + end end end plan_self(:pool_ids => pool_ids, :host_name => host.name) end end def finalize ::Katello::Pool.where(:id => input[:pool_ids]).each(&:import_data) + host = ::Host.find_by(:id => input[:managed][:id]) + host.subscription_facet.update_subscription_status end def rescue_strategy Dynflow::Action::Rescue::Skip end