foreman_openscap 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/policies_controller.rb +8 -4
  3. data/app/models/concerns/foreman_openscap/host_extensions.rb +11 -7
  4. data/app/models/foreman_openscap/policy.rb +11 -9
  5. data/app/views/job_templates/run_openscap_scans.erb +1 -0
  6. data/app/views/policy_dashboard/_policy_reports.html.erb +1 -1
  7. data/lib/foreman_openscap/version.rb +1 -1
  8. data/locale/de/foreman_openscap.edit.po +1231 -0
  9. data/locale/de/foreman_openscap.po +3 -0
  10. data/locale/de/foreman_openscap.po.time_stamp +0 -0
  11. data/locale/en_GB/foreman_openscap.edit.po +1231 -0
  12. data/locale/en_GB/foreman_openscap.po +3 -0
  13. data/locale/en_GB/foreman_openscap.po.time_stamp +0 -0
  14. data/locale/es/foreman_openscap.edit.po +1231 -0
  15. data/locale/es/foreman_openscap.po +3 -0
  16. data/locale/es/foreman_openscap.po.time_stamp +0 -0
  17. data/locale/foreman_openscap.pot +82 -78
  18. data/locale/fr/foreman_openscap.edit.po +1231 -0
  19. data/locale/fr/foreman_openscap.po +3 -0
  20. data/locale/fr/foreman_openscap.po.time_stamp +0 -0
  21. data/locale/gl/foreman_openscap.edit.po +1231 -0
  22. data/locale/gl/foreman_openscap.po +3 -0
  23. data/locale/gl/foreman_openscap.po.time_stamp +0 -0
  24. data/locale/it/foreman_openscap.edit.po +1231 -0
  25. data/locale/it/foreman_openscap.po +3 -0
  26. data/locale/it/foreman_openscap.po.time_stamp +0 -0
  27. data/locale/ja/foreman_openscap.edit.po +1231 -0
  28. data/locale/ja/foreman_openscap.po +3 -0
  29. data/locale/ja/foreman_openscap.po.time_stamp +0 -0
  30. data/locale/ko/foreman_openscap.edit.po +1231 -0
  31. data/locale/ko/foreman_openscap.po +3 -0
  32. data/locale/ko/foreman_openscap.po.time_stamp +0 -0
  33. data/locale/pt_BR/foreman_openscap.edit.po +1231 -0
  34. data/locale/pt_BR/foreman_openscap.po +3 -0
  35. data/locale/pt_BR/foreman_openscap.po.time_stamp +0 -0
  36. data/locale/ru/foreman_openscap.edit.po +1232 -0
  37. data/locale/ru/foreman_openscap.po +3 -0
  38. data/locale/ru/foreman_openscap.po.time_stamp +0 -0
  39. data/locale/sv_SE/foreman_openscap.edit.po +1231 -0
  40. data/locale/sv_SE/foreman_openscap.po +3 -0
  41. data/locale/sv_SE/foreman_openscap.po.time_stamp +0 -0
  42. data/locale/zh_CN/foreman_openscap.edit.po +1231 -0
  43. data/locale/zh_CN/foreman_openscap.po +3 -0
  44. data/locale/zh_CN/foreman_openscap.po.time_stamp +0 -0
  45. data/locale/zh_TW/foreman_openscap.edit.po +1231 -0
  46. data/locale/zh_TW/foreman_openscap.po +3 -0
  47. data/locale/zh_TW/foreman_openscap.po.time_stamp +0 -0
  48. data/test/unit/arf_report_test.rb +21 -0
  49. data/test/unit/concerns/host_extensions_test.rb +8 -0
  50. data/test/unit/openscap_host_test.rb +14 -2
  51. data/test/unit/policy_test.rb +8 -0
  52. metadata +63 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2bb650d43ac1e63a3a59875b4f699aaa85c3f147
4
- data.tar.gz: 1df85b65c444c8374458776bd3bd608bf2cda0d6
2
+ SHA256:
3
+ metadata.gz: 0b6304ecdc7fd28bb61ee2274acf8bf5a281bad437a67aa4b0fbe8214b438432
4
+ data.tar.gz: e7545538f9f374458f0b1d3b365367bf21532971d2043068fd83b3b7afbe7db8
5
5
  SHA512:
