Module: ForemanOpenscap::PolicyExtensions
- Extended by:
- ActiveSupport::Concern
- Includes:
- Authorizable, Taxonomix
- Defined in:
- app/models/concerns/foreman_openscap/policy_extensions.rb
Instance Method Summary collapse
- #assign_hosts(hosts) ⇒ Object
- #current_step ⇒ Object
- #first_step? ⇒ Boolean
- #hostgroup_ids ⇒ Object
- #hostgroup_ids=(ids) ⇒ Object
- #hostgroups ⇒ Object
- #hostgroups=(hostgroups) ⇒ Object
- #last_step? ⇒ Boolean
- #next_step ⇒ Object
- #previous_step ⇒ Object
- #rewind_step ⇒ Object
- #scan_name ⇒ Object
- #step_index ⇒ Object
- #steps ⇒ Object
- #to_enc ⇒ Object
- #used_hostgroup_ids ⇒ Object
- #used_location_ids ⇒ Object
- #used_organization_ids ⇒ Object
- #wizard_completed? ⇒ Boolean
Instance Method Details
#assign_hosts(hosts) ⇒ Object
128 129 130 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 128 def assign_hosts(hosts) assign_assets hosts.map &:get_asset end |
#current_step ⇒ Object
76 77 78 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 76 def current_step @current_step || steps.first end |
#first_step? ⇒ Boolean
92 93 94 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 92 def first_step? current_step == steps.first end |
#hostgroup_ids ⇒ Object
49 50 51 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 49 def hostgroup_ids assets.where(:assetable_type => 'Hostgroup').pluck(:assetable_id) end |
#hostgroup_ids=(ids) ⇒ Object
53 54 55 56 57 58 59 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 53 def hostgroup_ids=(ids) hostgroup_assets = [] ids.reject(&:empty?).map do |id| hostgroup_assets << assets.where(:assetable_type => 'Hostgroup', :assetable_id => id).first_or_create! end self.assets = hostgroup_assets end |
#hostgroups ⇒ Object
61 62 63 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 61 def hostgroups Hostgroup.find(hostgroup_ids) end |
#hostgroups=(hostgroups) ⇒ Object
65 66 67 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 65 def hostgroups=(hostgroups) hostgroup_ids = hostgroups.map(&:id).map(&:to_s) end |
#last_step? ⇒ Boolean
96 97 98 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 96 def last_step? current_step == steps.last end |
#next_step ⇒ Object
84 85 86 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 84 def next_step steps[steps.index(current_step) + 1 ] end |
#previous_step ⇒ Object
80 81 82 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 80 def previous_step steps[steps.index(current_step) - 1] end |
#rewind_step ⇒ Object
88 89 90 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 88 def rewind_step @current_step = previous_step end |
#scan_name ⇒ Object
108 109 110 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 108 def scan_name name end |
#step_index ⇒ Object
104 105 106 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 104 def step_index wizard_completed? ? steps.index(steps.last) : steps.index(current_step) + 1 end |
#steps ⇒ Object
69 70 71 72 73 74 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 69 def steps base_steps = ['Create policy', 'SCAP Content', 'Schedule'] base_steps << 'Locations' if SETTINGS[:locations_enabled] base_steps << 'Organizations' if SETTINGS[:organizations_enabled] base_steps << 'Hostgroups' #always be last. end |
#to_enc ⇒ Object
132 133 134 135 136 137 138 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 132 def to_enc { 'id' => self.id, 'profile_id' => self.scap_content_profile.try(:profile_id) || '', 'content_path' => "/var/lib/openscap/content/#{self.scap_content.digest}.xml", }.merge(period_enc) end |
#used_hostgroup_ids ⇒ Object
124 125 126 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 124 def used_hostgroup_ids [] end |
#used_location_ids ⇒ Object
112 113 114 115 116 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 112 def used_location_ids Location.joins(:taxable_taxonomies).where( 'taxable_taxonomies.taxable_type' => 'Scaptimony::Policy', 'taxable_taxonomies.taxable_id' => id).pluck("#{Location.arel_table.name}.id") end |
#used_organization_ids ⇒ Object
118 119 120 121 122 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 118 def used_organization_ids Organization.joins(:taxable_taxonomies).where( 'taxable_taxonomies.taxable_type' => 'Scaptimony::Policy', 'taxable_taxonomies.taxable_id' => id).pluck("#{Location.arel_table.name}.id") end |
#wizard_completed? ⇒ Boolean
100 101 102 |
# File 'app/models/concerns/foreman_openscap/policy_extensions.rb', line 100 def wizard_completed? new_record? && current_step.blank? end |