Sha256: fba27f6b346c261831868a5eb9fffd375f9f2053fd3391a6c60eb75b1befe569

Contents?: true

Size: 1.23 KB

Versions: 11

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

11 entries across 11 versions & 1 rubygems

Version Path
foreman_openscap-0.7.1 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.7 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.7.0 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.6 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.5 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.4 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.3 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.2 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.1 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.6.0 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-0.5.4 app/mailers/foreman_openscap/policy_mailer.rb