Skip to content

Commit

Permalink
Fixes #35901 - Allow searching for CCVs based on component CVs (#10767)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz authored Oct 13, 2023
1 parent a578284 commit c6064c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module FilteredAutoCompleteSearch

def auto_complete_search
begin
options = resource_class.respond_to?(:completer_scope_options) ? resource_class.completer_scope_options : {}
options = resource_class.respond_to?(:completer_scope_options) ? resource_class.completer_scope_options(params[:search]) : {}
items = resource_class.where(:id => self.index_relation).complete_for(params[:search], options)
items = items.map do |item|
category = ['and', 'or', 'not', 'has'].include?(item.to_s.sub(/^.*\s+/, '')) ? _('Operators') : ''
Expand Down
21 changes: 21 additions & 0 deletions app/models/katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ class ContentView < Katello::Model
scoped_search :on => :composite, :complete_value => true
scoped_search :on => :generated_for, :complete_value => true
scoped_search :on => :default # just for ordering
scoped_search :on => :name, :complete_value => true,
:rename => :content_views,
:operators => ['='],
:ext_method => :find_components_by_cv_name

def self.find_components_by_cv_name(_key, operator, value)
kcv = Katello::ContentView.table_name
kcvc = Katello::ContentViewComponent.table_name
{ :conditions => "#{kcv}.composite = 't' AND #{kcv}.id IN (SELECT #{kcvc}.composite_content_view_id FROM #{kcvc} WHERE #{kcvc}.content_view_id IN (SELECT #{kcv}.id FROM #{kcv} WHERE #{kcv}.name #{operator} ?))",
:parameter => [value]
}
end

def self.completer_scope_options(search)
if search.include?('content_views')
# Don't autocomplete CCV names when searching for components
{ :value_filter => { :composite => false } }
else
{}
end
end

enum generated_for: {
none: 0,
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/docker_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def self.with_identifiers(ids)
self.where(:id => ids)
end

def self.completer_scope_options
def self.completer_scope_options(_search)
{"#{Katello::Repository.table_name}" => lambda { |repo_class| repo_class.docker_type } }
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/yum_metadata_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def repositories
[repository]
end

def self.completer_scope_options
def self.completer_scope_options(_search)
{"#{Katello::Repository.table_name}" => lambda { |repo_class| repo_class.yum_type } }
end
end
Expand Down

0 comments on commit c6064c9

Please sign in to comment.