Class: Katello::Pool

Inherits:
Model
  • Object
show all
Includes:
Glue::Candlepin::Pool, Authorization::Pool, Glue::Candlepin::CandlepinObject
Defined in:
app/models/katello/pool.rb

Defined Under Namespace

Classes: Jail

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#destroy!

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



105
106
107
108
109
110
111
112
# File 'app/models/katello/pool.rb', line 105

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

#days_until_expirationObject

used for entitlements report template



80
81
82
# File 'app/models/katello/pool.rb', line 80

def days_until_expiration
  (end_date.to_date - Date.today).to_i
end

#expired?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/katello/pool.rb', line 65

def expired?
  end_date < Time.zone.now
end

#expiring_soon?Boolean

used for notification bell

Returns:

  • (Boolean)


74
75
76
77
# File 'app/models/katello/pool.rb', line 74

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



92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/katello/pool.rb', line 92

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

#product_host_countObject



54
55
56
# File 'app/models/katello/pool.rb', line 54

def product_host_count
  Katello::Host::ContentFacet.joins(bound_repositories: { product: :pools }).where(pools: { id: id }).distinct.count
end

#redhat?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/katello/pool.rb', line 69

def redhat?
  self.class.redhat.where(:id => self.id).exists?
end

#subscription_matches_organizationObject



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

#typeObject



84
85
86
# File 'app/models/katello/pool.rb', line 84

def type
  self.pool_type
end

#upstream?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/katello/pool.rb', line 88

def upstream?
  upstream_pool_id.present?
end