Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs #28538 - Drop smart_variable left overs #7511

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 5 additions & 45 deletions app/controllers/concerns/api/v2/lookup_keys_common_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ module Api::V2::LookupKeysCommonController
before_action :find_smart_class_parameters, :if => :smart_class_parameter_id?
before_action :find_smart_class_parameter, :if => :smart_class_parameter_id?

before_action :find_smart_variables, :if => :smart_variable_id?
before_action :find_smart_variable, :if => :smart_variable_id?

before_action :find_smarts
before_action :find_smart

Expand All @@ -21,10 +18,6 @@ module Api::V2::LookupKeysCommonController
before_action :cast_default_value, :only => [:create, :update]
end

def smart_variable_id?
params.key?('smart_variable_id') || controller_name.match(/smart_variables/)
end

def smart_class_parameter_id?
params.key?('smart_class_parameter_id') || controller_name.match(/smart_class_parameters/)
end
Expand All @@ -47,28 +40,6 @@ def smart_class_parameter_id?
end
end

def find_smart_variable
id = params.key?('smart_variable_id') ? params['smart_variable_id'] : params['id']
@smart_variable = VariableLookupKey.authorized(:view_external_variables).smart_variables.find_by_id(id.to_i) if id.to_i > 0
@smart_variable ||= begin
puppet_cond = { :puppetclass_id => @puppetclass.id } if @puppetclass
VariableLookupKey.authorized(:view_external_variables).smart_variables.where(puppet_cond).find_by_key(id.to_s)
end
@smart_variable
end

def find_smart_variables
@smart_variables = smart_variables_resource_scope.search_for(*search_options).paginate(paginate_options)
end

def smart_variables_resource_scope
return VariableLookupKey.authorized(:view_external_variables).smart_variables unless (@puppetclass || @host || @hostgroup)
puppetclass_ids = @puppetclass.id if @puppetclass
puppetclass_ids ||= @hostgroup.all_puppetclasses.map(&:id) if @hostgroup
puppetclass_ids ||= @host.all_puppetclasses.map(&:id) if @host
VariableLookupKey.authorized(:view_external_variables).global_parameters_for_class(puppetclass_ids)
end

def find_smart_class_parameter
id = params.key?('smart_class_parameter_id') ? params['smart_class_parameter_id'] : params['id']
@smart_class_parameter = PuppetclassLookupKey.authorized(:view_external_parameters).smart_class_parameters.find_by_id(id.to_i) if id.to_i > 0
Expand Down Expand Up @@ -106,33 +77,22 @@ def smart_class_parameters_resource_scope
end

def find_smarts
@smarts = @smart_variables
@smarts ||= @smart_class_parameters
@smarts
@smarts = @smart_class_parameters
end

def find_smart
@smart = @smart_variable
@smart ||= @smart_class_parameter
@smart
@smart = @smart_class_parameter
end

def return_if_smart_mismatch
if (@smarts && @smart && !@smarts.find_by_id(@smart.id)) || (@smarts && !@smart)
obj = smart_variable_id? ? "Smart variable" : "Smart class parameter"
id = if smart_variable_id?
params.key?('smart_variable_id') ? params['smart_variable_id'] : params['id']
else
params.key?('smart_class_parameter_id') ? params['smart_variable_id'] : params['id']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this previously appeared to have a bug. Note the mismatch.

end
not_found "#{obj} not found by id '#{id}'"
id = params.key?('smart_class_parameter_id') ? params['smart_class_parameter_id'] : params['id']
not_found "Smart class parameter not found by id '#{id}'"
end
end

def cast_default_value
obj = smart_variable_id? ? "smart_variable" : "smart_class_parameter"

cast_value(obj, :default_value)
cast_value("smart_class_parameter", :default_value)
end

def cast_value(obj = :override_value, value = :value)
Expand Down