Sha256: 418095e88b4e35312d158f6032922fec5d4a514468c52c565957ba130823ba90

Contents?: true

Size: 1.51 KB

Versions: 20

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.tr("*", "%")
      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

20 entries across 20 versions & 1 rubygems

Version Path
katello-3.2.1.1 app/models/katello/content_view_package_filter.rb
katello-3.2.1 app/models/katello/content_view_package_filter.rb
katello-3.2.0 app/models/katello/content_view_package_filter.rb
katello-3.2.0.rc3 app/models/katello/content_view_package_filter.rb
katello-3.2.0.rc2 app/models/katello/content_view_package_filter.rb
katello-3.2.0.rc1.1 app/models/katello/content_view_package_filter.rb
katello-3.2.0.rc1 app/models/katello/content_view_package_filter.rb
katello-3.1.0.1 app/models/katello/content_view_package_filter.rb
katello-3.1.0 app/models/katello/content_view_package_filter.rb
katello-3.1.0.rc2.1 app/models/katello/content_view_package_filter.rb
katello-3.0.2 app/models/katello/content_view_package_filter.rb
katello-3.1.0.rc1 app/models/katello/content_view_package_filter.rb
katello-3.0.1 app/models/katello/content_view_package_filter.rb
katello-3.0.0 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc7 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc5 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc4 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc3 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc2 app/models/katello/content_view_package_filter.rb
katello-3.0.0.rc1 app/models/katello/content_view_package_filter.rb