Class: ForemanOpenscap::PolicyMailer

Inherits:
ApplicationMailer
  • Object
show all
Defined in:
app/mailers/foreman_openscap/policy_mailer.rb

Instance Method Summary collapse

Instance Method Details

#policy_summary(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/mailers/foreman_openscap/policy_mailer.rb', line 3

def policy_summary(options = {})
  set_url
  user = ::User.find(options[:user])
  @time = options[:time] || 1.day.ago

  @policies = ::ForemanOpenscap::Policy.all.reject { |policy| policy.assets.map(&:host).compact.empty? }
  @compliant_hosts = @policies.map { |policy| ::Host.comply_with policy }.flatten
  @incompliant_hosts = @policies.map { |policy| ::Host.not_comply_with policy }.flatten
  changed_hosts_of_policies(@policies)

  if user.nil? || user.mail.nil?
    logger.warn "User with valid email not supplied, mail report will not be sent"
  else
    set_locale_for(user) do
      subject = _("SCAP policies summary")
      mail(:to => user.mail, :subject => subject)
    end
  end
end