Class: Actions::Katello::AlternateContentSource::Update
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::AlternateContentSource::Update
- Includes:
- AlternateContentSourceCommon
- Defined in:
- app/lib/actions/katello/alternate_content_source/update.rb
Instance Method Summary collapse
- #create_acss(acs, smart_proxies_to_associate) ⇒ Object
- #delete_acss(acs, smart_proxies_to_disassociate) ⇒ Object
- #humanized_name ⇒ Object
-
#plan(acs, smart_proxies, products, acs_params) ⇒ Object
smart_proxies ALWAYS represents the smart proxies to remain associated after the action runs.
- #update_acss(acs, smart_proxies_to_update, products_to_associate, products_to_disassociate) ⇒ Object
Methods included from AlternateContentSourceCommon
Instance Method Details
#create_acss(acs, smart_proxies_to_associate) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/lib/actions/katello/alternate_content_source/update.rb', line 40 def create_acss(acs, smart_proxies_to_associate) smart_proxies_to_associate&.each do |smart_proxy| if acs.custom? || acs.rhui? smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id) plan_action(Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs) elsif acs.simplified? create_simplified_acs(acs, smart_proxy) end end end |
#delete_acss(acs, smart_proxies_to_disassociate) ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/lib/actions/katello/alternate_content_source/update.rb', line 51 def delete_acss(acs, smart_proxies_to_disassociate) smart_proxies_to_disassociate&.each do |smart_proxy| acs.smart_proxy_alternate_content_sources.where(smart_proxy_id: smart_proxy.id).each do |smart_proxy_acs| plan_action(Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs) end end end |
#humanized_name ⇒ Object
81 82 83 |
# File 'app/lib/actions/katello/alternate_content_source/update.rb', line 81 def humanized_name _("Update Alternate Content Source") end |
#plan(acs, smart_proxies, products, acs_params) ⇒ Object
smart_proxies ALWAYS represents the smart proxies to remain associated after the action runs. If smart_proxies == [], there will be none afterwards. The same rule applies to products.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/lib/actions/katello/alternate_content_source/update.rb', line 9 def plan(acs, smart_proxies, products, acs_params) action_subject(acs) acs.update!(acs_params) smart_proxies = smart_proxies.uniq smart_proxies_to_associate = smart_proxies - acs.smart_proxies smart_proxies_to_disassociate = acs.smart_proxies - smart_proxies smart_proxies_to_update = smart_proxies & acs.smart_proxies products ||= [] products_to_associate = [] products_to_disassociate = [] if products.present? || acs.products.present? products = products.uniq products_to_associate = products - acs.products products_to_disassociate = acs.products - products old_product_ids = acs.products.pluck(:id) acs.products = products acs.audit_updated_products(old_product_ids) unless products_to_associate.empty? && products_to_disassociate.empty? end acs.save! concurrence do create_acss(acs, smart_proxies_to_associate) delete_acss(acs, smart_proxies_to_disassociate) update_acss(acs, smart_proxies_to_update, products_to_associate, products_to_disassociate) end end |
#update_acss(acs, smart_proxies_to_update, products_to_associate, products_to_disassociate) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/lib/actions/katello/alternate_content_source/update.rb', line 59 def update_acss(acs, smart_proxies_to_update, products_to_associate, products_to_disassociate) smart_proxies_to_update&.each do |smart_proxy| if acs.custom? || acs.rhui? smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.find_by(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id, repository_id: nil) plan_action(Pulp3::Orchestration::AlternateContentSource::Update, smart_proxy_acs) elsif acs.simplified? products_to_associate.each do |product| product.repositories.library.with_type(acs.content_type).each do |repo| smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.create(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id, repository_id: repo.id) plan_action(Pulp3::Orchestration::AlternateContentSource::Create, smart_proxy_acs) end end products_to_disassociate.each do |product| product.repositories.library.with_type(acs.content_type).each do |repo| smart_proxy_acs = ::Katello::SmartProxyAlternateContentSource.find_by(alternate_content_source_id: acs.id, smart_proxy_id: smart_proxy.id, repository_id: repo.id) plan_action(Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs) end end end end end |