Sha256: a233787e3a7d84b4ae44f85f11d849f2d86f9687e76cf03d3d0d7b59308b60bf

Contents?: true

Size: 1019 Bytes

Versions: 7

Compression:

Stored size: 1019 Bytes

Contents

class InsightsHit < ApplicationRecord
  include ::Authorizable
  belongs_to :host
  # since the facet is one-to-one association with a host, we can connect
  # through host_id column on both this model and facet.
  belongs_to :insights_facet, foreign_key: 'host_id', primary_key: 'host_id', counter_cache: :hits_count

  has_one :rule, class_name: 'InsightsRule', foreign_key: 'rule_id', primary_key: 'rule_id'

  scope :with_playbook, -> { joins(:rule) }

  scoped_search on: :title, complete_value: true
  scoped_search on: :total_risk, complete_value: true
  scoped_search on: :rule_id, complete_value: true, only_explicit: true
  scoped_search relation: :host, on: :name, rename: :hostname, complete_value: true
  scoped_search on: :rule_id, rename: :with_playbook, only_explicit: true, complete_value: false, ext_method: :find_with_playbook

  def self.find_with_playbook(key, operator, value)
    { joins: :rule }
  end

  def has_playbook?
    !rule.nil?
  end

  def host_uuid
    insights_facet.uuid
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_rh_cloud-5.0.35 app/models/insights_hit.rb
foreman_rh_cloud-5.0.34 app/models/insights_hit.rb
foreman_rh_cloud-5.0.33 app/models/insights_hit.rb
foreman_rh_cloud-5.0.32 app/models/insights_hit.rb
foreman_rh_cloud-5.0.31 app/models/insights_hit.rb
foreman_rh_cloud-5.0.30 app/models/insights_hit.rb
foreman_rh_cloud-5.0.29 app/models/insights_hit.rb