Skip to content

Commit

Permalink
807291, 817634 - activation key now validates pools when loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmckay committed May 1, 2012
1 parent 5537315 commit 29d5d46
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/app/models/activation_key.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 29d5d46

Please sign in to comment.