foreman_openscap 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -7
  2. data/README.md +14 -0
  3. data/app/assets/javascripts/foreman_openscap/policy_edit.js +1 -1
  4. data/app/controllers/api/v2/compliance/policies_controller.rb +12 -9
  5. data/app/controllers/api/v2/compliance/scap_contents_controller.rb +4 -2
  6. data/app/controllers/concerns/foreman/controller/parameters/policy.rb +12 -0
  7. data/app/controllers/concerns/foreman/controller/parameters/policy_api.rb +21 -0
  8. data/app/controllers/concerns/foreman/controller/parameters/scap_content.rb +15 -0
  9. data/app/controllers/policies_controller.rb +7 -3
  10. data/app/controllers/scap_contents_controller.rb +4 -2
  11. data/app/helpers/{dashboard_helper.rb → compliance_dashboard_helper.rb} +2 -2
  12. data/app/helpers/policy_dashboard_helper.rb +9 -4
  13. data/app/models/concerns/foreman_openscap/host_extensions.rb +3 -5
  14. data/app/models/concerns/foreman_openscap/hostgroup_extensions.rb +1 -1
  15. data/app/models/concerns/foreman_openscap/log_extensions.rb +0 -1
  16. data/app/models/concerns/foreman_openscap/openscap_proxy_core_extensions.rb +1 -1
  17. data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +1 -2
  18. data/app/models/foreman_openscap/arf_report.rb +6 -4
  19. data/app/models/foreman_openscap/compliance_status.rb +3 -1
  20. data/app/models/foreman_openscap/policy.rb +62 -33
  21. data/app/models/foreman_openscap/scap_content.rb +1 -3
  22. data/app/views/arf_reports/_list.html.erb +1 -1
  23. data/app/views/arf_reports/show.html.erb +4 -4
  24. data/app/views/compliance_hosts/show.html.erb +1 -1
  25. data/app/views/dashboard/_compliance_host_reports_widget.html.erb +6 -6
  26. data/app/views/policies/index.html.erb +2 -2
  27. data/app/views/policies/steps/_schedule_form.html.erb +1 -1
  28. data/app/views/policies/steps/_step_form.html.erb +1 -0
  29. data/app/views/policies/welcome.html.erb +1 -1
  30. data/app/views/policy_dashboard/index.html.erb +2 -2
  31. data/app/views/scap_contents/index.html.erb +2 -2
  32. data/app/views/scap_contents/welcome.html.erb +1 -1
  33. data/db/migrate/20160830113437_remove_deleted_policy.rb +10 -0
  34. data/db/seeds.d/openscap_policy_notification.rb +2 -0
  35. data/lib/foreman_openscap/data_migration.rb +1 -1
  36. data/lib/foreman_openscap/engine.rb +11 -1
  37. data/lib/foreman_openscap/helper.rb +4 -8
  38. data/lib/foreman_openscap/version.rb +1 -1
  39. data/locale/Makefile +60 -0
  40. data/locale/de/LC_MESSAGES/foreman_openscap.mo +0 -0
  41. data/locale/de/foreman_openscap.po +616 -0
  42. data/locale/en_GB/LC_MESSAGES/foreman_openscap.mo +0 -0
  43. data/locale/en_GB/foreman_openscap.po +616 -0
  44. data/locale/es/LC_MESSAGES/foreman_openscap.mo +0 -0
  45. data/locale/es/foreman_openscap.po +616 -0
  46. data/locale/foreman_openscap.pot +873 -0
  47. data/locale/fr/LC_MESSAGES/foreman_openscap.mo +0 -0
  48. data/locale/fr/foreman_openscap.po +616 -0
  49. data/locale/gl/LC_MESSAGES/foreman_openscap.mo +0 -0
  50. data/locale/gl/foreman_openscap.po +616 -0
  51. data/locale/it/LC_MESSAGES/foreman_openscap.mo +0 -0
  52. data/locale/it/foreman_openscap.po +616 -0
  53. data/locale/ja/LC_MESSAGES/foreman_openscap.mo +0 -0
  54. data/locale/ja/foreman_openscap.po +616 -0
  55. data/locale/ko/LC_MESSAGES/foreman_openscap.mo +0 -0
  56. data/locale/ko/foreman_openscap.po +616 -0
  57. data/locale/pt_BR/LC_MESSAGES/foreman_openscap.mo +0 -0
  58. data/locale/pt_BR/foreman_openscap.po +616 -0
  59. data/locale/ru/LC_MESSAGES/foreman_openscap.mo +0 -0
  60. data/locale/ru/foreman_openscap.po +617 -0
  61. data/locale/sv_SE/LC_MESSAGES/foreman_openscap.mo +0 -0
  62. data/locale/sv_SE/foreman_openscap.po +616 -0
  63. data/locale/zanata.xml +29 -0
  64. data/locale/zh_CN/LC_MESSAGES/foreman_openscap.mo +0 -0
  65. data/locale/zh_CN/foreman_openscap.po +616 -0
  66. data/locale/zh_TW/LC_MESSAGES/foreman_openscap.mo +0 -0
  67. data/locale/zh_TW/foreman_openscap.po +616 -0
  68. data/test/factories/policy_factory.rb +2 -2
  69. data/test/functional/api/v2/compliance/policies_controller_test.rb +7 -3
  70. data/test/test_plugin_helper.rb +35 -37
  71. data/test/unit/concerns/openscap_proxy_extenstions_test.rb +21 -0
  72. data/test/unit/openscap_host_test.rb +3 -1
  73. data/test/unit/policy_test.rb +125 -0
  74. data/test/unit/scap_content_test.rb +5 -0
  75. metadata +231 -198
