@@ -8,9 +8,62 @@ class PreupgradeReportEntry < ApplicationRecord
88 serialize :flags , Array
99 serialize :detail , JSON
1010
11- validates :preupgrade_report , :host , :hostname , :title , :actor , :audience , :severity , :leapp_run_id , presence : true
11+ validates :preupgrade_report , :host , :hostname , :title , :actor ,
12+ :audience , :severity , :leapp_run_id , presence : true
13+
14+ scoped_search on : :title , complete_value : true
15+ scoped_search on : :hostname , complete_value : true
16+ scoped_search on : :severity , complete_value : { high : 'high' , medium : 'medium' , low : 'low' , info : 'info' }
17+ scoped_search on : :summary
18+
19+ scoped_search on : :flags ,
20+ rename : :inhibitor ,
21+ only_explicit : true ,
22+ operators : [ '=' , '!=' ] ,
23+ complete_value : { yes : 'yes' , no : 'no' } ,
24+ ext_method : :search_yes_no_fields
25+
26+ scoped_search on : :detail ,
27+ rename : :has_remediation ,
28+ only_explicit : true ,
29+ operators : [ '=' , '!=' ] ,
30+ complete_value : { yes : 'yes' , no : 'no' } ,
31+ ext_method : :search_yes_no_fields
32+
33+ scoped_search on : :detail ,
34+ rename : :fix_type ,
35+ only_explicit : true ,
36+ operators : [ '=' , '!=' ] ,
37+ complete_value : { hint : 'hint' , command : 'command' } ,
38+ ext_method : :search_fix_type
1239
1340 def self . remediation_details ( remediation_ids , host )
1441 where ( id : remediation_ids , host : host ) . where . not ( detail : nil ) . pluck ( :detail )
1542 end
43+
44+ def self . search_yes_no_fields ( key , operator , value )
45+ column , term = case key . to_sym
46+ when :inhibitor then %w[ flags inhibitor ]
47+ when :has_remediation then %w[ detail remediations ]
48+ end
49+
50+ if ( operator == '=' && value == 'yes' ) || ( operator == '!=' && value == 'no' )
51+ { conditions : "preupgrade_report_entries.#{ column } LIKE '%%#{ term } %%'" }
52+ else
53+ { conditions : "(preupgrade_report_entries.#{ column } NOT LIKE '%%#{ term } %%' OR " \
54+ "preupgrade_report_entries.#{ column } IS NULL)" }
55+ end
56+ end
57+
58+ def self . search_fix_type ( _key , operator , value )
59+ return { } unless %w[ hint command ] . include? ( value . to_s . downcase )
60+
61+ like_op = operator == '=' ? 'LIKE' : 'NOT LIKE'
62+ conditions = "(preupgrade_report_entries.detail #{ like_op } '%%\" type\" :\" #{ value } \" %%' OR " \
63+ "preupgrade_report_entries.detail #{ like_op } '%%\" type\" : \" #{ value } \" %%')"
64+
65+ conditions = "(#{ conditions } OR preupgrade_report_entries.detail IS NULL)" if operator == '!='
66+
67+ { conditions : conditions }
68+ end
1669end
0 commit comments