Sha256: d4759d77a2d9d639e0d3bdd0ddcdb1777222b825b8e65c9730212e5259ea0dd7

Contents?: true

Size: 1.66 KB

Versions: 45

Compression:

Stored size: 1.66 KB

Contents

module Katello
  class Subscription < Katello::Model
    include Glue::Candlepin::CandlepinObject
    include Glue::Candlepin::Subscription
    include Katello::Authorization::Subscription

    has_many :pools, :class_name => "Katello::Pool", :inverse_of => :subscription, :dependent => :destroy
    has_many :products, :class_name => "Katello::Product", :through => :pools

    belongs_to :organization, :class_name => "Organization", :inverse_of => :subscriptions

    scope :in_organization, ->(org) { where(:organization => org) }

    scope :redhat, -> { joins(:products).merge(Katello::Product.redhat).distinct }

    def self.subscribable
      product_ids = Product.subscribable.pluck(:id) + [nil]
      joins(:pools).joins("LEFT OUTER JOIN #{Katello::PoolProduct.table_name} pool_prod ON #{Pool.table_name}.id = pool_prod.pool_id")
        .where("pool_prod.product_id" => product_ids)
        .group("#{self.table_name}.id")
    end

    delegate :user_ids, :to => :organization

    def self.using_virt_who
      joins(:pools).where("#{Katello::Pool.table_name}.virt_who" => true)
    end

    def redhat?
      products.redhat.any?
    end

    def active?
      pools.any?(&:active?)
    end

    def expiring_soon?
      pools.any?(&:expiring_soon?)
    end

    def recently_expired?
      pools.any?(&:recently_expired?)
    end

    def multi_entitlement?
      pools.where("#{Katello::Pool.table_name}.multi_entitlement" => true).any?
    end

    def virt_who_pools
      pools.where("#{Katello::Pool.table_name}.virt_who" => true)
    end

    def virt_who?
      virt_who_pools.any?
    end

    def self.humanize_class_name(_name = nil)
      _("Subscription")
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
katello-4.0.3 app/models/katello/subscription.rb
katello-3.18.5 app/models/katello/subscription.rb
katello-4.0.2.1 app/models/katello/subscription.rb
katello-4.0.2 app/models/katello/subscription.rb
katello-3.18.4 app/models/katello/subscription.rb
katello-4.0.1.2 app/models/katello/subscription.rb
katello-3.18.3.1 app/models/katello/subscription.rb
katello-4.0.1.1 app/models/katello/subscription.rb
katello-3.18.3 app/models/katello/subscription.rb
katello-4.0.1 app/models/katello/subscription.rb
katello-4.0.0 app/models/katello/subscription.rb
katello-4.0.0.rc3.1 app/models/katello/subscription.rb
katello-4.0.0.rc3 app/models/katello/subscription.rb
katello-3.18.2.1 app/models/katello/subscription.rb
katello-3.18.2 app/models/katello/subscription.rb
katello-3.17.3 app/models/katello/subscription.rb
katello-4.0.0.rc2 app/models/katello/subscription.rb
katello-3.18.1.1 app/models/katello/subscription.rb
katello-3.17.2 app/models/katello/subscription.rb
katello-4.0.0.rc1 app/models/katello/subscription.rb