Class: Katello::UINotifications::Subscriptions::ManifestExpireSoonWarning

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb

Class Method Summary collapse

Class Method Details

.actionsObject



55
56
57
58
59
60
61
62
63
64
65
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb', line 55

def actions
  {
    :links => [
      {
        :href => "/subscriptions",
        :title => _('Subscriptions'),
        :external => false,
      },
    ],
  }
end

.blueprintObject



67
68
69
70
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb', line 67

def blueprint
  @blueprint ||= NotificationBlueprint.unscoped.find_by(
    :name => 'manifest_expire_soon_warning')
end

.deliver!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb', line 6

def deliver!
  ::Organization.unscoped.all.each do |organization|
    if (notification = existing_notification(organization))
      days_remaining = organization.manifest_expire_days_remaining
      if days_remaining == 0 || days_remaining > Setting[:expire_soon_days].to_i
        # if the manifest has already expired, delete the notification;
        # user will have a ManifestExpiredWarning instead.
        # If user changes the expire_soon_days setting, remove notifications
        # that are no longer relevant.
        Rails.logger.debug("ManifestExpireSoonWarning: deleting notification for #{organization.name}")
        notification.destroy
        next
      end
      # don't update if the message hasn't changed
      next unless message(organization).to_s !=
        notification.message.to_s
      notification.update(
        :message => message(organization),
        :actions => actions
      )
    else
      next unless organization.manifest_expiring_soon?
      ::Notification.create!(
        :subject => organization,
        :initiator => User.anonymous_admin,
        :audience => Notification::AUDIENCE_SUBJECT,
        :message => message(organization),
        :actions => actions,
        :notification_blueprint => blueprint
      )
    end
  end
end

.existing_notification(subject) ⇒ Object



40
41
42
43
44
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb', line 40

def existing_notification(subject)
  matching_notification = Notification.unscoped.find_by(:subject => subject, :notification_blueprint => blueprint)
  return false if matching_notification.blank?
  matching_notification
end

.message(organization) ⇒ Object



46
47
48
49
50
51
52
53
# File 'app/services/katello/ui_notifications/subscriptions/manifest_expire_soon_warning.rb', line 46

def message(organization)
  ::UINotifications::StringParser.new(
    blueprint.message,
    :manifest_expire_date => organization.manifest_expiration_date&.to_date,
    :subject => organization,
    :days_remaining => organization.manifest_expire_days_remaining
  )
end