Sha256: d0977f1c641807b0804e60873e57add75c5331abcf57c1e8957812468bda320a

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

module ForemanOpenscap
  class PolicyMailer < ::ApplicationMailer

    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.incomply_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

    private

    def changed_hosts_of_policies(policies)
      hash = @policies.inject({}) do |result, policy|
        result[policy.id] = policy.hosts
        result
      end

      @changed_hosts = []
      hash.each do |key, values|
        values.each do |host|
          @changed_hosts << host if host.scap_status_changed?(::ForemanOpenscap::Policy.find(key))
        end
      end
      @changed_hosts.uniq
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
foreman_openscap-0.7.13 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.12 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.11 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.10 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.8.3 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.9 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.8 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.7 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.8.2 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.6 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.8.1 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.5 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.8.0 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.4 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.3 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.2 app/mailers/foreman_openscap/policy_mailer.rb