Class: InsightsCloud::HitsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/insights_cloud/hits_controller.rb

Instance Method Summary collapse

Instance Method Details

#action_permissionObject



56
57
58
59
60
61
62
63
# File 'app/controllers/insights_cloud/hits_controller.rb', line 56

def action_permission
  case params[:action]
  when 'resolutions'
    'view'
  else
    super
  end
end

#controller_permissionObject



52
53
54
# File 'app/controllers/insights_cloud/hits_controller.rb', line 52

def controller_permission
  :insights_hits
end

#indexObject



5
6
7
8
9
10
11
12
# File 'app/controllers/insights_cloud/hits_controller.rb', line 5

def index
  hits = resource_base_search_and_page.preload(:host, :rule)

  render json: {
    hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, has_playbook: hit.has_playbook?, host_uuid: hit.host_uuid) },
    itemCount: hits.count,
  }, status: :ok
end

#model_of_controllerObject



44
45
46
# File 'app/controllers/insights_cloud/hits_controller.rb', line 44

def model_of_controller
  ::InsightsHit
end

#resolutionsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/insights_cloud/hits_controller.rb', line 29

def resolutions
  if remediation_all_selected_param
    hits = resource_base.with_playbook.search_for(params[:query])
  else
    hits = resource_base_search_and_page.with_playbook.where(id: remediation_ids_param)
  end

  hits.preload(:host, rule: :resolutions)

  render json: {
    hits: hits.map { |hit| hit.attributes.merge(hostname: hit.host&.name, resolutions: hit.rule.resolutions.map(&:attributes), reboot: hit.rule.reboot_required) },
    itemCount: hits.count,
  }, status: :ok
end

#resource_classObject



48
49
50
# File 'app/controllers/insights_cloud/hits_controller.rb', line 48

def resource_class
  ::InsightsHit
end

#showObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/insights_cloud/hits_controller.rb', line 14

def show
  host = Host.where(id: host_id_param).first
  hits = host.insights&.hits

  unless hits
    return render json: {
      error: 'No recommendations were found for this host',
    }, status: :not_found
  end

  render json: {
    hits: hits,
  }, status: :ok
end