Class: Katello::Erratum

Inherits:
Model
  • Object
show all
Includes:
Concerns::PulpDatabaseUnit
Defined in:
app/models/katello/erratum.rb

Defined Under Namespace

Classes: Jail

Constant Summary collapse

SECURITY =
["security"].freeze
BUGZILLA =
["bugfix", "recommended"].freeze
ENHANCEMENT =
["enhancement", "optional"].freeze
TYPES =
[SECURITY, BUGZILLA, ENHANCEMENT].flatten.freeze
NONE =
"None".freeze
LOW =
"Low".freeze
MODERATE =
"Moderate".freeze
IMPORTANT =
"Important".freeze
CRITICAL =
"Critical".freeze
SEVERITIES =
[NONE, LOW, MODERATE, IMPORTANT, CRITICAL].freeze
CONTENT_TYPE =
"erratum".freeze
BACKEND_IDENTIFIER_FIELD =
"erratum_pulp3_href".freeze
PRN_IDENTIFIER_FIELD =
"erratum_prn".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::PulpDatabaseUnit

#backend_data, #library_repositories, #remove_from_repository

Methods inherited from Model

#destroy!

Class Method Details

.applicable_to_hosts(hosts) ⇒ Object



101
102
103
104
105
106
107
108
# File 'app/models/katello/erratum.rb', line 101

def self.applicable_to_hosts(hosts)
  # NOTE: ContentFacetErrata actually holds the "Applicable Errata" to that host
  # It is not the errata "belonging" to the host. Its rather the errata that is "applicable"
  # which is calculated elsewhere.

  self.group(:id).distinct.joins(:content_facets).
    where("#{Katello::Host::ContentFacet.table_name}.host_id" => hosts.select(:id))
end

.applicable_to_hosts_dashboard(hosts) ⇒ Object



110
111
112
113
# File 'app/models/katello/erratum.rb', line 110

def self.applicable_to_hosts_dashboard(hosts)
  Erratum.where(:id => applicable_to_hosts(hosts)).
    order("#{self.table_name}.updated desc").limit(6)
end

.backend_identifier_fieldObject



97
98
99
# File 'app/models/katello/erratum.rb', line 97

def self.backend_identifier_field
  SmartProxy.pulp_primary!.content_service(CONTENT_TYPE).backend_unit_identifier ? BACKEND_IDENTIFIER_FIELD.to_sym : nil
end

.content_facet_association_classObject



93
94
95
# File 'app/models/katello/erratum.rb', line 93

def self.content_facet_association_class
  ContentFacetErratum
end

.filter_errata_type(_key, operator, value) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/katello/erratum.rb', line 71

def self.filter_errata_type(_key, operator, value)
  if value.downcase == "other"
    if ['!=', '<>'].include?(operator)
      { conditions: sanitize_sql_for_conditions(["errata_type IN (?)", TYPES]) }
    else
      { conditions: sanitize_sql_for_conditions(["errata_type NOT IN (?)", TYPES]) }
    end
  else
    if ['!=', '<>'].include?(operator)
      { conditions: sanitize_sql_for_conditions(["errata_type != ?", value]) }
    else
      { conditions: sanitize_sql_for_conditions(["errata_type = ?", value]) }
    end
  end
end

.find_by_modular(_key, operator, value) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
# File 'app/models/katello/erratum.rb', line 199

def self.find_by_modular(_key, operator, value)
  conditions = ""
  if operator == '='
    query = value.downcase == "true" ? modular : non_modular
    conditions = "#{table_name}.id in (#{query.select(:id).to_sql})"
  else
    #failure condition. No such value so must return 0
    conditions = "1=0"
  end
  { :conditions => conditions }
end

.ids_installable_for_hosts(hosts = nil) ⇒ Object



140
141
142
# File 'app/models/katello/erratum.rb', line 140

def self.ids_installable_for_hosts(hosts = nil)
  installable_for_hosts(hosts).select(:id)
end

.list_filenames_by_clauses(repo, clauses, additional_included_errata) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'app/models/katello/erratum.rb', line 144

def self.list_filenames_by_clauses(repo, clauses, additional_included_errata)
  query_clauses = clauses.map do |clause|
    "(#{clause.to_sql})"
  end
  statement = query_clauses.join(" AND ")

  Katello::ErratumPackage.joins(:erratum => :repository_errata).
    where("#{RepositoryErratum.table_name}.repository_id" => repo.id).where(statement).pluck(:filename) -
    Katello::ErratumPackage.joins(:erratum => :repository_errata).where("#{RepositoryErratum.table_name}.repository_id" => repo.id).
      where("#{Erratum.table_name}.errata_id" => additional_included_errata.pluck(:errata_id)).pluck(:filename)
