Sha256: b8244547d1504fc2d761a149130f00a7462103cbe7faea629b7674a8d8e4539f

Contents?: true

Size: 1.51 KB

Versions: 9

Compression:

Stored size: 1.51 KB

Contents

module Katello
  class ContentViewPackageFilter < ContentViewFilter
    CONTENT_TYPE = Rpm::CONTENT_TYPE

    has_many :package_rules, :dependent => :destroy, :foreign_key => :content_view_filter_id,
                             :class_name => "Katello::ContentViewPackageFilterRule"
    validates_lengths_from_database

    # Returns a set of Pulp/MongoDB conditions to filter out packages in the
    # repo repository that match parameters
    #
    # @param repo [Repository] a repository containing packages to filter
    # @return [Array] an array of hashes with MongoDB conditions
    def generate_clauses(repo)
      package_filenames = []

      self.package_rules.each do |rule|
        package_filenames.concat(query_rpms(repo, rule))
      end
      if self.original_packages
        package_filenames.concat(repo.packages_without_errata.map(&:filename))
      end

      { 'filename' => { "$in" => package_filenames } } unless package_filenames.empty?
    end

    def original_packages=(value)
      self[:original_packages] = value
    end

    protected

    def query_rpms(repo, rule)
      query_name = rule.name.gsub("*", "%")
      query = Rpm.in_repositories(repo).where("#{Rpm.table_name}.name ilike ?", query_name)
      if !rule.version.blank?
        query = query.search_version_equal(rule.version)
      elsif !rule.min_version.blank? || !rule.max_version.blank?
        query = query.search_version_range(rule.min_version, rule.max_version)
      end
      query.pluck("#{Rpm.table_name}.filename")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/models/katello/content_view_package_filter.rb
katello-2.4.4 app/models/katello/content_view_package_filter.rb
katello-2.4.3 app/models/katello/content_view_package_filter.rb
katello-2.4.2 app/models/katello/content_view_package_filter.rb
katello-2.4.1 app/models/katello/content_view_package_filter.rb
katello-2.4.0 app/models/katello/content_view_package_filter.rb
katello-2.4.0.rc3 app/models/katello/content_view_package_filter.rb
katello-2.4.0.rc2 app/models/katello/content_view_package_filter.rb
katello-2.4.0.rc1 app/models/katello/content_view_package_filter.rb