Sha256: e85fa208a2eda73b961c7de45619e1c89493651fdea24b1a660990ba631f945c

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

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) }
  scope :for_organizations, ->(organization_ids) { joins(:host).where(hosts: { organization_id: organization_ids}) }

  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

37 entries across 37 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.59 app/models/insights_hit.rb
foreman_rh_cloud-9.0.58 app/models/insights_hit.rb
foreman_rh_cloud-9.0.57 app/models/insights_hit.rb
foreman_rh_cloud-10.0.1 app/models/insights_hit.rb
foreman_rh_cloud-9.0.56 app/models/insights_hit.rb
foreman_rh_cloud-9.0.55 app/models/insights_hit.rb
foreman_rh_cloud-9.0.54 app/models/insights_hit.rb
foreman_rh_cloud-9.0.53 app/models/insights_hit.rb
foreman_rh_cloud-9.0.52 app/models/insights_hit.rb
foreman_rh_cloud-8.0.52 app/models/insights_hit.rb
foreman_rh_cloud-9.0.51 app/models/insights_hit.rb
foreman_rh_cloud-8.0.51 app/models/insights_hit.rb
foreman_rh_cloud-7.0.48 app/models/insights_hit.rb
foreman_rh_cloud-7.0.47 app/models/insights_hit.rb
foreman_rh_cloud-8.0.50 app/models/insights_hit.rb
foreman_rh_cloud-8.0.49 app/models/insights_hit.rb
foreman_rh_cloud-8.0.48 app/models/insights_hit.rb
foreman_rh_cloud-8.0.47 app/models/insights_hit.rb
foreman_rh_cloud-8.0.46 app/models/insights_hit.rb
foreman_rh_cloud-6.0.45 app/models/insights_hit.rb