From 29d5d46ca6b4a96c2b410b6f765b72c1732fc941 Mon Sep 17 00:00:00 2001 From: Tom McKay Date: Mon, 30 Apr 2012 13:26:10 -0400 Subject: [PATCH] 807291, 817634 - activation key now validates pools when loaded --- src/app/models/activation_key.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/app/models/activation_key.rb b/src/app/models/activation_key.rb index d8ffd43e7a8..a161c082974 100644 --- a/src/app/models/activation_key.rb +++ b/src/app/models/activation_key.rb @@ -32,6 +32,7 @@ class ActivationKey < ActiveRecord::Base scope :readable, lambda {|org| ActivationKey.readable?(org) ? where(:organization_id=>org.id) : where("0 = 1")} + after_find :validate_pools validates :name, :presence => true, :katello_name_format => true, :length => { :maximum => 255 } validates_uniqueness_of :name, :scope => :organization_id @@ -191,4 +192,24 @@ def extended_json to_ret end + private + + def validate_pools + obsolete_pools = [] + self.pools.each { |pool| + begin + # This will hit candlepin; if it fails that means the + # pool is no longer accessible. + pool.productName + next + rescue + obsolete_pools << pool + end + } + updated_pools = self.pools - obsolete_pools + if self.pools != updated_pools + self.pools = updated_pools + self.save! + end + end end