Skip to content

Commit

Permalink
Fixes #37567 - Remove OVAL related permissions from DB
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jun 19, 2024
1 parent a4230aa commit eec42af
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db/migrate/20240617105409_remove_oval_permissions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class RemoveOvalPermissions < ActiveRecord::Migration[6.1]
def up
['ForemanOpenscap::OvalPolicy', 'ForemanOpenscap::OvalContent', 'ForemanOpenscap::Cve'].each do |resource_type|
Permission.where(resource_type: resource_type).each do |permission|
# Filter has before_destroy check if it belongs to a locked role (e.g. default one). Since this is a cleanup, we don't care.
permission.filters.delete_all
# Permission should remove Filterings on destroy
permission.destroy
end
end
# Not a permission, but still a leftover from OVAL removal
if ForemanOpenscap.with_remote_execution?
oval_feature = RemoteExecutionFeature.find_by(label: 'foreman_openscap_run_oval_scans')
oval_scan_template = Template.find_by(name: 'Run OVAL scans')
TemplateInvocation.where(template_id: oval_scan_template&.id).delete_all
JobInvocation.where(remote_execution_feature_id: oval_feature&id).delete_all
TemplateInput.where(template_id: oval_scan_template&.id).delete_all
oval_feature&.destroy
oval_scan_template&.delete
end
end
end

0 comments on commit eec42af

Please sign in to comment.