Sha256: 667650472f4e2ef84538702e7832f745841586426893cf491b24032ece629374

Contents?: true

Size: 1.23 KB

Versions: 28

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

    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

28 entries across 28 versions & 1 rubygems

Version Path
foreman_openscap-1.0.7 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.6 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.5 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.4 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.3 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.2 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.1 app/mailers/foreman_openscap/policy_mailer.rb
foreman_openscap-1.0.0 app/mailers/foreman_openscap/policy_mailer.rb