Class: Katello::Erratum
- Includes:
- Concerns::PulpDatabaseUnit
- Defined in:
- app/models/katello/erratum.rb
Constant Summary collapse
- SECURITY =
"security"- BUGZILLA =
"bugfix"- ENHANCEMENT =
"enhancement"- TYPES =
[SECURITY, BUGZILLA, ENHANCEMENT]
- CONTENT_TYPE =
Pulp::Erratum::CONTENT_TYPE
Class Method Summary collapse
- .applicable_to_hosts(hosts) ⇒ Object
- .installable_for_hosts(hosts = nil) ⇒ Object
- .list_filenames_by_clauses(repo, clauses) ⇒ Object
- .of_type(type) ⇒ Object
- .repository_association_class ⇒ Object
- .with_identifiers(ids) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #hosts_applicable ⇒ Object
- #hosts_available ⇒ Object
- #hosts_unavailable ⇒ Object
- #update_from_json(json) ⇒ Object
Methods included from Concerns::PulpDatabaseUnit
Methods inherited from Model
Class Method Details
.applicable_to_hosts(hosts) ⇒ Object
48 49 50 51 |
# File 'app/models/katello/erratum.rb', line 48 def self.applicable_to_hosts(hosts) self.joins(:content_facet_errata).joins(:content_facets). where("#{Katello::Host::ContentFacet.table_name}.host_id" => hosts).uniq end |
.installable_for_hosts(hosts = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/katello/erratum.rb', line 78 def self.installable_for_hosts(hosts = nil) query = Katello::Erratum.joins(:content_facet_errata).joins(:repository_errata). joins("INNER JOIN #{Katello::ContentFacetRepository.table_name} on \ #{Katello::ContentFacetRepository.table_name}.content_facet_id = #{Katello::ContentFacetErratum.table_name}.content_facet_id"). joins("INNER JOIN #{Katello::RepositoryErratum.table_name} AS host_repo_errata ON \ host_repo_errata.erratum_id = #{Katello::Erratum.table_name}.id"). where("#{Katello::ContentFacetRepository.table_name}.repository_id = host_repo_errata.repository_id") query = query.joins(:content_facets).where("#{Katello::Host::ContentFacet.table_name}.host_id" => [hosts.map(&:id)]) if hosts query.uniq end |
.list_filenames_by_clauses(repo, clauses) ⇒ Object
108 109 110 111 112 113 |
# File 'app/models/katello/erratum.rb', line 108 def self.list_filenames_by_clauses(repo, clauses) errata = Katello.pulp_server.extensions.errata.search(Katello::Erratum::CONTENT_TYPE, :filters => clauses) Katello::ErratumPackage.joins(:erratum => :repository_errata). where("#{RepositoryErratum.table_name}.repository_id" => repo.id, "#{Erratum.table_name}.uuid" => errata.map { |e| e['_id'] }).pluck(:filename) end |
.of_type(type) ⇒ Object
36 37 38 |
# File 'app/models/katello/erratum.rb', line 36 def self.of_type(type) where(:errata_type => type) end |
.repository_association_class ⇒ Object
44 45 46 |
# File 'app/models/katello/erratum.rb', line 44 def self.repository_association_class RepositoryErratum end |
.with_identifiers(ids) ⇒ Object
57 58 59 60 61 62 |
# File 'app/models/katello/erratum.rb', line 57 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}.uuid in (?) or #{self.table_name}.errata_id in (?)", id_integers, ids, ids) end |
Instance Method Details
#<=>(other) ⇒ Object
53 54 55 |
# File 'app/models/katello/erratum.rb', line 53 def <=>(other) return self.errata_id <=> other.errata_id end |
#hosts_applicable ⇒ Object
64 65 66 |
# File 'app/models/katello/erratum.rb', line 64 def hosts_applicable self.content_facets_applicable.joins(:host) end |
#hosts_available ⇒ Object
68 69 70 71 72 |
# File 'app/models/katello/erratum.rb', line 68 def hosts_available self.hosts_applicable.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").uniq end |
#hosts_unavailable ⇒ Object
74 75 76 |
# File 'app/models/katello/erratum.rb', line 74 def hosts_unavailable self.hosts_applicable.where("#{Katello::System.table_name}.id not in (#{self.hosts_available.select("#{Katello::System.table_name}.id").to_sql})") end |
#update_from_json(json) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/katello/erratum.rb', line 90 def update_from_json(json) keys = %w(title id severity issued type description reboot_suggested solution updated summary) custom_json = json.clone.delete_if { |key, _value| !keys.include?(key) } if self.updated.blank? || (custom_json['updated'].to_datetime != self.updated.to_datetime) custom_json['errata_id'] = custom_json.delete('id') custom_json['errata_type'] = custom_json.delete('type') self.update_attributes!(custom_json) unless json['references'].blank? update_bugzillas(json['references'].select { |r| r['type'] == 'bugzilla' }) update_cves(json['references'].select { |r| r['type'] == 'cve' }) end end update_packages(json['pkglist']) unless json['pkglist'].blank? end |