Sha256: 76093e41c046d60f79ee455bbfa56a4a369609094e30ce7a6015085dce1fd8ff

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

#
# Copyright (c) 2014 Red Hat Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
# along with this software; if not, see http://www.gnu.org/licenses/gpl.txt
#

require 'scaptimony/arf_report'

module ForemanOpenscap
  module ArfReportExtensions
    extend ActiveSupport::Concern
    include Taxonomix
    included do
      has_one :host, :through => :asset, :as => :assetable, :source => :assetable, :source_type => 'Host::Base'

      after_save :assign_locations_organizations

      scope :hosts, lambda { includes(:policy, :arf_report_breakdown) }
      scope :latest, lambda { includes(:host, :policy, :arf_report_breakdown).limit(5).order("scaptimony_arf_reports.created_at DESC") }
      scope :of_policy, lambda {|policy_id| {:conditions => {:policy_id => policy_id}}}

      scoped_search :in => :host, :on => :name, :complete_value => :true, :rename => "host"

      default_scope {
        with_taxonomy_scope do
          order("scaptimony_arf_reports.created_at DESC")
        end
      }
    end

    def assign_locations_organizations
      if host
        self.location_ids = [host.location_id] if SETTINGS[:locations_enabled]
        self.organization_ids = [host.organization_id] if SETTINGS[:organizations_enabled]
      end
    end

    def failed?
      failed > 0
    end

    def passed?
      passed > 0 && !failed?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreman_openscap-0.4.3 app/models/concerns/foreman_openscap/arf_report_extensions.rb
foreman_openscap-0.4.2 app/models/concerns/foreman_openscap/arf_report_extensions.rb
foreman_openscap-0.4.1 app/models/concerns/foreman_openscap/arf_report_extensions.rb
foreman_openscap-0.4.0 app/models/concerns/foreman_openscap/arf_report_extensions.rb