app/models/katello/activation_key.rb in katello-2.4.5 vs app/models/katello/activation_key.rb in katello-3.0.0.rc1
- old
+ new
@@ -18,10 +18,12 @@
has_many :system_activation_keys, :class_name => "Katello::SystemActivationKey", :dependent => :destroy
has_many :systems, :through => :system_activation_keys
has_many :pools, :through => :pool_activation_keys, :class_name => "Katello::Pool"
has_many :pool_activation_keys, :class_name => "Katello::PoolActivationKey", :dependent => :destroy, :inverse_of => :activation_key
+ has_many :subscription_facet_activation_keys, :class_name => "Katello::SubscriptionFacetActivationKey", :dependent => :destroy
+ has_many :subscription_facets, :through => :subscription_facet_activation_keys
before_validation :set_default_content_view, :unless => :persisted?
validates_lengths_from_database
validates_with Validators::KatelloNameFormatValidator, :attributes => :name
@@ -37,13 +39,13 @@
else
if value.nil?
record.errors[attr] << _("cannot be nil")
elsif value <= 0
record.errors[attr] << _("cannot be less than one")
- elsif value < record.systems.length
+ elsif value < record.subscription_facets.length
# we don't let users to set usage limit lower than current in-use
- record.errors[attr] << _("cannot be lower than current usage count (%s)" % record.systems.length)
+ record.errors[attr] << _("cannot be lower than current usage count (%s)" % record.subscription_facets.length)
end
end
end
validates_with Validators::ContentViewEnvironmentValidator
@@ -52,21 +54,22 @@
scoped_search :on => :name, :complete_value => true
scoped_search :on => :organization_id, :complete_value => true
scoped_search :rename => :environment, :on => :name, :in => :environment, :complete_value => true
scoped_search :rename => :content_view, :on => :name, :in => :content_view, :complete_value => true
scoped_search :on => :content_view_id, :complete_value => true
+ scoped_search :on => :description, :complete_value => true
def environment_exists
if environment_id && environment.nil?
errors.add(:environment, _("ID: %s doesn't exist ") % environment_id)
elsif !environment.nil? && environment.organization != self.organization
errors.add(:environment, _("name: %s doesn't exist ") % environment.name)
end
end
def usage_count
- system_activation_keys.count
+ subscription_facet_activation_keys.count
end
def related_resources
self.organization
end
@@ -93,33 +96,23 @@
def products
all_products = []
cp_pools = self.get_key_pools
if cp_pools
- pools = cp_pools.collect { |cp_pool| Pool.find_by_cp_id(cp_pool['id']) }
+ pools = cp_pools.collect { |cp_pool| Pool.find_by(:cp_id => cp_pool['id']) }
pools.each do |pool|
all_products << pool.subscription.products
end
end
all_products.flatten!
end
def available_content
- self.products.map(&:available_content).flatten
+ self.products.map(&:available_content).flatten.uniq { |product| product.content.id }
end
def valid_content_label?(content_label)
self.available_content.map(&:content).any? { |content| content.label == content_label }
- end
-
- # sets up system when registering with this activation key - must be executed in a transaction
- def apply_to_system(system)
- if !max_content_hosts.nil? && !self.unlimited_content_hosts && usage_count >= max_content_hosts
- fail Errors::MaxContentHostsReachedException, _("Max Content Hosts (%{limit}) reached for activation key '%{name}'") % {:limit => max_content_hosts, :name => name}
- end
- system.environment_id = self.environment_id if self.environment_id
- system.content_view_id = self.content_view_id if self.content_view_id
- system.system_activation_keys.build(:activation_key => self)
end
def calculate_consumption(product, pools, _allocate)
pools = pools.sort_by { |pool| [pool.start_date, pool.cp_id] }
consumption = {}