Sha256: 83e70eef6b37d6c299c52114eae35b7000a60db67fa36795ecd787307c2e6652

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 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 token_changed_callback
    User.current = User.anonymous_admin unless User.current
    scc_products.where.not(product: nil).find_each do |sp|
      reponame = sp.friendly_name + ' ' + description
      repository = sp.product.repositories.find_by(name: reponame)
      unless 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

4 entries across 4 versions & 1 rubygems

Version Path
foreman_scc_manager-1.3.1 app/models/scc_repository.rb
foreman_scc_manager-1.3.0 app/models/scc_repository.rb
foreman_scc_manager-1.2.0 app/models/scc_repository.rb
foreman_scc_manager-1.1.0 app/models/scc_repository.rb