Class: Api::V2::PreupgradeReportEntriesController

Inherits:
BaseController
  • Object
show all
Includes:
ApiAuthorizer, Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/api/v2/preupgrade_report_entries_controller.rb

Instance Method Summary collapse

Instance Method Details

#bulk_remediateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/api/v2/preupgrade_report_entries_controller.rb', line 33

def bulk_remediate
  entries = filtered_remediation_entries
  remediation_ids = entries.pluck(:id)

  if remediation_ids.empty?
    return render json: { error: _('No fixable entries found matching the selection.') },
      status: :unprocessable_entity
  end

  composer = JobInvocationComposer.for_feature(
    'leapp_remediation_plan',
    target_host_ids(entries),
    { 'remediation_ids' => remediation_ids.join(',') }
  )
  composer.trigger!
  job_invocation = composer.job_invocation

  render json: { id: job_invocation.id }
rescue StandardError => e
  Foreman::Logging.exception('Failed to trigger bulk remediation job', e)
  render json: { error: _('An unexpected error occurred while creating the remediation job.') },
    status: :internal_server_error
end

#indexObject



18
19
20
21
22
# File 'app/controllers/api/v2/preupgrade_report_entries_controller.rb', line 18

def index
  @total = resource_scope.count
  @preupgrade_report_entries = resource_scope_for_index
  @subtotal = @preupgrade_report_entries.total_entries
end