Sha256: 69e0d77b88cdcffbef93a91a3a1dbf79081f0877517b3f052e22632f9d47a578

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

module ForemanAnsible
  # A class that builds custom notificaton for REX job if it's insights
  # remediation feature
  # rubocop:disable LineLength
  class InsightsNotificationBuilder < ::UINotifications::RemoteExecutionJobs::BaseJobFinish
    # rubocop:enable LineLength
    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

17 entries across 17 versions & 1 rubygems

Version Path
foreman_ansible-2.2.14 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.13 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.12 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.11 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.10 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.9 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.8 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.7 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.6 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.5 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.4 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.3 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.2 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.1 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.2.0 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.1.2 app/services/foreman_ansible/insights_notification_builder.rb
foreman_ansible-2.1.1 app/services/foreman_ansible/insights_notification_builder.rb