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
163
164
165
|
# File 'app/models/katello/activation_key.rb', line 163
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
167
168
169
170
171
172
173
|
# File 'app/models/katello/activation_key.rb', line 167
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
138
139
140
141
142
143
144
|
# File 'app/models/katello/activation_key.rb', line 138
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
184
185
186
187
188
189
190
191
|
# File 'app/models/katello/activation_key.rb', line 184
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_ids=(ids) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'app/models/katello/activation_key.rb', line 86
def content_view_environment_ids=(ids)
ids = Array(ids).reject(&:blank?)
if ids.empty?
self.content_view_environments = []
else
self.content_view_environments = ContentViewEnvironment.find(ids.uniq)
end
end
|
#content_view_environment_labels ⇒ Object
146
147
148
|
# File 'app/models/katello/activation_key.rb', line 146
def content_view_environment_labels
content_view_environments.map(&:label).join(',')
end
|
#content_view_environments=(new_cvenvs) ⇒ Object
95
96
97
98
99
100
101
102
103
104
|
# File 'app/models/katello/activation_key.rb', line 95
def content_view_environments=(new_cvenvs)
new_cvenvs = Array(new_cvenvs).uniq(&:id)
if new_cvenvs.length > 1 && !Setting['allow_multiple_content_views']
fail ::Katello::Errors::MultiEnvironmentNotSupportedError,
_("Assigning an activation key to multiple content view environments is not enabled. To enable, set the allow_multiple_content_views setting.")
end
super(new_cvenvs)
Katello::ContentViewEnvironmentActivationKey.reprioritize_for_activation_key(self, new_cvenvs)
self.content_view_environments.reload unless self.new_record?
end
|
#copy(new_name) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'app/models/katello/activation_key.rb', line 154
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
106
107
108
109
|
# File 'app/models/katello/activation_key.rb', line 106
def multi_content_view_environment?
content_view_environments.size > 1
end
|
134
135
136
|
# File 'app/models/katello/activation_key.rb', line 134
def related_resources
self.organization
end
|
#single_content_view ⇒ Object
116
117
118
119
120
121
|
# File 'app/models/katello/activation_key.rb', line 116
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
111
112
113
114
|
# File 'app/models/katello/activation_key.rb', line 111
def single_content_view_environment?
content_view_environments.size == 1
end
|
#single_lifecycle_environment ⇒ Object
123
124
125
126
127
128
|
# File 'app/models/katello/activation_key.rb', line 123
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
130
131
132
|
# File 'app/models/katello/activation_key.rb', line 130
def usage_count
subscription_facet_activation_keys.count
end
|
#valid_content_override_label?(content_label) ⇒ Boolean
150
151
152
|
# File 'app/models/katello/activation_key.rb', line 150
def valid_content_override_label?(content_label)
self.available_content.map(&:content).any? { |content| content.label == content_label }
end
|
#validate_destroyable! ⇒ Object
175
176
177
178
179
180
181
182
|
# File 'app/models/katello/activation_key.rb', line 175
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
|