Class: UiJobWizardController

Inherits:
Api::V2::BaseController
  • Object
show all
Includes:
FiltersHelper
Defined in:
app/controllers/ui_job_wizard_controller.rb

Instance Method Summary collapse

Instance Method Details

#action_permissionObject



52
53
54
# File 'app/controllers/ui_job_wizard_controller.rb', line 52

def action_permission
  :view_job_templates
end

#categoriesObject



3
4
5
6
7
8
9
10
11
# File 'app/controllers/ui_job_wizard_controller.rb', line 3

def categories
  job_categories = resource_scope(permission: action_permission)
                   .search_for("job_category ~ \"#{params[:search]}\"")
                   .where(:snippet => false)
                   .select(:job_category).distinct
                   .reorder(:job_category)
                   .pluck(:job_category)
  render :json => {:job_categories => job_categories, :with_katello => with_katello, default_category: default_category, default_template: default_template&.id}
end

#default_categoryObject



30
31
32
# File 'app/controllers/ui_job_wizard_controller.rb', line 30

def default_category
  default_template&.job_category
end

#default_templateObject



34
35
36
37
38
# File 'app/controllers/ui_job_wizard_controller.rb', line 34

def default_template
  if (setting_value = Setting['remote_execution_form_job_template'])
    JobTemplate.authorized(:view_job_templates).find_by :name => setting_value
  end
end

#job_invocationObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/ui_job_wizard_controller.rb', line 63

def job_invocation
  job = JobInvocation.authorized.find(params[:id])
  composer = JobInvocationComposer.from_job_invocation(job, params).params
  job_template_inputs = JobTemplate.authorized.find(composer[:template_invocations][0][:template_id]).template_inputs_with_foreign
  job_template_inputs_hash = Hash[job_template_inputs.map { |input| ["inputs[#{input[:name]}]", {:advanced => input[:advanced], :value => (composer[:template_invocations][0][:input_values].find { |value| value[:template_input_id] == input[:id] }).try(:[], :value)}] }]
  provider_inputs = composer[:template_invocations][0][:provider_input_values]
  provider_inputs_hash = Hash[provider_inputs.map { |input| ["inputs[#{input[:name]}]", {:advanced => true, :value => input[:value]}] }]
  inputs = job_template_inputs_hash.merge(provider_inputs_hash)
  job_organization = Taxonomy.find_by(id: job.task.input[:current_organization_id])
  job_location = Taxonomy.find_by(id: job.task.input[:current_location_id])
  render :json => {
    :job => composer,
    :job_organization => job_organization,
    :job_location => job_location,
    :inputs => inputs,
  }
end

#map_template_inputs(template_inputs_with_foreign) ⇒ Object



26
27
28
# File 'app/controllers/ui_job_wizard_controller.rb', line 26

def map_template_inputs(template_inputs_with_foreign)
  template_inputs_with_foreign.map { |input| input.attributes.merge({:resource_type_tableize => input.resource_type&.tableize }) }
end

#resource_classObject



48
49
50
# File 'app/controllers/ui_job_wizard_controller.rb', line 48

def resource_class
  JobTemplate
end

#resource_name(nested_resource = nil) ⇒ Object



40
41
42
# File 'app/controllers/ui_job_wizard_controller.rb', line 40

def resource_name(nested_resource = nil)
  nested_resource || 'job_template'
end

#resourcesObject



56
57
58
59
60
61
# File 'app/controllers/ui_job_wizard_controller.rb', line 56

def resources
  resource_type = params[:resource]
  resource_list = resource_type.constantize.authorized("view_#{resource_type.underscore.pluralize}").all.map { |r| {:name => r.to_s, :id => r.id } }.select { |v| v[:name] =~ /#{params[:name]}/ }
  render :json => { :results =>
    resource_list.sort_by { |r| r[:name] }.take(100), :subtotal => resource_list.count}
end

#templateObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/ui_job_wizard_controller.rb', line 13

def template
  job_template = JobTemplate.authorized.find(params[:id])
  advanced_template_inputs, template_inputs = map_template_inputs(job_template.template_inputs_with_foreign).partition { |x| x["advanced"] }
  provider_inputs = job_template.provider.provider_inputs.map { |input| input.instance_values.merge({:provider_input => true, default: input.value }) }
  render :json => {
    :job_template => job_template,
    :effective_user => job_template.effective_user,
    :template_inputs => template_inputs,
    :provider_name => job_template.provider.provider_input_namespace,
    :advanced_template_inputs => advanced_template_inputs+provider_inputs,
  }
end

#with_katelloObject



44
45
46
# File 'app/controllers/ui_job_wizard_controller.rb', line 44

def with_katello
  ::Foreman::Plugin.installed? 'katello'
end