Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #19314 - Notification for subscr. expiring soon
The notifications drawer should show a warning when some subscription is about to expire. "expiring_soon?" defined in the subscriptions.rb code says this is 120 days before it expires.
- Loading branch information
Showing
6 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SendExpireSoonNotifications < ApplicationJob | ||
after_perform do | ||
self.class.set(:wait => 12.hours).perform_later | ||
end | ||
|
||
def perform | ||
Katello::UINotifications::Subscriptions::ExpireSoon.deliver! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/services/katello/ui_notifications/subscriptions/expire_soon.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Katello | ||
module UINotifications | ||
module Subscriptions | ||
class ExpireSoon | ||
class << self | ||
def deliver! | ||
::Organization.unscoped.all.each do |organization| | ||
if (notification = notification_already_exists?(organization)) | ||
next unless organization.expiring_subscriptions.count.to_s == | ||
notification.message.split(' ').first | ||
notification.update_attributes( | ||
:message => message(organization), | ||
:actions => actions | ||
) | ||
else | ||
next unless organization.expiring_subscriptions.count > 0 | ||
::Notification.create!( | ||
:subject => organization, | ||
:initiator => User.anonymous_admin, | ||
:audience => Notification::AUDIENCE_SUBJECT, | ||
:message => message(organization), | ||
:actions => actions, | ||
:notification_blueprint => blueprint | ||
) | ||
end | ||
end | ||
end | ||
|
||
def notification_already_exists?(subject) | ||
subs_expiration_notification = Notification.unscoped.find_by(:subject => subject) | ||
return false if subs_expiration_notification.blank? | ||
subs_expiration_notification.notification_blueprint == blueprint | ||
subs_expiration_notification | ||
end | ||
|
||
def message(organization) | ||
::UINotifications::StringParser.new( | ||
blueprint.message, | ||
:expiring_subs => organization.expiring_subscriptions.count, | ||
:subject => organization | ||
) | ||
end | ||
|
||
|
||
def actions | ||
{ | ||
:links => [ | ||
{ | ||
:href => "/subscriptions?search=expires<\"#{Katello::Pool::DAYS_EXPIRING_SOON} days from now\"", | ||
:title => _('Subscriptions'), | ||
:external => true | ||
} | ||
] | ||
} | ||
end | ||
|
||
def blueprint | ||
@blueprint ||= NotificationBlueprint.unscoped.find_by( | ||
:name => 'subs_expire_soon') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
# First, we check if there's a job already enqueued for Pulp notifications | ||
# First, we check if there's a job already enqueued for any notifications | ||
::Foreman::Application.dynflow.config.on_init do |world| | ||
pending_jobs = world.persistence.find_execution_plans(filters: { :state => 'scheduled' }) | ||
scheduled_job = pending_jobs.select do |job| | ||
scheduled_pulp_job = pending_jobs.select do |job| | ||
delayed_plan = world.persistence.load_delayed_plan job.id | ||
next if delayed_plan.blank? | ||
delayed_plan.to_hash[:serialized_args].first["job_class"] == 'CreatePulpDiskSpaceNotifications' | ||
end | ||
scheduled_subs_expiration_job = pending_jobs.select do |job| | ||
delayed_plan = world.persistence.load_delayed_plan job.id | ||
next if delayed_plan.blank? | ||
delayed_plan.to_hash[:serialized_args].first["job_class"] == 'SendExpireSoonNotifications' | ||
end | ||
|
||
# Only create notifications if there isn't a scheduled job | ||
CreatePulpDiskSpaceNotifications.perform_later if scheduled_job.blank? | ||
CreatePulpDiskSpaceNotifications.perform_later if scheduled_pulp_job.blank? | ||
SendExpireSoonNotifications.perform_later if scheduled_subs_expiration_job.blank? | ||
end |