Skip to content

Commit fe2e792

Browse files
committed
Fixes #38252 - Display searchable_value as true/false in search field
1 parent 84a54dc commit fe2e792

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app/models/concerns/hostext/search.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module Search
7575

7676
scoped_search :relation => :fact_values, :on => :value, :in_key => :fact_names, :on_key => :name, :rename => :facts, :complete_value => true, :only_explicit => true, :ext_method => :search_cast_facts
7777
scoped_search :relation => :search_parameters, :on => :name, :complete_value => true, :rename => :params_name, :only_explicit => true
78-
scoped_search :relation => :search_parameters, :on => :searchable_value, :in_key => :search_parameters, :on_key => :name, :complete_value => true, :rename => :params, :ext_method => :search_by_params, :only_explicit => true, :operators => ['= ', '~ ']
78+
scoped_search :relation => :search_parameters, :on => :searchable_value, :in_key => :search_parameters, :on_key => :name, :complete_value => { true: 't', false: 'f'}, :rename => :params, :ext_method => :search_by_params, :only_explicit => true, :operators => ['= ', '~ ']
7979

8080
scoped_search :relation => :reported_data, :on => :boot_time, :rename => 'boot_time', :only_explicit => true
8181
scoped_search :relation => :reported_data, :on => :boot_time, :rename => 'reported.boot_time', :only_explicit => true
@@ -170,13 +170,15 @@ def search_by_hostgroup_and_descendants(key, operator, value)
170170
end
171171

172172
def search_by_params(key, operator, value)
173+
# boolean value is saved as 't'/'f' in searchable_value column
174+
normalized_value = value == 'true' ? 't' : 'f'
173175
key_name = key.sub(/^.*\./, '')
174-
condition = sanitize_sql_for_conditions(["name = ? and searchable_value #{operator} ?", key_name, value_to_sql(operator, value)])
176+
condition = sanitize_sql_for_conditions(["name = ? and searchable_value #{operator} ?", key_name, value_to_sql(operator, normalized_value)])
175177
p = Parameter.where(condition).reorder(:priority)
176178
return {:conditions => '1 = 0'} if p.blank?
177179

178180
max = p.first.priority
179-
condition = sanitize_sql_for_conditions(["name = ? and NOT(searchable_value #{operator} ?) and priority > ?", key_name, value_to_sql(operator, value), max])
181+
condition = sanitize_sql_for_conditions(["name = ? and NOT(searchable_value #{operator} ?) and priority > ?", key_name, value_to_sql(operator, normalized_value), max])
180182
n = Parameter.where(condition).reorder(:priority)
181183

182184
conditions = param_conditions(p)

0 commit comments

Comments
 (0)