Skip to content

Commit

Permalink
Fixes #35901 - Allow searching for CCVs based on component CVs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Oct 12, 2023
1 parent 06cf003 commit def1eaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit def1eaf

Please sign in to comment.