Skip to content

Commit

Permalink
Fixes #37170 - Support exiring in information in subscription report
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Feb 20, 2024
1 parent fb6f707 commit e9a05e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions app/lib/katello/concerns/base_template_scope_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ def host_latest_installable_rpm_version(host, package)
keyword :includes, Array, of: [String, Symbol], desc: 'An array of associations represented by strings or symbols, to be included in the SQL query. The list can be extended
from plugins and can not be fully documented here. Most used associations are :subscription, :products, :organization', default: nil
returns array_of: 'Pool', desc: 'The collection that can be iterated over using each_record'
keyword :expiring_in_days, String, desc: "Return subscriptions expiring in given number of days", default: nil
end
def load_pools(search: '', includes: nil)
load_resource(klass: Pool.readable, search: search, permission: nil, includes: includes)
def load_pools(search: '', includes: nil, expiring_in_days: nil)
pools = Pool.readable
if expiring_in_days
pools = pools.expiring_in_days(expiring_in_days)
end
load_resource(klass: pools, search: search, permission: nil, includes: includes)
end

apipie :method, 'Returns the last time the host checked in via RHSM' do
Expand Down
16 changes: 13 additions & 3 deletions app/models/katello/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ def quantity_available
self.quantity - self.consumed
end

def subscription_name
self.subscription&.name
end

def subscription_sku
self.subscription&.cp_id
end

def type
self.pool_type
end

def upstream?
upstream_pool_id.present?
end
Expand Down Expand Up @@ -141,17 +148,20 @@ def default_sort
property :account_number, Integer, desc: 'Returns subscription account number'
property :contract_number, Integer, desc: 'Returns subscription contract number'
property :type, String, desc: 'Returns type of the pool, e.g. "NORMAL"'
property :subscription_name, String, desc: 'Returns name of subscription'
property :subscription_sku, String, desc: 'Returns sku of subscription'
property :organization, 'Organization', desc: 'Returns organization to which the pool belongs'
property :start_date, ActiveSupport::TimeWithZone, desc: 'Returns subscription start date'
property :end_date, ActiveSupport::TimeWithZone, desc: 'Returns subscription end date'
property :days_until_expiration, Integer, desc: 'Returns number of days until expiration'
end
class Jail < ::Safemode::Jail
allow :id, :name, :available, :quantity, :product_id, :contract_number, :type, :account_number, :start_date, :end_date, :organization, :consumed, :days_until_expiration
allow :id, :name, :available, :quantity, :product_id, :contract_number, :type, :subscription_name, :subscription_sku, :account_number, :start_date, :end_date, :organization, :consumed, :days_until_expiration, :subscription,
:expiring_in_days
end
end
end

class ActiveRecord::AssociationRelation::Jail < Safemode::Jail
allow :sort_by
allow :sort_by, :expiring_in_days
end

0 comments on commit e9a05e2

Please sign in to comment.