Class: Katello::Pool
- Includes:
- Glue::Candlepin::Pool, Authorization::Pool, Glue::Candlepin::CandlepinObject
- Defined in:
- app/models/katello/pool.rb
Defined Under Namespace
Classes: Jail
Constant Summary collapse
- DAYS_RECENTLY_EXPIRED =
30
Class Method Summary collapse
-
.audit_hook_to_find_records(keyname, change, _audit) ⇒ Object
Note - Audit hook added to find records based on column except associations to display audit information.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#days_until_expiration ⇒ Object
used for entitlements report template.
-
#expiring_soon? ⇒ Boolean
used for notification bell.
- #import_audit_record(old_host_ids, new_host_ids = subscription_facets.pluck(:host_id)) ⇒ Object
- #quantity_available ⇒ Object
- #recently_expired? ⇒ Boolean
- #redhat? ⇒ Boolean
- #subscription_matches_organization ⇒ Object
- #type ⇒ Object
- #upstream? ⇒ Boolean
Methods inherited from Model
Class Method Details
.audit_hook_to_find_records(keyname, change, _audit) ⇒ Object
Note - Audit hook added to find records based on column except associations to display audit information
117 118 119 120 121 122 123 124 |
# File 'app/models/katello/pool.rb', line 117 def self.audit_hook_to_find_records(keyname, change, _audit) if keyname =~ /_ids$/ case keyname when 'host_ids' ::Host.where(:id => change)&.index_by(&:id) end end end |
Instance Method Details
#active? ⇒ Boolean
71 72 73 |
# File 'app/models/katello/pool.rb', line 71 def active? active end |
#days_until_expiration ⇒ Object
used for entitlements report template
82 83 84 |
# File 'app/models/katello/pool.rb', line 82 def days_until_expiration (end_date.to_date - Date.today).to_i end |
#expiring_soon? ⇒ Boolean
used for notification bell
76 77 78 79 |
# File 'app/models/katello/pool.rb', line 76 def expiring_soon? days_until_expiration >= 0 && days_until_expiration <= Setting[:expire_soon_days].to_i end |
#import_audit_record(old_host_ids, new_host_ids = subscription_facets.pluck(:host_id)) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/katello/pool.rb', line 104 def import_audit_record(old_host_ids, new_host_ids = subscription_facets.pluck(:host_id)) return if old_host_ids.empty? && new_host_ids.empty? pool_id = self.id Audited::Audit.new( :auditable_id => pool_id, :auditable_type => 'Katello::Pool', :action => 'update', :auditable_name => self.name, :audited_changes => {'host_ids' => [old_host_ids, new_host_ids]} ).save! end |
#quantity_available ⇒ Object
90 91 92 93 94 |
# File 'app/models/katello/pool.rb', line 90 def quantity_available return -1 if self.quantity == -1 return 0 unless self.quantity && self.consumed self.quantity - self.consumed end |
#recently_expired? ⇒ Boolean
86 87 88 |
# File 'app/models/katello/pool.rb', line 86 def recently_expired? Date.today >= end_date.to_date && (Date.today - end_date.to_date) <= DAYS_RECENTLY_EXPIRED end |
#redhat? ⇒ Boolean
67 68 69 |
# File 'app/models/katello/pool.rb', line 67 def redhat? self.class.redhat.where(:id => self.id).exists? end |
#subscription_matches_organization ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/katello/pool.rb', line 58 def subscription_matches_organization return if errors[:subscription].any? || errors[:organization].any? # let other validations catch this unless subscription&.organization_id == self.organization_id errors.add(:base, _("A Pool and its Subscription cannot belong to different organizations.")) end end |
#type ⇒ Object
96 97 98 |
# File 'app/models/katello/pool.rb', line 96 def type self.pool_type end |
#upstream? ⇒ Boolean
100 101 102 |
# File 'app/models/katello/pool.rb', line 100 def upstream? upstream_pool_id.present? end |