Class: ArfReportsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ArfReportsController
- Includes:
- Foreman::Controller::AutoCompleteSearch, ForemanOpenscap::ArfReportsControllerCommonExtensions
- Defined in:
- app/controllers/arf_reports_controller.rb
Instance Method Summary collapse
- #delete_multiple ⇒ Object
- #destroy ⇒ Object
- #download_html ⇒ Object
- #index ⇒ Object
- #model_of_controller ⇒ Object
- #parse_bzip ⇒ Object
- #parse_html ⇒ Object
- #show ⇒ Object
- #show_html ⇒ Object
- #show_log ⇒ Object
- #submit_delete_multiple ⇒ Object
Methods included from ForemanOpenscap::ArfReportsControllerCommonExtensions
Instance Method Details
#delete_multiple ⇒ Object
67 68 |
# File 'app/controllers/arf_reports_controller.rb', line 67 def delete_multiple end |
#destroy ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/controllers/arf_reports_controller.rb', line 59 def destroy if @arf_report.destroy process_success(:success_msg => _("Successfully deleted ARF report."), :success_redirect => arf_reports_path) else process_error(:error_msg => _("Failed to delete ARF Report for host %{host_name} reported at %{reported_at}") % { :host_name => @arf_report.host.name, :reported_at => @arf_report.reported_at }) end end |
#download_html ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/arf_reports_controller.rb', line 48 def download_html begin response = @arf_report.to_html send_data response, :filename => "#{format_filename}.html", :type => 'text/html', :disposition => 'attachement' rescue => e process_error(:error_msg => _("Failed to downloaded ARF report in HTML: %s") % e., :error_redirect => arf_report_path(@arf_report.id)) end end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/arf_reports_controller.rb', line 12 def index # Avoid using includes() with nested associations and "order by" together. Otherwise, # includes() will use join tables instead and Rails somehow create many objects and # high memory consumption. @arf_reports_pg = resource_base.search_for(params[:search], :order => params[:order]) .paginate(:page => params[:page], :per_page => params[:per_page]) arf_report_ids = @arf_reports_pg.pluck(:id) @arf_reports = resource_base.includes(:policy, :openscap_proxy, :host => i[policies last_report_object host_statuses]) .where(id: arf_report_ids) .sort_by { |arf_report| arf_report_ids.index(arf_report.id) } end |
#model_of_controller ⇒ Object
8 9 10 |
# File 'app/controllers/arf_reports_controller.rb', line 8 def model_of_controller ::ForemanOpenscap::ArfReport end |
#parse_bzip ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/arf_reports_controller.rb', line 38 def parse_bzip begin response = @arf_report.to_bzip send_data response, :filename => "#{format_filename}.xml.bz2", :type => 'application/octet-stream', :disposition => 'attachement' rescue => e process_error(:error_msg => (_("Failed to downloaded ARF report as bzip: %s") % e.), :error_redirect => arf_report_path(@arf_report.id)) end end |
#parse_html ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/controllers/arf_reports_controller.rb', line 30 def parse_html begin self.response_body = @arf_report.to_html rescue => e render :plain => _(e.) end end |
#show ⇒ Object
24 25 |
# File 'app/controllers/arf_reports_controller.rb', line 24 def show end |
#show_html ⇒ Object
27 28 |
# File 'app/controllers/arf_reports_controller.rb', line 27 def show_html end |
#show_log ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/arf_reports_controller.rb', line 81 def show_log return not_found unless @arf_report # TODO: use Message/Log model directly instead? log = @arf_report.logs.find(params[:log_id]) return not_found unless log respond_to do |format| format.json do render json: { log: { source: log.source, message: { value: log..value, fixes: log..fixes, } }, }, status: :ok end end end |
#submit_delete_multiple ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/arf_reports_controller.rb', line 70 def submit_delete_multiple failed_deletes = @arf_reports.reject(&:destroy).count if failed_deletes > 0 process_error(:error_msg => (_("Failed to delete %s compliance reports") % failed_deletes), :error_redirect => arf_reports_path) else process_success(:success_msg => (_("Successfully deleted %s compliance reports") % @arf_reports.size), :success_redirect => arf_reports_path) end end |