Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions app/models/concerns/foreman_remote_execution/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ def self.prepended(base)

def search_by_job_invocation(key, operator, value)
if key == 'job_invocation.result'
operator = operator == '=' ? 'IN' : 'NOT IN'
value = TemplateInvocation::TaskResultMap.status_to_task_result(value)
end
in_operator = operator == '=' ? 'IN' : 'NOT IN'
task_results = TemplateInvocation::TaskResultMap.status_to_task_result(value)
subquery = TemplateInvocation.joins(:run_host_job_task)
.where.not(host_id: nil)
.where("#{ForemanTasks::Task.table_name}.result IN (?)", task_results)
.select(:host_id)

{ :conditions => "#{Host.table_name}.id #{in_operator} (#{subquery.to_sql})" }
else
subquery = TemplateInvocation.where.not(host_id: nil)
.where("job_invocation_id #{operator} ?", value_to_sql(operator, value))
.select(:host_id)

mapping = {
'job_invocation.id' => %(#{TemplateInvocation.table_name}.job_invocation_id #{operator} ?),
'job_invocation.result' => %(#{ForemanTasks::Task.table_name}.result #{operator} (?)),
}
{
:conditions => sanitize_sql_for_conditions([mapping[key], value_to_sql(operator, value)]),
:joins => { :template_invocations => [:run_host_job_task] },
}
{ :conditions => "#{Host.table_name}.id IN (#{subquery.to_sql})" }
end
end
end
end
Expand Down
Loading