Sha256: 3209cbf10e81140f8cfa79198583d3249107192d8967c79dbe7268110c5907e4

Contents?: true

Size: 908 Bytes

Versions: 9

Compression:

Stored size: 908 Bytes

Contents

class SccRepository < ApplicationRecord
  after_commit :token_changed_callback

  self.include_root_in_json = false

  belongs_to :scc_account
  has_one :organization, through: :scc_account
  has_and_belongs_to_many :scc_products

  def full_url
    token.blank? ? url : url + '?' + token
  end

  def uniq_name(scc_product)
    scc_product.uniq_name + ' ' + description
  end

  def token_changed_callback
    User.current ||= User.anonymous_admin
    scc_products.where.not(product: nil).find_each do |sp|
      reponame = uniq_name(sp)
      repository = sp.product.root_repositories.find_by(name: reponame)
      unless repository.nil? || repository.url == full_url
        ::Foreman::Logging.logger('foreman_scc_manager').info "Update URL-token for repository '#{reponame}'."
        ForemanTasks.async_task(::Actions::Katello::Repository::Update, repository, url: full_url)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foreman_scc_manager-1.8.5 app/models/scc_repository.rb
foreman_scc_manager-1.8.4 app/models/scc_repository.rb
foreman_scc_manager-1.7.1 app/models/scc_repository.rb
foreman_scc_manager-1.8.3 app/models/scc_repository.rb
foreman_scc_manager-1.8.2 app/models/scc_repository.rb
foreman_scc_manager-1.8.1 app/models/scc_repository.rb
foreman_scc_manager-1.8.0 app/models/scc_repository.rb
foreman_scc_manager-1.7.0 app/models/scc_repository.rb
foreman_scc_manager-1.6.3 app/models/scc_repository.rb