end

.list_modular_streams_by_clauses(repo, clauses, additional_included_errata) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/models/katello/erratum.rb', line 156

def self.list_modular_streams_by_clauses(repo, clauses, additional_included_errata)
  query_clauses = clauses.map do |clause|
    "(#{clause.to_sql})"
  end
  statement = query_clauses.join(" AND ")
  ModuleStream.where(:id => ModuleStreamErratumPackage.joins(:erratum_package => {:erratum => :repository_errata}).
      where("#{RepositoryErratum.table_name}.repository_id" => repo.id).
      where(statement).select("#{ModuleStreamErratumPackage.table_name}.module_stream_id")).
    joins(:repository_module_streams).
    where("#{RepositoryModuleStream.table_name}.repository_id" => repo.id) -
  ModuleStream.where(:id => ModuleStreamErratumPackage.joins(:erratum_package => {:erratum => :repository_errata}).
      where("#{RepositoryErratum.table_name}.repository_id" => repo.id).
      where(statement).where("#{Erratum.table_name}.errata_id" => additional_included_errata.pluck(:errata_id)).select("#{ModuleStreamErratumPackage.table_name}.module_stream_id")).
    joins(:repository_module_streams).
    where("#{RepositoryModuleStream.table_name}.repository_id" => repo.id)
end

.of_type(type, include_other = false) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'app/models/katello/erratum.rb', line 61

def self.of_type(type, include_other = false)
  if include_other
    where.not(
      :errata_type => [Erratum::SECURITY, Erratum::BUGZILLA, Erratum::ENHANCEMENT].flatten
      ).or(where(:errata_type => type))
  else
    where(:errata_type => type)
  end
end

.with_identifiers(ids) ⇒ Object



119
120
121
122
123
124
# File 'app/models/katello/erratum.rb', line 119

def self.with_identifiers(ids)
  ids = [ids] unless ids.is_a?(Array)
  ids.map!(&:to_s)
  id_integers = ids.map { |string| Integer(string) rescue -1 }
  where("#{self.table_name}.id in (?) or #{self.table_name}.pulp_id in (?) or #{self.table_name}.errata_id in (?)", id_integers, ids, ids)
end

Instance Method Details

#<=>(other) ⇒ Object



115
116
117
# File 'app/models/katello/erratum.rb', line 115

def <=>(other)
  return self.errata_id <=> other.errata_id
end

#content_view_filtersObject



211
212
213
# File 'app/models/katello/erratum.rb', line 211

def content_view_filters
  Katello::ContentViewErratumFilterRule.where(errata_id: self.errata_id).eager_load(:filter).map(&:filter)
end

#hosts_applicable(org_id = nil) ⇒ Object



126
127
128
129
130
131
132
# File 'app/models/katello/erratum.rb', line 126

def hosts_applicable(org_id = nil)
  if org_id.present?
    self.content_facets_applicable.joins(:host).where("#{::Host.table_name}.organization_id" => org_id)
  else
    self.content_facets_applicable.joins(:host)
  end
end

#hosts_available(org_id = nil) ⇒ Object



134
135
136
137
138
# File 'app/models/katello/erratum.rb', line 134

def hosts_available(org_id = nil)
  self.hosts_applicable(org_id).distinct.joins("INNER JOIN #{Katello::RepositoryErratum.table_name} on \
    #{Katello::RepositoryErratum.table_name}.erratum_id = #{self.id}").joins(:content_facet_repositories).
    where("#{Katello::ContentFacetRepository.table_name}.repository_id = #{Katello::RepositoryErratum.table_name}.repository_id")
end

#module_stream_objectsObject



192
193
194
195
196
197
# File 'app/models/katello/erratum.rb', line 192

def module_stream_objects
  streams = packages.map do |pack|
    pack.module_streams
  end
  return streams.flatten.uniq
end

#module_stream_specsObject



188
189
190
# File 'app/models/katello/erratum.rb', line 188

def module_stream_specs
  packages.collect { |package| package.module_streams.map(&:module_spec) }.flatten.uniq
end

#module_streamsObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/models/katello/erratum.rb', line 173

def module_streams
  # return something like
  # {module_stream => [packages]}
  module_stream_rpms = {}
  packages.each do |pack|
    pack.module_streams.each do |mod|
      module_stream_rpms[mod.module_spec_hash] ||= []
      module_stream_rpms[mod.module_spec_hash] << pack.nvrea unless module_stream_rpms[mod.module_spec_hash].include?(pack.nvrea)
    end
  end
  module_stream_rpms.map do |module_hash, nvreas|
    module_hash.merge(:packages => nvreas)
  end
end