Class: TemplateInvocationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- TemplateInvocationsController
show all
- Includes:
- Foreman::Controller::AutoCompleteSearch, JobInvocationsHelper, RemoteExecutionHelper
- Defined in:
- app/controllers/template_invocations_controller.rb
Instance Method Summary
collapse
#collapsed_preview, #input_safe_value, #minicard, #preview_hosts, #show_job_location, #show_job_organization, #template_name_and_provider_link
#description_checkbox_f, #description_format_help, #description_format_textarea_f, #documentation_button_rex, #host_counter, #host_tasks_authorizer, #invocation_count, #invocation_description, #invocation_result, #job_hosts_authorizer, #job_invocation_task_buttons, #job_invocations_buttons, #job_report_template, #job_report_template_parameters, #link_to_invocation_task_if_authorized, #load_template_from_task, #normalize_line_sets, #preview_box, #providers_options, #remote_execution_provider_for, #targeting_hosts, #template_invocation_actions, #template_invocation_status, #template_invocation_task_buttons, #time_in_words_span
Instance Method Details
#controller_permission ⇒ Object
9
10
11
|
# File 'app/controllers/template_invocations_controller.rb', line 9
def controller_permission
'job_invocations'
end
|
#show ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/template_invocations_controller.rb', line 13
def show
@template_invocation = TemplateInvocation.find(params[:id])
raise ActiveRecord::RecordNotFound unless User.current.can?(:view_job_invocations, @template_invocation.job_invocation)
@template_invocation_task = @template_invocation.run_host_job_task
@host = @template_invocation.host
@auto_refresh = @template_invocation_task.pending?
@since = params[:since].to_f if params[:since].present?
@line_sets = @template_invocation_task.main_action.live_output
@line_sets = @line_sets.drop_while { |o| o['timestamp'].to_f <= @since } if @since
@line_counter = params[:line_counter].to_i
end
|
#show_template_invocation_by_host ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/template_invocations_controller.rb', line 26
def show_template_invocation_by_host
@template_invocation = @job_invocation.template_invocations.find { |template_inv| template_inv.host_id == @host.id }
if @template_invocation.nil?
render :json => { :error => _('Template invocation not found') }, :status => :not_found
end
@template_invocation_task = @template_invocation.run_host_job_task
lines = normalize_line_sets(@template_invocation_task.main_action.live_output)
transformed_input_values = @template_invocation.input_values.joins(:template_input).map do |input_value|
{
name: input_value&.template_input&.name,
value: input_safe_value(input_value),
}
end
auto_refresh = @job_invocation.task.try(:pending?)
finished = @job_invocation.status_label == 'failed' || @job_invocation.status_label == 'succeeded' || @job_invocation.status_label == 'cancelled'
render :json => { :output => lines, :preview => template_invocation_preview(@template_invocation, @host), :input_values => transformed_input_values, :job_invocation_description => @job_invocation.description, :task_id => @template_invocation_task.id, :task_cancellable => @template_invocation_task.cancellable?, :host_name => @host.name, :permissions => {
:view_foreman_tasks => User.current.allowed_to?(:view_foreman_tasks),
:cancel_job_invocations => User.current.allowed_to?(:cancel_job_invocations),
:execute_jobs => User.current.allowed_to?(:create_job_invocations) && (!@host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts)),
},
:auto_refresh => auto_refresh, :finished => finished}, status: :ok
end
|