Sha256: 28f338a1999347d79e651322bd9bba565c436a2ad1c7f0bd1851ab9471494ce0

Contents?: true

Size: 1.65 KB

Versions: 71

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module ForemanAnsible
  # A class that builds custom notificaton for REX job if it's insights
  # remediation feature
  class InsightsNotificationBuilder < ::UINotifications::RemoteExecutionJobs::BaseJobFinish
    def deliver!
      ::Notification.create!(
        :audience => Notification::AUDIENCE_USER,
        :notification_blueprint => blueprint,
        :initiator => initiator,
        :message => message,
        :subject => subject,
        :actions => {
          :links => links
        }
      )
    end

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

    def hosts_count
      @hosts_count ||= subject.template_invocations_hosts.size
    end

    def message
      UINotifications::StringParser.new(blueprint.message,
                                        :hosts_count => hosts_count)
    end

    def links
      job_links + insights_links
    end

    def insights_links
      pattern_template = subject.pattern_template_invocations.first
      plan_id = pattern_template.input_values.
                joins(:template_input).
                where('template_inputs.name' => 'plan_id').
                first.try(:value)
      return [] if plan_id.nil?

      [
        {
          :href => "/redhat_access/insights/planner/#{plan_id}",
          :title => _('Remediation Plan')
        }
      ]
    end

    def job_links
      UINotifications::URLResolver.new(
        subject,
        :links => [{
          :path_method => :job_invocation_path,
          :title => _('Job Details')
        }]
      ).actions[:links]
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
foreman_ansible-13.0.7 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.5 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-14.0.0 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.4 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.3 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.2 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.1 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-13.0.0 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.7 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-10.4.4 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-7.1.8 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.6 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.5 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-10.4.3 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.4 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-10.4.2 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.3 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.2 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.1 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-12.0.0 app/services/foreman_ansible/insights_notification_builder.rb