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 d566b3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/helpers/katello/subscription_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def report_link
end

def start_report_task(days_from_now)
@report_template = ReportTemplate.find_by(name: "Subscription - Entitlement Report")
@report_template = ReportTemplate.find_by(name: "Subscription - General Report")
template_input_id = @report_template.template_inputs.find_by_name("Days from Now").id.to_s
params = { format: 'csv', template_id: @report_template.id, input_values: { template_input_id => { value: days_from_now} } }
composer = ReportComposer.new(params)
Expand Down
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
10 changes: 3 additions & 7 deletions app/mailers/katello/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ class SubscriptionMailer < ApplicationMailer
include SubscriptionMailerHelper

def subscription_expiry(options)
user = ::User.find(options[:user])
days_from_now = options[:query]

::User.as(user.login) do
@pools = Katello::Pool.readable.expiring_in_days(days_from_now)
@affected_hosts = ::Host::Managed.with_pools_expiring_in_days(days_from_now)
end

if @affected_hosts.any?
start_report_task(days_from_now)
@report_url = report_url
@report_link = report_link
end
start_report_task(days_from_now)
@report_url = report_url
@report_link = report_link

set_locale_for(user) do
mail(:to => user.mail, :subject => _("You have subscriptions expiring within %s days") % days_from_now)
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 d566b3a

Please sign in to comment.