Skip to content

Commit

Permalink
Fixes #36569 - List only supported Job Templates on upstream
Browse files Browse the repository at this point in the history
Update the job_templates seed file to include only supported templates.
  • Loading branch information
nofaralfasi committed Jul 24, 2023
1 parent 5b44890 commit 8bd9f15
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion db/seeds.d/75_job_templates.rb
Expand Up @@ -2,6 +2,11 @@

organizations = Organization.unscoped.all
locations = Location.unscoped.all

unsupported_templates = Foreman::Plugin.find('foreman_theme_satellite').present? ?
{ 'Smart Proxy Upgrade Playbook': 'smart_proxy_upgrade_-_ansible_default.erb' } :
{ 'Capsule Upgrade Playbook': 'capsule_upgrade_-_ansible_default.erb' }

User.as_anonymous_admin do
RemoteExecutionFeature.without_auditing do
if Rails.env.test? || Foreman.in_rake?
Expand All @@ -14,7 +19,9 @@
end
JobTemplate.without_auditing do
Dir[File.join("#{ForemanAnsible::Engine.root}/app/views/foreman_ansible/"\
'job_templates/**/*.erb')].each do |template|
'job_templates/**/*.erb')].reject { |template|
unsupported_templates.values.include?(File.basename(template)) }.each do |template|

sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
template = JobTemplate.import_raw!(File.read(template),
:default => true,
Expand All @@ -23,6 +30,13 @@
template.organizations = organizations if template.present?
template.locations = locations if template.present?
end

unsupported_existed_templates = JobTemplate.where(name: unsupported_templates.keys)

unless unsupported_existed_templates.empty?
unsupported_existed_templates.update_all(locked: false)
unsupported_existed_templates.destroy_all
end
end
end
end

0 comments on commit 8bd9f15

Please sign in to comment.