Revision acfbc458
Added by Marek Hulán about 10 years ago
app/controllers/smart_proxies_controller.rb | ||
---|---|---|
class SmartProxiesController < ApplicationController
|
||
before_filter :find_by_id, :only => [:edit, :update, :destroy, :ping, :refresh]
|
||
|
||
include Foreman::Controller::AutoCompleteSearch
|
||
before_filter :find_by_name, :only => [:edit, :update, :refresh, :ping, :destroy]
|
||
|
||
def index
|
||
@proxies = SmartProxy.includes(:features).paginate :page => params[:page]
|
||
@smart_proxies = resource_base.includes(:features).paginate :page => params[:page]
|
||
end
|
||
|
||
def new
|
||
@proxy = SmartProxy.new
|
||
@smart_proxy = SmartProxy.new
|
||
end
|
||
|
||
def create
|
||
@proxy = SmartProxy.new(params[:smart_proxy])
|
||
if @proxy.save
|
||
process_success :object => @proxy
|
||
@smart_proxy = SmartProxy.new(params[:smart_proxy])
|
||
if @smart_proxy.save
|
||
process_success :object => @smart_proxy
|
||
else
|
||
process_error :object => @proxy
|
||
process_error :object => @smart_proxy
|
||
end
|
||
end
|
||
|
||
... | ... | |
|
||
def ping
|
||
respond_to do |format|
|
||
format.json {render :json => errors_hash(@proxy.refresh)}
|
||
format.json {render :json => errors_hash(@smart_proxy.refresh)}
|
||
end
|
||
end
|
||
|
||
def refresh
|
||
old_features = @proxy.features
|
||
if @proxy.refresh.blank? && @proxy.save
|
||
msg = @proxy.features == old_features ? _("No changes found when refreshing features from %s.") : _("Successfully refreshed features from %s.")
|
||
process_success :object => @proxy, :success_msg => msg % @proxy.name
|
||
old_features = @smart_proxy.features
|
||
if @smart_proxy.refresh.blank? && @smart_proxy.save
|
||
msg = @smart_proxy.features == old_features ? _("No changes found when refreshing features from %s.") : _("Successfully refreshed features from %s.")
|
||
process_success :object => @smart_proxy, :success_msg => msg % @smart_proxy.name
|
||
else
|
||
process_error :object => @proxy
|
||
process_error :object => @smart_proxy
|
||
end
|
||
end
|
||
|
||
def update
|
||
if @proxy.update_attributes(params[:smart_proxy])
|
||
process_success :object => @proxy
|
||
if @smart_proxy.update_attributes(params[:smart_proxy])
|
||
process_success :object => @smart_proxy
|
||
else
|
||
process_error :object => @proxy
|
||
process_error :object => @smart_proxy
|
||
end
|
||
end
|
||
|
||
def destroy
|
||
if @proxy.destroy
|
||
process_success :object => @proxy
|
||
if @smart_proxy.destroy
|
||
process_success :object => @smart_proxy
|
||
else
|
||
process_error :object => @proxy
|
||
process_error :object => @smart_proxy
|
||
end
|
||
end
|
||
|
||
private
|
||
def find_by_id
|
||
@proxy = SmartProxy.find(params[:id])
|
||
|
||
def action_permission
|
||
case params[:action]
|
||
when 'refresh'
|
||
:edit
|
||
when 'ping'
|
||
:view
|
||
else
|
||
super
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #812 - new permissions model, user group role and nest support, role filters for better granularity
Contributions from: