-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37567 - Remove OVAL related permissions from DB
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |