Sha256: a9366ce93947d628d03bc4bce970715dfa3e49916d97579c0fadd2fb443e8bb1

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

class SccProduct < ApplicationRecord
  include Authorizable
  include ForemanTasks::Concerns::ActionSubject

  scope :only_products_with_repos, -> { joins(:scc_repositories).distinct }

  self.include_root_in_json = false

  belongs_to :scc_account
  belongs_to :product, class_name: 'Katello::Product'
  has_one :organization, through: :scc_account
  has_and_belongs_to_many :scc_repositories
  has_many :scc_extendings, inverse_of: :scc_product, dependent: :destroy
  has_many :scc_extensions, through: :scc_extendings
  has_many :inverse_scc_extendings,
           inverse_of: :scc_extension,
           dependent: :destroy,
           class_name: :SccExtending,
           foreign_key: :scc_extension_id
  has_many :inverse_scc_extensions, through: :inverse_scc_extendings, source: :scc_product

  default_scope -> { order(:name) }
  scoped_search on: :name, complete_value: true
  scoped_search on: :friendly_name

  def uniq_name
    "#{scc_id} " + friendly_name
  end

  def subscribe
    raise 'Product already subscribed!' if product

    new_product = Katello::Product.new
    new_product.name = uniq_name
    new_product.description = description
    ForemanTasks.sync_task(::Actions::Katello::Product::Create, new_product, scc_account.organization)
    new_product.reload
    scc_repositories.each do |repo|
      uniq_repo_name = repo.uniq_name(self)
      label = Katello::Util::Model.labelize(uniq_repo_name)
      unprotected = true
      gpg_key = new_product.gpg_key
      new_repo = new_product.add_repo(label, uniq_repo_name, repo.full_url, 'yum', unprotected, gpg_key)
      new_repo.arch = arch || 'noarch'
      new_repo.mirror_on_sync = true
      new_repo.verify_ssl_on_sync = true
      ForemanTasks.sync_task(::Actions::Katello::Repository::Create, new_repo, false, false)
    end
    update!(product: new_product)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_scc_manager-1.8.5 app/models/scc_product.rb