Sha256: 68bb6f966dda5fc68f0a080f3784b6a59c10d9457e9b97e6ad2a46da63808622

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

# UI controller for ansible roles
class AnsibleRolesController < ::ApplicationController
  include Foreman::Controller::AutoCompleteSearch

  before_action :find_resource, :only => [:destroy]
  before_action :find_proxy, :only => [:import]
  before_action :create_importer, :only => [:import, :confirm_import]
  before_action :default_order, :only => [:index]

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

  def destroy
    if @ansible_role.destroy
      process_success
    else
      process_error
    end
  end

  def import
    changed = @importer.import!
    if changed.values.all?(&:empty?)
      success no_changed_roles_message
      redirect_to ansible_roles_path
    else
      render :locals => { :changed => changed }
    end
  end

  def confirm_import
    @importer.finish_import(params[:changed].to_unsafe_h)
    success _('Import of roles successfully finished.')
    redirect_to ansible_roles_path
  end

  private

  def default_order
    params[:order] ||= 'name ASC'
  end

  def find_proxy
    return nil unless params[:proxy]
    @proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
  end

  def create_importer
    @importer = ForemanAnsible::UiRolesImporter.new(@proxy)
  end

  def no_changed_roles_message
    return _('No changes in roles detected.') if @proxy.blank?
    _('No changes in roles detected on %s.') % @proxy.name
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_ansible-2.2.14 app/controllers/ansible_roles_controller.rb
foreman_ansible-2.2.13 app/controllers/ansible_roles_controller.rb
foreman_ansible-2.2.12 app/controllers/ansible_roles_controller.rb
foreman_ansible-2.2.11 app/controllers/ansible_roles_controller.rb
foreman_ansible-2.2.6 app/controllers/ansible_roles_controller.rb