Project

General

Profile

« Previous | Next » 

Revision 221fd050

Added by Tom Caspy over 8 years ago

fixes #9108 - parent parameters are now overrideable

View differences:

app/controllers/hostgroups_controller.rb
before_filter :find_resource, :only => [:nest, :clone, :edit, :update, :destroy]
before_filter :ajax_request, :only => [:process_hostgroup, :current_parameters, :puppetclass_parameters]
before_filter :taxonomy_scope, :only => [:new, :edit, :process_hostgroup]
before_filter :update_parent_params!, :only => [:update, :create]
def index
@hostgroups = resource_base.search_for(params[:search], :order => params[:order]).paginate :page => params[:page]
......
end
def update
if params[:hostgroup][:group_parameters_attributes].present?
params[:hostgroup][:group_parameters_attributes].merge(parse_parent_params(params.select { |k| k.match(/parent.*/) } ))
end
# remove from hash :root_pass if blank?
params[:hostgroup].except!(:root_pass) if params[:hostgroup][:root_pass].blank?
if @hostgroup.update_attributes(params[:hostgroup])
......
end
def parse_parent_params(parameters)
parameters.reject! { |k, v| v.empty? }
parameter_keys = parameters.select { |p| p.match(/key/) }.values
parameter_values = parameters.select { |p| p.match(/value/) }.values
parameters = {}
parameters_hash = parameter_keys.zip(parameter_values).reject{|k, v| v.blank?}
parameter_keys.zip(parameter_values).each do |key, value|
id = GroupParameter.last.id + 1
parameters[id] = { 'name' => key, 'value' => value }
parameters_hash.each_with_index do |val, i|
key, value = val[0], val[1]
id = GroupParameter.last.id + 1 + i
parameters[id] = { 'name' => key, 'value' => value, 'nested' => true } if value.present?
end
parameters
end
def update_parent_params!
parent_params = parse_parent_params(params.select { |k| k.match(/parent.*/) } )
if params[:hostgroup] && (params[:hostgroup][:group_parameters_attributes].present? || parent_params.present?)
params[:hostgroup][:group_parameters_attributes] ||= {}
params[:hostgroup][:group_parameters_attributes].merge!(parent_params)
end
end
def define_parent
if params[:hostgroup][:parent_id].present?
@parent = Hostgroup.authorized(:view_hostgroups).find(params[:hostgroup][:parent_id])

Also available in: Unified diff