Class: PreupgradeReportEntry

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/preupgrade_report_entry.rb

Class Method Summary collapse

Class Method Details

.remediation_details(remediation_ids, host) ⇒ Object



53
54
55
# File 'app/models/preupgrade_report_entry.rb', line 53

def self.remediation_details(remediation_ids, host)
  where(id: remediation_ids, host: host).where.not(detail: nil).pluck(:detail)
end

.search_fix_type(_key, operator, value) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/preupgrade_report_entry.rb', line 73

def self.search_fix_type(_key, operator, value)
  unless %w[hint command].include?(value.to_s.downcase)
    raise Foreman::Exception, N_("Unknown fix_type value '%s' for search_fix_type") % value
  end

  safe_value = sanitize_sql_like(value.to_s.downcase)
  like_op    = (operator == '=') ? 'LIKE' : 'NOT LIKE'

  conditions = "(preupgrade_report_entries.detail #{like_op} " \
               "'%%\"type\":\"#{safe_value}\"%%' OR " \
               "preupgrade_report_entries.detail #{like_op} " \
               "'%%\"type\": \"#{safe_value}\"%%')"
  conditions = "(#{conditions} OR preupgrade_report_entries.detail IS NULL)" if operator == '!='
  { conditions: conditions }
end

.search_yes_no_fields(key, operator, value) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/preupgrade_report_entry.rb', line 57

def self.search_yes_no_fields(key, operator, value)
  column, term = case key.to_sym
                 when :inhibitor       then %w[flags inhibitor]
                 when :has_remediation then %w[detail remediations]
                 else raise Foreman::Exception,
                   N_("Unknown search key '%s' for search_yes_no_fields") % key
                 end

  if (operator == '=' && value == 'yes') || (operator == '!=' && value == 'no')
    { conditions: "preupgrade_report_entries.#{column} LIKE '%%#{term}%%'" }
  else
    { conditions: "(preupgrade_report_entries.#{column} NOT LIKE '%%#{term}%%' OR " \
                  "preupgrade_report_entries.#{column} IS NULL)" }
  end
end