Class: Katello::ActivationKey
Defined Under Namespace
Classes: Jail
Class Method Summary
collapse
Instance Method Summary
collapse
#deletable?, #editable?, #readable?
Methods included from Glue
logger
included
Class Method Details
.humanize_class_name(_name = nil) ⇒ Object
153
154
155
|
# File 'app/models/katello/activation_key.rb', line 153
def self.humanize_class_name(_name = nil)
_("Activation Keys")
end
|
.in_environments(envs) ⇒ Object
82
83
84
|
# File 'app/models/katello/activation_key.rb', line 82
def self.in_environments(envs)
with_environments(envs)
end
|
.return_activation_keys_by_id(activation_key_ids) ⇒ Object
157
158
159
160
161
162
163
|
# File 'app/models/katello/activation_key.rb', line 157
def self.return_activation_keys_by_id(activation_key_ids)
if activation_key_ids.empty?
{:conditions => "1=0"}
else
{:conditions => "#{Katello::ActivationKey.table_name}.id IN (#{activation_key_ids.join(',')})"}
end
end
|
Instance Method Details
#available_releases ⇒ Object
128
129
130
131
132
133
134
|
# File 'app/models/katello/activation_key.rb', line 128
def available_releases
releases = self.content_view_environments.flat_map do |cvenv|
cvenv.content_view.version(cvenv.lifecycle_environment).available_releases
end
return self.organization.library.available_releases if releases.blank?
releases
end
|
#check_cvenvs ⇒ Object
174
175
176
177
178
179
180
181
|
# File 'app/models/katello/activation_key.rb', line 174
def check_cvenvs
cvenvs_not_in_org = self.content_view_environments.any? do |cvenv|
cvenv.content_view.organization != cvenv.environment.organization ||
self.organization != cvenv.content_view.organization
end
errors.add(:base, _("Cannot add content view environments from a different organization")) if cvenvs_not_in_org
end
|
#content_view_environment_labels ⇒ Object
136
137
138
|
# File 'app/models/katello/activation_key.rb', line 136
def content_view_environment_labels
content_view_environments.map(&:label).join(',')
end
|
#content_view_environments=(new_cvenvs) ⇒ Object
#copy(new_name) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'app/models/katello/activation_key.rb', line 144
def copy(new_name)
new_key = ActivationKey.new
new_key.name = new_name
new_key.attributes = self.attributes.slice("description", "organization_id", "max_hosts", "unlimited_hosts")
new_key.host_collection_ids = self.host_collection_ids
new_key.content_view_environments = content_view_environments
new_key
end
|
#multi_content_view_environment? ⇒ Boolean
96
97
98
99
|
# File 'app/models/katello/activation_key.rb', line 96
def multi_content_view_environment?
content_view_environments.size > 1
end
|
124
125
126
|
# File 'app/models/katello/activation_key.rb', line 124
def related_resources
self.organization
end
|
#single_content_view ⇒ Object
106
107
108
109
110
111
|
# File 'app/models/katello/activation_key.rb', line 106
def single_content_view
if multi_content_view_environment?
Rails.logger.warn _("Activation key %s has more than one content view. Use #content_views instead.") % name
end
content_view_environments&.first&.content_view
end
|
#single_content_view_environment? ⇒ Boolean
101
102
103
104
|
# File 'app/models/katello/activation_key.rb', line 101
def single_content_view_environment?
content_view_environments.size == 1
end
|
#single_lifecycle_environment ⇒ Object
113
114
115
116
117
118
|
# File 'app/models/katello/activation_key.rb', line 113
def single_lifecycle_environment
if multi_content_view_environment?
Rails.logger.warn _("Activation key %s has more than one lifecycle environment. Use #lifecycle_environments instead.") % name
end
content_view_environments&.first&.lifecycle_environment
end
|
#usage_count ⇒ Object
120
121
122
|
# File 'app/models/katello/activation_key.rb', line 120
def usage_count
subscription_facet_activation_keys.count
end
|
#valid_content_override_label?(content_label) ⇒ Boolean
140
141
142
|
# File 'app/models/katello/activation_key.rb', line 140
def valid_content_override_label?(content_label)
self.available_content.map(&:content).any? { |content| content.label == content_label }
end
|
#validate_destroyable! ⇒ Object
165
166
167
168
169
170
171
172
|
# File 'app/models/katello/activation_key.rb', line 165
def validate_destroyable!
if !organization.being_deleted? && Parameter.where(name: 'kt_activation_keys').pluck(:value).any? { |value| value.split(",").include?(name) }
fail _("This activation key is associated to one or more Hosts/Hostgroups. "\
"Search and unassociate Hosts/Hostgroups using params.kt_activation_keys ~ \"%{name}\" "\
"before deleting." % {name: name})
end
true
end
|