From def1eaf4bc90308069ba813f1fa2d724bcfbadf0 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Thu, 12 Oct 2023 15:34:16 -0400 Subject: [PATCH] Fixes #35901 - Allow searching for CCVs based on component CVs --- .../concerns/filtered_auto_complete_search.rb | 2 +- app/models/katello/content_view.rb | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/katello/concerns/filtered_auto_complete_search.rb b/app/controllers/katello/concerns/filtered_auto_complete_search.rb index 1055a5a9336..0fa32c15340 100644 --- a/app/controllers/katello/concerns/filtered_auto_complete_search.rb +++ b/app/controllers/katello/concerns/filtered_auto_complete_search.rb @@ -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') : '' diff --git a/app/models/katello/content_view.rb b/app/models/katello/content_view.rb index 316d2d452fa..5fa54ac20f0 100644 --- a/app/models/katello/content_view.rb +++ b/app/models/katello/content_view.rb @@ -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,