Class: Api::V2::HostReportsController
- Inherits:
-
V2::BaseController
- Object
- V2::BaseController
- Api::V2::HostReportsController
- Includes:
- Api::Version2, Foreman::Controller::CsvResponder, Foreman::Controller::SmartProxyAuth, ForemanHostReports::Controller::Parameters::HostReport
- Defined in:
- app/controllers/api/v2/host_reports_controller.rb
Instance Method Summary collapse
Methods included from ForemanHostReports::Controller::Parameters::HostReport
Instance Method Details
#create ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/api/v2/host_reports_controller.rb', line 50 def create params[:host_report].delete(:version) the_body = params[:host_report].delete(:body) if the_body && !the_body.is_a?(String) logger.warn "Report body not as a string, serializing JSON" the_body = JSON.pretty_generate(the_body) end keywords = params[:host_report].delete(:keywords) @host_report = HostReport.new(host_report_params.merge(body: the_body)) if keywords.present? keywords_to_insert = keywords.each_with_object([]) do |n, ks| ks << { name: n } end ReportKeyword.upsert_all(keywords_to_insert, unique_by: :name) @host_report.report_keyword_ids = ReportKeyword.where(name: keywords).distinct.pluck(:id) end result = @host_report.save @host_report.body = nil process_response result end |
#destroy ⇒ Object
73 74 75 |
# File 'app/controllers/api/v2/host_reports_controller.rb', line 73 def destroy process_response @host_report.destroy end |
#export ⇒ Object
80 81 82 83 84 |
# File 'app/controllers/api/v2/host_reports_controller.rb', line 80 def export params[:per_page] = 'all' @host_reports = resource_scope_for_index.preload(:host, :proxy) csv_response(@host_reports) end |
#index ⇒ Object
20 21 22 23 24 |
# File 'app/controllers/api/v2/host_reports_controller.rb', line 20 def index = {} .update(host_id: params[:host_id]) if params[:host_id] @host_reports = resource_scope_for_index() end |
#show ⇒ Object
28 29 30 |
# File 'app/controllers/api/v2/host_reports_controller.rb', line 28 def show @host_report = resource_scope.find(params[:id]) end |