Sha256: 9a0d60262f8659a8f675b0852e89c552477ba5c3eb7bd335c06ed4708cfd3fbb

Contents?: true

Size: 1.6 KB

Versions: 28

Compression:

Stored size: 1.6 KB

Contents

module ForemanOpenscap
  class ScapContent < ApplicationRecord
    audited :except => [:scap_file]
    include Authorizable
    include Taxonomix
    include DataStreamContent

    has_many :scap_content_profiles, :dependent => :destroy
    has_many :policies

    validates :title, :presence => true, :length => { :maximum => 255 }, uniqueness: true
    validates :original_filename, :length => { :maximum => 255 }

    scoped_search :on => :title,             :complete_value => true
    scoped_search :on => :original_filename, :complete_value => true, :rename => :filename
    scoped_search :on => :created_at

    default_scope do
      with_taxonomy_scope do
        order("foreman_openscap_scap_contents.title")
      end
    end

    def used_location_ids
      Location.joins(:taxable_taxonomies).where(
        'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::ScapContent',
        'taxable_taxonomies.taxable_id' => id
      ).pluck("#{Location.arel_table.name}.id")
    end

    def used_organization_ids
      Organization.joins(:taxable_taxonomies).where(
        'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::ScapContent',
        'taxable_taxonomies.taxable_id' => id
      ).pluck("#{Location.arel_table.name}.id")
    end

    def to_label
      title
    end

    def as_json(*args)
      hash = super
      hash["scap_file"] = scap_file.to_s.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')
    end

    def fetch_profiles
      api = ProxyAPI::Openscap.new(:url => proxy_url)
      profiles = api.fetch_policies_for_scap_content(scap_file)
      profiles
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
foreman_openscap-4.1.3 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.6 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.2.0 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.5 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.1.2 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.1.1 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.1.0 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.4 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.3 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.2 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.1 app/models/foreman_openscap/scap_content.rb
foreman_openscap-3.0.1 app/models/foreman_openscap/scap_content.rb
foreman_openscap-4.0.0 app/models/foreman_openscap/scap_content.rb
foreman_openscap-3.0.0 app/models/foreman_openscap/scap_content.rb
foreman_openscap-2.0.2 app/models/foreman_openscap/scap_content.rb
foreman_openscap-1.0.10 app/models/foreman_openscap/scap_content.rb
foreman_openscap-2.0.1 app/models/foreman_openscap/scap_content.rb
foreman_openscap-1.0.9 app/models/foreman_openscap/scap_content.rb
foreman_openscap-2.0.0 app/models/foreman_openscap/scap_content.rb
foreman_openscap-1.0.8 app/models/foreman_openscap/scap_content.rb