Project

General

Profile

« Previous | Next » 

Revision 0afb9e99

Added by Dominic Cleal over 7 years ago

fixes #17395 - use admin user for load_template_vars

When `load_template_vars` is called from before_action, the current user
must already be set to ensure caching of parameters inside Host#params
is done with consistent permissions. Otherwise when Foreman::Renderer's
kickstart_attributes (or similar) renders a ptable that uses params,
the method will cache an empty parameters hash.

(cherry picked from commit f8a2b268619722b7b696ab5ab000d2b0e5ae42df)

View differences:

app/controllers/unattended_controller.rb
alias_method_chain f, :unattended
end
before_action :set_admin_user, :unless => Proc.new { preview? }
# We want to find out our requesting host
before_action :get_host_details, :allowed_to_install?, :except => :hostgroup_template
before_action :handle_ca, :if => Proc.new { params[:kind] == 'provision' }
......
before_action :load_template_vars, :only => :host_template
# all of our requests should be returned in text/plain
after_action :set_content_type
before_action :set_admin_user, :only => :built
# this actions is called by each operatingsystem post/finish script - it notify us that the OS installation is done.
def built
......
type = 'iPXE' if type == 'gPXE'
if (config = @host.provisioning_template({ :kind => type }))
if !preview?
User.as_anonymous_admin do
safe_render config
end
else
safe_render config
end
safe_render config
else
error_message = N_("unable to find %{type} template for %{host} running %{os}")
render_custom_error(:not_found, error_message, {:type => type, :host => @host.name, :os => @host.operatingsystem})

Also available in: Unified diff