Class: Katello::ActivationKey

Inherits:
Model
  • Object
show all
Includes:
ForemanTasks::Concerns::ActionSubject, Katello::Authorization::ActivationKey, Glue, Glue::Candlepin::ActivationKey, ScopedSearchExtensions
Defined in:
app/models/katello/activation_key.rb

Defined Under Namespace

Classes: Jail

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Katello::Authorization::ActivationKey

#deletable?, #editable?, #readable?

Methods included from Glue

logger

Methods included from Glue::Candlepin::ActivationKey

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_releasesObject



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_cvenvsObject



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_labelsObject



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



86
87
88
89
90
91
92
93
94
# File 'app/models/katello/activation_key.rb', line 86

def content_view_environments=(new_cvenvs)
  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



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

Returns:

  • (Boolean)


96
97
98
99
# File 'app/models/katello/activation_key.rb', line 96

def multi_content_view_environment?
  # returns false if there are no content view environments
  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_viewObject



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

Returns:

  • (Boolean)


101
102
103
104
# File 'app/models/katello/activation_key.rb', line 101

def single_content_view_environment?
  # also returns false if there are no content view environments
  content_view_environments.size == 1
end

#single_lifecycle_environmentObject



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_countObject



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

Returns:

  • (Boolean)


140
141
142
# File 'app/models/katello/activation_key.rb', line 140

def valid_content_override_label?()
  self.available_content.map(&:content).any? { |content| 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