Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36569 - List only supported Job Templates on upstream #650

Merged
merged 1 commit into from Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions db/seeds.d/75_job_templates.rb
Expand Up @@ -2,6 +2,16 @@

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

template_files = Dir[File.join("#{ForemanAnsible::Engine.root}/app/views/foreman_ansible/job_templates/**/*.erb")]

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

User.as_anonymous_admin do
RemoteExecutionFeature.without_auditing do
if Rails.env.test? || Foreman.in_rake?
Expand All @@ -13,8 +23,7 @@
ForemanAnsible::Engine.register_rex_feature
end
JobTemplate.without_auditing do
Dir[File.join("#{ForemanAnsible::Engine.root}/app/views/foreman_ansible/"\
'job_templates/**/*.erb')].each do |template|
template_files.reject { |template| unsupported_templates.value?(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 +32,13 @@
template.organizations = organizations if template.present?
template.locations = locations if template.present?
end

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

if unsupported_templates_in_db.any?
unsupported_templates_in_db.update_all(locked: false)
unsupported_templates_in_db.destroy_all
end
end
end
end