Skip to content

Commit

Permalink
Fixes #36953 - Fetch configured ansible tags on rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
girijaasoni committed Nov 29, 2023
1 parent acd3f7c commit 6eb921e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
12 changes: 11 additions & 1 deletion app/controllers/ui_job_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ def categories

def template
job_template = JobTemplate.authorized.find(params[:id])
provider_input_values = []
if params[:jobInvocationId]
job = JobInvocation.authorized.find(params[:jobInvocationId])
composer = JobInvocationComposer.from_job_invocation(job, params).params
provider_input_values = composer[:template_invocations][0][:provider_input_values]
end
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 }) }
provider_inputs = job_template.provider.provider_inputs(provider_input_values).map { |input| input.instance_values.merge({:provider_input => true, :default => input.value }) }
render :json => {
:job_template => job_template,
:effective_user => job_template.effective_user,
Expand Down Expand Up @@ -63,15 +69,19 @@ def resources
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_provider_inputs = composer[:template_invocations][0][:provider_input_values]
inputs = 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 = Hash[job_provider_inputs.map { |input| ["provider_inputs[#{input[:name]}]", {:provider_input => input[:provider_input], :value => input[:value]}] }]
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,
:provider_inputs => provider_inputs,
}
end
end
5 changes: 3 additions & 2 deletions app/lib/foreman_remote_execution/provider_input.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module ForemanRemoteExecution
class ProviderInput
attr_reader :name, :label, :description, :options, :value_type, :required
attr_reader :name, :label, :default, :description, :options, :value_type, :required
attr_accessor :value

def initialize(name:, label:, value:, description: nil, options: nil, value_type: nil, required: false, hidden: false)
def initialize(name:, label:, value:, default: nil, description: nil, options: nil, value_type: nil, required: false, hidden: false)
@name = name
@label = label
@value = value
@default = default
@description = description
@options = options
@value_type = value_type
Expand Down
1 change: 1 addition & 0 deletions app/models/job_invocation_composer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def template_invocations_params
job_invocation.pattern_template_invocations.map do |template_invocation|
params = template_invocation.attributes.slice('template_id', 'effective_user')
params['input_values'] = template_invocation.input_values.map { |v| v.attributes.slice('template_input_id', 'value') }
params['provider_input_values'] = template_invocation.provider_input_values.map { |v| v.attributes.slice('name', 'value') }
params
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
end
get 'cockpit/redirect', to: 'cockpit#redirect'
get 'ui_job_wizard/categories', to: 'ui_job_wizard#categories'
get 'ui_job_wizard/template/:id', to: 'ui_job_wizard#template'
get 'ui_job_wizard/template/:id(/:jobInvocationId)', to: 'ui_job_wizard#template'
get 'ui_job_wizard/resources', to: 'ui_job_wizard#resources'
get 'ui_job_wizard/job_invocation', to: 'ui_job_wizard#job_invocation'

Expand Down
4 changes: 3 additions & 1 deletion webpack/JobWizard/JobWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ export const JobWizard = ({ rerunData }) => {
dispatch(
get({
key: JOB_TEMPLATE,
url: `/ui_job_wizard/template/${jobTemplateID}`,
url: rerunData
? `/ui_job_wizard/template/${jobTemplateID}/${rerunData?.reruns}`

Check failure on line 164 in webpack/JobWizard/JobWizard.js

View workflow job for this annotation

GitHub Actions / test_js (12)

'rerunData.reruns' is missing in props validation

Check failure on line 164 in webpack/JobWizard/JobWizard.js

View workflow job for this annotation

GitHub Actions / test_js (12)

'rerunData.reruns' is missing in props validation
: `/ui_job_wizard/template/${jobTemplateID}`,
handleSuccess: rerunData
? ({
data: {
Expand Down

0 comments on commit 6eb921e

Please sign in to comment.