Sha256: 934be6a5dc5c49f026fa506f2d2b301239e72f4f8baf75c96e4aea1222dfebaf

Contents?: true

Size: 1.87 KB

Versions: 21

Compression:

Stored size: 1.87 KB

Contents

module Katello
  class HostAvailableModuleStream < Katello::Model
    belongs_to :host, :inverse_of => :host_available_module_streams, :class_name => '::Host::Managed'
    belongs_to :available_module_stream, :inverse_of => :host_available_module_streams, :class_name => 'Katello::AvailableModuleStream'
    serialize :installed_profiles

    scope :installed, -> { enabled.where.not(installed_profiles: []) }
    scope :enabled, -> { where(status: ENABLED) }
    scope :disabled, -> { where(status: DISABLED) }
    scope :unknown, -> { where(status: UNKNOWN) }

    ENABLED = "enabled".freeze
    DISABLED = "disabled".freeze
    UNKNOWN = "unknown".freeze
    INSTALLED = "installed".freeze
    UPGRADABLE = "upgradable".freeze

    STATUS = [ENABLED, DISABLED, UNKNOWN].freeze

    API_STATES = {
      ENABLED => :enabled,
      DISABLED => :disabled,
      UNKNOWN => :unknown,
      INSTALLED => :installed,
      UPGRADABLE => :upgradable
    }.with_indifferent_access

    scoped_search :on => :name, :relation => :available_module_stream, :complete_value => true
    scoped_search :on => :stream, :relation => :available_module_stream, :complete_value => false
    scoped_search :on => :status, :complete_value => STATUS

    def upgradable?
      return false if status != ENABLED

      ModuleStream.installable_for_hosts([host_id]).
           where(ModuleStream.table_name => {:name => available_module_stream.name,
                                             :stream => available_module_stream.stream}).exists?
    end

    def self.upgradable(host)
      upgradable_module_name_streams = ModuleStream.installable_for_hosts([host]).select(:name, :stream)

      enabled.joins(:available_module_stream).where(:host_id => host).
              where("(#{AvailableModuleStream.table_name}.name, #{AvailableModuleStream.table_name}.stream) in (#{upgradable_module_name_streams.to_sql})")
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
katello-4.3.1 app/models/katello/host_available_module_stream.rb
katello-4.4.0.rc1 app/models/katello/host_available_module_stream.rb
katello-4.2.2 app/models/katello/host_available_module_stream.rb
katello-4.3.0 app/models/katello/host_available_module_stream.rb
katello-4.3.0.rc4 app/models/katello/host_available_module_stream.rb
katello-4.3.0.rc3 app/models/katello/host_available_module_stream.rb
katello-4.3.0.rc2.1 app/models/katello/host_available_module_stream.rb
katello-4.3.0.rc2 app/models/katello/host_available_module_stream.rb
katello-4.3.0.rc1 app/models/katello/host_available_module_stream.rb
katello-4.2.1 app/models/katello/host_available_module_stream.rb
katello-4.2.0.1 app/models/katello/host_available_module_stream.rb
katello-4.1.4 app/models/katello/host_available_module_stream.rb
katello-4.2.0.1.rc3 app/models/katello/host_available_module_stream.rb
katello-4.2.0.1.rc2 app/models/katello/host_available_module_stream.rb
katello-4.2.0.rc2 app/models/katello/host_available_module_stream.rb
katello-4.1.3 app/models/katello/host_available_module_stream.rb
katello-4.2.0.rc1 app/models/katello/host_available_module_stream.rb
katello-4.1.2.1 app/models/katello/host_available_module_stream.rb
katello-4.1.2 app/models/katello/host_available_module_stream.rb
katello-4.1.1 app/models/katello/host_available_module_stream.rb