Sha256: 95d137c8de318072fcbdacf3f28f41655c9beaf06928d6d346986b9dd1280d4a

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

module Katello
  class ContentViewEnvironment < Katello::Model
    self.include_root_in_json = false

    include ForemanTasks::Concerns::ActionSubject
    include Glue::Candlepin::Environment if SETTINGS[:katello][:use_cp]
    include Glue if SETTINGS[:katello][:use_cp]
    include Authorization::ContentViewEnvironment

    belongs_to :content_view, :class_name => "Katello::ContentView", :inverse_of => :content_view_environments
    belongs_to :environment, :class_name => "Katello::KTEnvironment", :inverse_of => :content_view_environments
    belongs_to :content_view_version, :class_name => "Katello::ContentViewVersion",
                                      :inverse_of => :content_view_environments

    validates_lengths_from_database
    validates :environment_id, uniqueness: {scope: :content_view_id}, presence: true
    validates :content_view_id, presence: true

    before_save :generate_info

    scope :non_default, -> { joins(:content_view).where("katello_content_views.default" => false) }

    def self.for_systems(systems)
      joins("INNER JOIN #{System.table_name} on #{System.table_name}.environment_id = #{ContentViewEnvironment.table_name}.environment_id").
           where("#{System.table_name}.content_view_id = #{ContentViewEnvironment.table_name}.content_view_id").where("#{System.table_name}.id" => systems).uniq
    end

    # retrieve the owning environment for this content view environment.
    def owner
      self.environment
    end

    def systems
      content_view.systems.in_environment(environment)
    end

    def activation_keys
      content_view.activation_keys.in_environment(environment)
    end

    private

    def generate_info
      self.name ||= environment.name

      if content_view.default?
        self.label ||= environment.label
        self.cp_id ||= environment.id.to_s
      else
        self.label ||= [environment.label, content_view.label].join('/')
        self.cp_id ||= [environment.id, content_view.id].join('-')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/models/katello/content_view_environment.rb
katello-2.4.4 app/models/katello/content_view_environment.rb
katello-2.4.3 app/models/katello/content_view_environment.rb
katello-2.4.2 app/models/katello/content_view_environment.rb
katello-2.4.1 app/models/katello/content_view_environment.rb
katello-2.4.0 app/models/katello/content_view_environment.rb
katello-2.4.0.rc3 app/models/katello/content_view_environment.rb
katello-2.4.0.rc2 app/models/katello/content_view_environment.rb
katello-2.4.0.rc1 app/models/katello/content_view_environment.rb