Sha256: 91cfe8ade2e0fc8cfa562c1c07e6f59849411e53253cc957d2a587b6faa06f7f

Contents?: true

Size: 1.5 KB

Versions: 38

Compression:

Stored size: 1.5 KB

Contents

class ScapContentsController < ApplicationController
  include Foreman::Controller::AutoCompleteSearch
  include Foreman::Controller::Parameters::ScapContent

  before_action :handle_file_upload, :only => %i[create update]
  before_action :find_by_id, :only => %i[show edit update destroy]

  def model_of_controller
    ::ForemanOpenscap::ScapContent
  end

  def index
    @contents = resource_base_search_and_page.search_for(params[:search])
  end

  def show
    send_data @scap_content.scap_file,
              :type     => 'application/xml',
              :filename => @scap_content.original_filename
  end

  def new
    @scap_content = ForemanOpenscap::ScapContent.new
  end

  def create
    @scap_content = ForemanOpenscap::ScapContent.new(scap_content_params)
    if @scap_content.save
      process_success
    else
      process_error
    end
  end

  def update
    if @scap_content.update(scap_content_params)
      process_success
    else
      process_error
    end
  end

  def destroy
    if @scap_content.destroy
      process_success
    else
      process_error :object => @scap_content
    end
  end

  private

  def find_by_id
    @scap_content = resource_base.find(params[:id])
  end

  def handle_file_upload
    return unless params[:scap_content] && scap_raw_file = params[:scap_content][:scap_file]
    params[:scap_content][:original_filename] = scap_raw_file.original_filename
    params[:scap_content][:scap_file] = scap_raw_file.tempfile.read if scap_raw_file.tempfile.respond_to?(:read)
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
foreman_openscap-10.1.0 app/controllers/scap_contents_controller.rb
foreman_openscap-10.0.3 app/controllers/scap_contents_controller.rb
foreman_openscap-10.0.2 app/controllers/scap_contents_controller.rb
foreman_openscap-10.0.1 app/controllers/scap_contents_controller.rb
foreman_openscap-10.0.0 app/controllers/scap_contents_controller.rb
foreman_openscap-9.0.4 app/controllers/scap_contents_controller.rb
foreman_openscap-9.0.3 app/controllers/scap_contents_controller.rb
foreman_openscap-9.0.2 app/controllers/scap_contents_controller.rb
foreman_openscap-9.0.1 app/controllers/scap_contents_controller.rb
foreman_openscap-9.0.0 app/controllers/scap_contents_controller.rb
foreman_openscap-8.0.0 app/controllers/scap_contents_controller.rb
foreman_openscap-7.1.1 app/controllers/scap_contents_controller.rb
foreman_openscap-7.1.0 app/controllers/scap_contents_controller.rb
foreman_openscap-7.0.0 app/controllers/scap_contents_controller.rb
foreman_openscap-6.0.0 app/controllers/scap_contents_controller.rb
foreman_openscap-5.2.3 app/controllers/scap_contents_controller.rb
foreman_openscap-5.2.2 app/controllers/scap_contents_controller.rb
foreman_openscap-5.1.1 app/controllers/scap_contents_controller.rb
foreman_openscap-5.2.1 app/controllers/scap_contents_controller.rb
foreman_openscap-5.2.0 app/controllers/scap_contents_controller.rb