Class: Katello::ProductContent

Inherits:
Model
  • Object
show all
Defined in:
app/models/katello/product_content.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#destroy!

Class Method Details

.content_table_nameObject



32
33
34
# File 'app/models/katello/product_content.rb', line 32

def self.content_table_name
  Katello::Content.table_name
end

.enabled(organization) ⇒ Object



36
37
38
# File 'app/models/katello/product_content.rb', line 36

def self.enabled(organization)
  joins(:content).where("#{self.content_table_name}.cp_content_id" => Katello::RootRepository.in_organization(organization).select(:content_id))
end

.with_valid_subscription(organization) ⇒ Object



40
41
42
# File 'app/models/katello/product_content.rb', line 40

def self.with_valid_subscription(organization)
  where(:product_id => Katello::PoolProduct.where(:pool_id => organization.pools).select(:product_id))
end

Instance Method Details

#archObject



54
55
56
# File 'app/models/katello/product_content.rb', line 54

def arch
  unfiltered_repositories.first&.arch
end

#enabled_value_from_candlepinObject



62
63
64
65
66
# File 'app/models/katello/product_content.rb', line 62

def enabled_value_from_candlepin
  cp_product = ::Katello::Resources::Candlepin::Product.get(product.organization.label, product.cp_id).first
  cp_content = cp_product['productContent'].find { |pc| pc['content']['id'] == content.cp_content_id }
  cp_content['enabled']
end

#os_versionsObject



58
59
60
# File 'app/models/katello/product_content.rb', line 58

def os_versions
  unfiltered_repositories.first&.os_versions || []
end

#repositoriesObject

following 4 methods used by Katello::Api::V2::RepositorySetsController#index



45
46
47
# File 'app/models/katello/product_content.rb', line 45

def repositories
  Katello::Repository.in_default_view.where(:root_id => product.root_repositories.has_url.where(:content_id => content.cp_content_id))
end

#set_enabled_from_candlepin!Object



68
69
70
71
72
73
74
75
76
77
# File 'app/models/katello/product_content.rb', line 68

def set_enabled_from_candlepin!
  new_value = enabled_value_from_candlepin
  if self.enabled != new_value
    Rails.logger.info "Setting enabled to #{new_value} for Candlepin content #{content.cp_content_id}, ProductContent #{self.id}"
    self.update!(:enabled => new_value)
  else
    Rails.logger.info "No change in enabled value for Candlepin content #{content.cp_content_id}, ProductContent #{self.id}"
    false
  end
end

#unfiltered_repositoriesObject



49
50
51
52
# File 'app/models/katello/product_content.rb', line 49

def unfiltered_repositories
  # don't filter by url, as we want to show all repos in the product
  Katello::Repository.in_default_view.where(:root_id => product.root_repositories.where(:content_id => content.cp_content_id))
end