Sha256: 33788e9abced4aaa97a8fe5f64234c7a4d65c4695eff6803e9f0f0eeff14c997

Contents?: true

Size: 1.64 KB

Versions: 28

Compression:

Stored size: 1.64 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

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

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

    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?
      # for custom subscriptions, there is no separate marketing and engineering product
      #   so query our Products table and check there
      product = Katello::Product.where(:cp_id => self.cp_id, :organization => self.organization).first
      product.nil? || product.redhat?
    end

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

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

    def recently_expired?
      pools.any?(&:recently_expired?)
    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

28 entries across 28 versions & 1 rubygems

Version Path
katello-3.11.2 app/models/katello/subscription.rb
katello-3.10.2 app/models/katello/subscription.rb
katello-3.12.0 app/models/katello/subscription.rb
katello-3.12.0.rc2 app/models/katello/subscription.rb
katello-3.10.1.1 app/models/katello/subscription.rb
katello-3.12.0.rc1 app/models/katello/subscription.rb
katello-3.10.1 app/models/katello/subscription.rb
katello-3.11.1 app/models/katello/subscription.rb
katello-3.11.0 app/models/katello/subscription.rb
katello-3.11.0.rc2 app/models/katello/subscription.rb
katello-3.11.0.rc1 app/models/katello/subscription.rb
katello-3.10.0 app/models/katello/subscription.rb
katello-3.10.0.rc1.1 app/models/katello/subscription.rb
katello-3.9.1 app/models/katello/subscription.rb
katello-3.10.0.rc1 app/models/katello/subscription.rb
katello-3.9.0 app/models/katello/subscription.rb
katello-3.8.1 app/models/katello/subscription.rb
katello-3.9.0.rc2 app/models/katello/subscription.rb
katello-3.9.0.rc1 app/models/katello/subscription.rb
katello-3.7.1.1 app/models/katello/subscription.rb