6
- metadata.gz: 5efb6c2e817057e687acf1ee59e33f3ec8ec2cd6efe5665251d985af370d6b1d399284cc9c08fcff534b5635e42664b20e80f8abca2d44ddcc574e178c967abd
7
- data.tar.gz: 369139267348ea91d46c7dbd0f6950a40f68474109dee88e0366f9dbc0e874697e37c862e0d09050c850ca849942c1eb378c102b64928770fd558c0fde0dd74f
6
+ metadata.gz: 8206badfe4852a6a74ba2ced8aeb863f1fdb09383b4522c92604eb255fed2ee0fbe98bb3544b81be75969de2b581c2123ad5619f01f9e324e30f081a7224239f
7
+ data.tar.gz: baf9118c0c690b4c446f565848848cd11368345c59bcd44b44b4e443f387ba26c631e173d352cdc5de150a2cd792bad3cadb55b292c325cd7c93642e88eaf47d
@@ -79,10 +79,14 @@ class PoliciesController < ApplicationController
79
79
  def update_multiple_hosts
80
80
  if (id = params['policy']['id'])
81
81
  policy = ::ForemanOpenscap::Policy.find(id)
82
- policy.assign_hosts(@hosts)
83
- success _("Updated hosts: Assigned with compliance policy: %s") % policy.name
84
- # We prefer to go back as this does not lose the current search
85
- redirect_to hosts_path
82
+ policy.host_ids = policy.host_ids + @hosts.pluck(:id)
83
+ if policy.save
84
+ success _("Updated hosts: Assigned with compliance policy: %s") % policy.name
85
+ # We prefer to go back as this does not lose the current search
86
+ return redirect_to hosts_path
87
+ else
88
+ return process_error :object => policy, :redirect => hosts_path
89
+ end
86
90
  else
87
91
  error _('No compliance policy selected.')
88
92
  redirect_to(select_multiple_hosts_policies_path)
@@ -9,6 +9,8 @@ module ForemanOpenscap
9
9
  base.has_many :arf_reports, :class_name => '::ForemanOpenscap::ArfReport', :foreign_key => :host_id
10
10
  base.has_one :compliance_status_object, :class_name => '::ForemanOpenscap::ComplianceStatus', :foreign_key => 'host_id'
11
11
 
12
+ base.validate :openscap_proxy_in_taxonomy, :if => Proc.new { |host| host.openscap_proxy_id.present? }
13
+
12
14
  base.scoped_search :relation => :policies, :on => :name, :complete_value => true, :rename => :compliance_policy,
13
15
  :only_explicit => true, :operators => ['= '], :ext_method => :search_by_policy_name
14
16
 
@@ -121,13 +123,11 @@ module ForemanOpenscap
121
123
  end
122
124
 
123
125
  def reports_for_policy(policy, limit = nil)
124
- if limit
125
- ForemanOpenscap::ArfReport.joins(:policy_arf_report)
126
- .merge(ForemanOpenscap::PolicyArfReport.of_policy(policy.id)).where(:host_id => id).limit limit
127
- else
128
- ForemanOpenscap::ArfReport.joins(:policy_arf_report)
129
- .merge(ForemanOpenscap::PolicyArfReport.of_policy(policy.id)).where(:host_id => id)
130
- end
126
+ report_scope = ForemanOpenscap::ArfReport.unscoped.joins(:policy_arf_report)
127
+ .merge(ForemanOpenscap::PolicyArfReport.of_policy(policy.id)).where(:host_id => id)
128
+ .order("#{ForemanOpenscap::ArfReport.table_name}.created_at DESC")
129
+ report_scope = report_scope.limit(limit) if limit
130
+ report_scope
131
131
  end
132
132
 
133
133
  def compliance_status(options = {})
@@ -138,6 +138,10 @@ module ForemanOpenscap
138
138
  @compliance_status_label ||= get_status(ForemanOpenscap::ComplianceStatus).to_label(options)