@@ -6,6 +6,6 @@
6
6
  { :include_blank => _('Choose period') },
7
7
  { :onchange => 'period_selected(this)' }) %>
8
8
  <%= select_f(f, :weekday, days_of_week_hash, :first, :last, :include_blank => _('Choose weekday')) %>
9
- <%= select_f(f, :day_of_month, (1..31).to_a, :to_i, :to_s, :help_inline => _('Number of a day in month, note that not all months have same count of days')) %>
9
+ <%= select_f(f, :day_of_month, (1..31).to_a, :to_i, :to_s, :help_inline => _('Number of a day in month, note that not all months have same count of days'), :include_blank => _('Choose day in month')) %>
10
10
  <%= text_f(f, :cron_line, :help_inline => _('You can specify custom cron line, e.g. "0 3 * * *", separate each of 5 values by space')) %>
11
11
  </div>
@@ -3,6 +3,7 @@
3
3
  <%= form_for @policy,
4
4
  :url => (@policy.id? ? policy_path(:id => @policy.id) : policies_path) do |f| %>
5
5
  <%= base_errors_for @policy %>
6
+ <%= f.hidden_field(:wizard_initiated, :value => @policy.wizard_initiated?) %>
6
7
  <%= f.hidden_field(:current_step, :value => @policy.next_step) unless @policy.current_step.blank? %>
7
8
  <% @policy.steps.each do | step | %>
8
9
  <%= render :partial => "policies/steps/#{step.downcase.tr(' ', '_')}_form", :locals => {:f => f, :step => step} %>
@@ -1,4 +1,4 @@
1
- <% title_actions display_link_if_authorized(_("New Compliance Policy"), hash_for_new_policy_path) %>
1
+ <% title_actions display_link_if_authorized(_("New Compliance Policy"), hash_for_new_policy_path, :class => "btn btn-default") %>
2
2
 
3
3
  <% title _("Compliance policy configuration") %>
4
4
  <div id="welcome">
@@ -6,10 +6,10 @@
6
6
  <ul>
7
7
  <% [{:template => 'policy_status_widget', :sizex => 8, :sizey => 1, :name => N_('Status table')},
8
8
  {:template => 'policy_chart_widget', :sizex => 4, :sizey => 1, :name => N_('Status chart')}].each do |w| %>
9
- <% widget = Widget.new(w) %>
9
+ <% widget = compliance_widget(w) %>
10
10
  <%= content_tag(:li, widget_data(widget)) do %>
11
11
  <div class="widget <%= widget.name.parameterize %>">
12
- <%= render_widget(widget) %>
12
+ <%= render(:partial => widget.template, :locals => widget.data) %>
13
13
  </div>
14
14
  <% end %>
15
15
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <% title _("SCAP Contents") %>
2
2
 
3
- <% title_actions(display_link_if_authorized(_("Upload New SCAP Content"), hash_for_new_scap_content_path),
4
- link_to(_("Help"), :action => "welcome")) %>
3
+ <% title_actions(display_link_if_authorized(_("Upload New SCAP Content"), hash_for_new_scap_content_path, :class => 'btn btn-default'),
4
+ link_to(_("Help"), { :action => "welcome" }, { :class => 'btn btn-info' })) %>
5
5
 
6
6
  <%= render :partial => 'list' %>
@@ -1,4 +1,4 @@
1
- <% title_actions display_link_if_authorized(_("New SCAP content"), hash_for_new_scap_content_path) %>
1
+ <% title_actions display_link_if_authorized(_("New SCAP content"), hash_for_new_scap_content_path, :class => "btn btn-default") %>
2
2
 
3
3
  <% title _("SCAP content configuration") %>
4
4
  <div id="welcome">
