From b575f80393be10680169c2b930b9bd484c9036ce Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Thu, 2 Aug 2018 13:42:04 +0200 Subject: [PATCH] Fixes #21704 - Make it work for categories containing more templates --- app/models/job_invocation_composer.rb | 8 +++++++- app/views/job_invocations/_form.html.erb | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/job_invocation_composer.rb b/app/models/job_invocation_composer.rb index b42d2da8b..fe245ee42 100644 --- a/app/models/job_invocation_composer.rb +++ b/app/models/job_invocation_composer.rb @@ -306,11 +306,11 @@ def initialize(params, set_defaults = false) @set_defaults = set_defaults @job_invocation = JobInvocation.new @job_invocation.task_group = JobInvocationTaskGroup.new + @reruns = params[:reruns] compose @host_ids = validate_host_ids(params[:host_ids]) @search_query = job_invocation.targeting.search_query if job_invocation.targeting.bookmark_id.blank? - @reruns = params[:reruns] end def self.from_job_invocation(job_invocation, params = {}) @@ -345,6 +345,8 @@ def compose job_invocation.key_passphrase = params[:key_passphrase] job_invocation.sudo_password = params[:sudo_password] + job_invocation.job_category = nil unless rerun_possible? + self end # rubocop:enable Metrics/AbcSize @@ -473,6 +475,10 @@ def job_template_ids job_invocation.pattern_template_invocations.map(&:template_id) end + def rerun_possible? + !(@reruns && job_invocation.pattern_template_invocations.empty?) + end + private # builds input values for a given templates id based on params diff --git a/app/views/job_invocations/_form.html.erb b/app/views/job_invocations/_form.html.erb index e6aebbd5a..f28427bb3 100644 --- a/app/views/job_invocations/_form.html.erb +++ b/app/views/job_invocations/_form.html.erb @@ -6,13 +6,15 @@ <%= form_for @composer.job_invocation, :html => {'data-refresh-url' => refresh_job_invocations_path, :id => 'job_invocation_form'} do |f| %> - <% if @composer.reruns && @composer.job_invocation.pattern_template_invocations.empty? %> + <% unless @composer.rerun_possible? %> <%= alert :text => _('Could not rerun job %{id} because its template could not be found') % { :id => @composer.reruns }, :class => 'alert alert-block alert-danger has-error', :close => false %> <% end %> - <%= selectable_f f, :job_category, @composer.available_job_categories, {:selected => @composer.job_invocation.job_category, :include_blank => @composer.job_invocation.job_category.nil?}, :label => _('Job category') %> + <%= selectable_f f, :job_category, @composer.available_job_categories, + { :selected => @composer.job_invocation.job_category, :include_blank => @composer.job_invocation.job_category.nil? }, + :label => _('Job category') %> <%= f.hidden_field(:remote_execution_feature_id, :value => @composer.remote_execution_feature_id) %> <% selected_templates_per_provider = {} %>