139
139
  end
140
140
 
141
+ def openscap_proxy_in_taxonomy
142
+ validate_association_taxonomy(:openscap_proxy)
143
+ end
144
+
141
145
  module ClassMethods
142
146
  def search_by_removed_from_policy(key, operator, policy_name)
143
147
  policy = ForemanOpenscap::Policy.find_by :name => policy_name
@@ -36,7 +36,7 @@ module ForemanOpenscap
36
36
  validates :scap_content_id, presence: true, if: Proc.new { |policy| policy.should_validate?('SCAP Content') }
37
37
  validate :matching_content_profile, if: Proc.new { |policy| policy.should_validate?('SCAP Content') }
38
38
 
39
- validate :valid_cron_line, :valid_weekday, :valid_day_of_month, :valid_tailoring, :valid_tailoring_profile
39
+ validate :valid_cron_line, :valid_weekday, :valid_day_of_month, :valid_tailoring, :valid_tailoring_profile, :no_mixed_deployments
40
40
  after_save :assign_policy_to_hostgroups
41
41
  # before_destroy - ensure that the policy has no hostgroups, or classes
42
42
 
@@ -46,10 +46,6 @@ module ForemanOpenscap
46
46
  end
47
47
  end
48
48
 
49
- def assign_assets(a)
50
- self.asset_ids = (self.asset_ids + a.collect(&:id)).uniq
51
- end
52
-
53
49
  def to_html
54
50
  if scap_content.nil?
55
51
  return html_error_message(_('Cannot generate HTML guide, scap content is missing.'))
@@ -112,6 +108,7 @@ module ForemanOpenscap
112
108
  end
113
109
 
114
110
  def previous_step
111
+ return steps.last if current_step.empty?
115
112
  steps[steps.index(current_step) - 1]
116
113
  end
117
114
 
@@ -165,10 +162,6 @@ module ForemanOpenscap
165
162
  []
166
163
  end
167
164
 
168
- def assign_hosts(hosts)
169
- assign_assets hosts.map &:get_asset
170
- end
171
-
172
165
  def unassign_hosts(hosts)
173
166
  host_asset_ids = ForemanOpenscap::Asset.where(:assetable_type => 'Host::Base', :assetable_id => hosts.map(&:id)).pluck(:id)
174
167
  self.asset_ids = self.asset_ids - host_asset_ids
@@ -315,5 +308,14 @@ module ForemanOpenscap
315
308
  existing_assets = self.assets.where(:assetable_type => complimentary_class_name)
316
309
  self.assets = existing_assets + new_assets
317
310
  end
311
+
312
+ def no_mixed_deployments
313
+ assets.each do |asset|
314
+ assetable = asset.assetable
315
+ unless assetable.policies.pluck(:deploy_by).all? { |deployed_by| deployed_by == deploy_by }
316
+ errors.add(:base, _("cannot assign to %s, all assigned policies must be deployed in the same way") % assetable.name)
317
+ end
318
+ end
319
+ end
318
320
  end
319
321
  end
@@ -15,6 +15,7 @@ template_inputs:
15
15
  provider_type: SSH
16
16
  kind: job_template
17
17
  %>
18
+ <% raise "Create and assign a policy to this host before proceeding" unless input('policies').respond_to? :map %>
18
19
 
19
20
  <% input('policies').map { |policy_config| policy_config['id'] }.each do |id| -%>
20
21
  /usr/bin/foreman_scap_client <%= id %>
@@ -11,7 +11,7 @@
11
11
  <th><%= _("Other") %></th>
12
12
  <th><%= _('Actions') %></th>
13
13
  </tr>
14
- <% @policy.arf_reports.latest.each do |arf_report| %>
14
+ <% @latest_reports.each do |arf_report| %>
15
15
  <tr>
16
16
  <td><%= name_column(arf_report.host) %></td>
17
17
  <td><%= assigned_icon(@policy, arf_report) %></td>
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "1.0.4".freeze
2
+ VERSION = "1.0.5".freeze
3
3
  end