Sha256: 54bdac11e439702a8ff14fd0c430a84caad9b560a04f70b23dff427dc5e6f45f

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 KB

Contents

class DiscoveryRulesController < ApplicationController
  # Two-pane searching must be disabled for rules otherwise query completion will not work
  #include Foreman::Controller::AutoCompleteSearch

  include Foreman::Controller::Parameters::DiscoveryRule

  before_action :find_resource, :only => [:edit, :update, :destroy, :enable, :disable, :auto_provision]

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

  def new
    @discovery_rule = DiscoveryRule.new(:priority => DiscoveryRule.suggest_priority)
  end

  def create
    @discovery_rule = DiscoveryRule.new(discovery_rule_params)
    if @discovery_rule.save
      process_success
    else
      process_error
    end
  end

  def edit
  end

  def update
    if @discovery_rule.update_attributes(discovery_rule_params)
      process_success
    else
      process_error
    end
  end

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

  def enable
    set_enabled true
  end

  def disable
    set_enabled false
  end

  private

  def action_permission
    case params[:action]
    when 'enable', 'disable'
      :edit
    else
      super
    end
  end

  def set_enabled(enabled)
    @discovery_rule.enabled = enabled
    if @discovery_rule.save
      process_success :success_msg => (enabled ? _('Rule enabled') : _('Rule disabled')), :success_redirect => :back
    else
      process_error
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
foreman_discovery-16.0.1 app/controllers/discovery_rules_controller.rb
foreman_discovery-16.0.0 app/controllers/discovery_rules_controller.rb
foreman_discovery-15.1.0 app/controllers/discovery_rules_controller.rb
foreman_discovery-15.0.2 app/controllers/discovery_rules_controller.rb
foreman_discovery-15.0.1 app/controllers/discovery_rules_controller.rb
foreman_discovery-15.0.0 app/controllers/discovery_rules_controller.rb
foreman_discovery-14.0.1 app/controllers/discovery_rules_controller.rb
foreman_discovery-14.0.0 app/controllers/discovery_rules_controller.rb
foreman_discovery-13.0.1 app/controllers/discovery_rules_controller.rb
foreman_discovery-12.0.2 app/controllers/discovery_rules_controller.rb