Sha256: 0f4eef9e8bdcd94df856ceec1908a48c118814397331d7402dfe5ac289d1c70a

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

class TailoringFilesController < ApplicationController
  include Foreman::Controller::AutoCompleteSearch
  include Foreman::Controller::Parameters::TailoringFile

  before_filter :find_tailoring_file, :only => [:destroy, :update, :edit, :xml]
  before_filter :handle_file_upload, :only => [:create, :update]

  def model_of_controller
    ::ForemanOpenscap::TailoringFile
  end

  def index
    @tailoring_files = resource_base.search_for(params[:search], :order => params[:order]).
                       paginate(:page => params[:page], :per_page => params[:per_page])
  end

  def new
    @tailoring_file = ::ForemanOpenscap::TailoringFile.new
  end

  def create
    @tailoring_file = ForemanOpenscap::TailoringFile.new(tailoring_file_params)
    if @tailoring_file.save
      process_success
    else
      process_error
    end
  end

  def edit
  end

  def update
    if @tailoring_file.update_attributes(tailoring_file_params)
      process_success
    else
      process_error
    end
  end

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

  def xml
    send_data @tailoring_file.scap_file,
              :type     => 'application/xml',
              :filename => @tailoring_file.original_filename || "#{@tailoring_file.name}.xml"
  end

  private

  def find_tailoring_file
    @tailoring_file = resource_base.find(params[:id])
  end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_openscap-0.7.1 app/controllers/tailoring_files_controller.rb
foreman_openscap-0.6.7 app/controllers/tailoring_files_controller.rb
foreman_openscap-0.7.0 app/controllers/tailoring_files_controller.rb
foreman_openscap-0.6.6 app/controllers/tailoring_files_controller.rb
foreman_openscap-0.6.5 app/controllers/tailoring_files_controller.rb
foreman_openscap-0.6.4 app/controllers/tailoring_files_controller.rb