Sha256: ebd43f6998da17ff20555d0f76b287e0c4ae0bde9046407338b8fae1aa9f10b2

Contents?: true

Size: 1.5 KB

Versions: 92

Compression:

Stored size: 1.5 KB

Contents

module UINotifications
  module Tasks
    class TaskPausedAdmin < Tasks::Base
      def deliver!
        # delete previous notifications about paused tasks first
        Notification.where(notification_blueprint_id: blueprint.id).each(&:destroy)
        notification = ::Notification.new(
          :audience => Notification::AUDIENCE_ADMIN,
          :notification_blueprint => blueprint,
          :initiator => initiator,
          :subject => subject,
          :message => message
        )

        notification.send(:set_custom_attributes) # to add links from blueprint
        notification.actions['links'] ||= []
        if troubleshooting_help_generator
          troubleshooting_link = troubleshooting_help_generator.troubleshooting_link(generic_only: true)
          notification.actions['links'] << troubleshooting_link.to_h(capitalize_title: true) if troubleshooting_link
        end
        notification.save!
        notification
      end

      def initiator
        User.anonymous_admin
      end

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

      def message
        return @message if @message

        tasks_count = ForemanTasks::Task.where(state: 'paused').count
        @message = n_('There is %{count} paused task in the system that need attention',
                      'There are %{count} paused tasks in the system that need attention',
                      tasks_count) % { count: tasks_count }
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-10.0.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-10.0.0 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.2.3 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.2.2 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.2.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.2.0 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.1.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.0.4 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.1.0 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.0.2 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.0.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.3.3 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-9.0.0 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.2.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.1.4 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.3.2 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.3.1 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.1.3 app/services/ui_notifications/tasks/task_paused_admin.rb
foreman-tasks-8.3.0 app/services/ui_notifications/tasks/task_paused_admin.rb