@@ -0,0 +1,10 @@
1
+ class RemoveDeletedPolicy < ActiveRecord::Migration
2
+ def up
3
+ ForemanOpenscap::AssetPolicy.all.collect(&:policy_id).uniq.each do |policy_id|
4
+ execute("DELETE FROM foreman_openscap_asset_policies WHERE policy_id = '#{policy_id}';") if ForemanOpenscap::Policy.find_by_id(policy_id).nil?
5
+ end
6
+ end
7
+
8
+ def down
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ N_('Openscap policy summary')
2
+
1
3
  policy_notification = {
2
4
  :name => :openscap_policy_summary,
3
5
  :description => N_('A summary of reports for OpenSCAP policies'),
@@ -64,7 +64,7 @@ module ForemanOpenscap
64
64
 
65
65
  def fetch_host_name(asset_id)
66
66
  asset = ForemanOpenscap::Asset.find(asset_id)
67
- asset.host.to_label
67
+ ForemanOpenscap::Helper.find_name_or_uuid_by_host(asset.host)
68
68
  end
69
69
 
70
70
  def arfs_by_reported(time)
@@ -39,7 +39,7 @@ module ForemanOpenscap
39
39
  Apipie.configuration.checksum_path += ['/compliance/']
40
40
  end
41
41
 
42
- initializer 'foreman_openscap.register_plugin', :after => :finisher_hook do |app|
42
+ initializer 'foreman_openscap.register_plugin', :before => :finisher_hook do |app|
43
43
  Foreman::Plugin.register :foreman_openscap do
44
44
  requires_foreman '>= 1.11'
45
45
 
@@ -124,9 +124,19 @@ module ForemanOpenscap
124
124
  "dashboard link hosts with no reports", "dashboard link hosts with alerts disabled",
125
125
  "widgets not in dashboard show up in list"]
126
126
  })
127
+ # strong params
128
+ parameter_filter Host::Managed, :openscap_proxy_id, :openscap_proxy
129
+ parameter_filter Log, :result
130
+
127
131
  end
128
132
  end
129
133
 
134
+ initializer 'foreman_openscap.register_gettext', after: :load_config_initializers do |_app|
135
+ locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
136
+ locale_domain = 'foreman_openscap'
137
+ Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
138
+ end
139
+
130
140
  #Include concerns in this config.to_prepare block
131
141
  config.to_prepare do
132
142
  Host::Managed.send(:include, ForemanOpenscap::OpenscapProxyExtensions)
@@ -16,25 +16,21 @@ module ForemanOpenscap::Helper
16
16
  end
17
17
 
18
18
  def self.find_name_or_uuid_by_host(host)
19
- if defined?(::Katello::System)
20
- host.content_host.uuid
21
- else
22
- host.name
23
- end
19
+ (host.respond_to?(:subscription_facet) && !host.subscription_facet.nil?) ? host.subscription_facet.try(:uuid) : host.name
24
20
  end
25
21
 
26
22
  private
27
23
 
28
24
  def self.find_host_by_name_or_uuid(cname)
29
- if defined?(Katello::System)
30
- host = Host.includes(:content_host).where(:katello_systems => {:uuid => cname}).first
25
+ if Facets.registered_facets.keys.include?(:subscription_facet)
26
+ host = Katello::Host::SubscriptionFacet.find_by_uuid(cname).try(:host)
31
27
  host ||= Host.find_by_name(cname)
32
28
  else
33
29
  host = Host.find_by_name(cname)
34
30
  end
31
+
35
32
  unless host
36
33
  Rails.logger.error "Could not find Host with name: #{cname}"
37
- Rails.logger.error "Please check that Content host is linked to Foreman host" if defined?(Katello::System)
38
34
  fail ActiveRecord::RecordNotFound
39
35
  end
40
36
  host
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.0"
3
3
  end
data/locale/Makefile ADDED
@@ -0,0 +1,60 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. More info in the README.
3
+ #
4
+ # make all-mo (default) - generate MO files
5
+ # make check - check translations using translate-tool
6
+ # make tx-update - download and merge translations from Transifex
7
+ # make clean - clean everything
8
+ #
9
+ DOMAIN = foreman_openscap
10
+ VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
+ POTFILE = $(DOMAIN).pot
12
+ MOFILE = $(DOMAIN).mo
13
+ POFILES = $(shell find . -name '$(DOMAIN).po')
14
+ MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
+ POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
+ EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+
18
+ %.mo: %.po
19
+ mkdir -p $(shell dirname $@)/LC_MESSAGES
20
+ msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
21
+
22
+ # Generate MO files from PO files
23
+ all-mo: $(MOFILES)
24
+
25
+ # Check for malformed strings
26
+ %.pox: %.po
27
+ msgfmt -c $<
28
+ pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
29
+ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
30
+ cat $@
31
+ ! grep -q msgid $@
32
+
33
+ %.edit.po:
34
+ touch $@
35
+
36
+ check: $(POXFILES)
37
+
38
+ # Unify duplicate translations
39
+ uniq-po:
40
+ for f in $(shell find ./ -name "*.po") ; do \
41
+ msguniq $$f -o $$f ; \
42
+ done
43
+
44
+ tx-pull: $(EDITFILES)
45
+ tx pull -f
46
+ for f in $(EDITFILES) ; do \
47
+ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
48
+ done
49
+
50
+ tx-update: tx-pull
51
+ @echo
52
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo
54
+
55
+ mo-files: $(MOFILES)
56
+ git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
57
+ git commit -m "i18n - pulling from tx"
58
+ @echo
59
+ @echo Changes commited!
60
+ @echo