Class: Katello::Api::V2::ActivationKeysController
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#empty_search_query?, #full_result_response, #resource_class, #scoped_search, #skip_session
Methods included from Rendering
#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template
#api_version
Instance Method Details
#add_host_collections ⇒ Object
163
164
165
166
167
168
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 163
def add_host_collections
ids = activation_key_params[:host_collection_ids]
@activation_key.host_collection_ids = (@activation_key.host_collection_ids + ids).uniq
@activation_key.save!
respond_for_show(:resource => @activation_key)
end
|
#available_host_collections ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 137
def available_host_collections
table_name = HostCollection.table_name
host_collection_ids = @activation_key.host_collections.pluck("#{table_name}.id")
scoped = HostCollection.readable
scoped = scoped.where("#{table_name}.id NOT IN (?)", host_collection_ids) if host_collection_ids.present?
scoped = scoped.where(:organization_id => @activation_key.organization)
scoped = scoped.where(:name => params[:name]) if params[:name]
respond_for_index(:collection => scoped_search(scoped, :name, :asc, :resource_class => HostCollection))
end
|
#available_releases ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 151
def available_releases
response = {
:results => @activation_key.available_releases,
:total => @activation_key.available_releases.size,
:subtotal => @activation_key.available_releases.size,
}
respond_for_index :collection => response
end
|
#content_override ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 188
def content_override
if params[:content_overrides]
organization = @activation_key.organization
specified_labels = []
content_override_values = params[:content_overrides].map do |override|
specified_labels << override[:content_label]
validate_content_overrides_enabled(override)
end
specified_labels.uniq!
existing_labels = organization.contents.where(label: specified_labels).pluck(:label).uniq
unless specified_labels.size == existing_labels.size
missing_labels = specified_labels - existing_labels
msg = "Content label(s) \"#{missing_labels.join(", ")}\" were not found in the Organization \"#{organization}\""
fail HttpErrors::BadRequest, _(msg)
end
@activation_key.set_content_overrides(content_override_values)
end
respond_for_show(:resource => @activation_key)
end
|
#copy ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 114
def copy
@activation_key = Katello::ActivationKey.readable.find_by(:id => params[:id])
throw_resource_not_found(name: 'activation_key', id: params[:id]) if @activation_key.nil?
fail HttpErrors::BadRequest, _("New name cannot be blank") unless params[:new_name]
@new_activation_key = @activation_key.copy(params[:new_name])
@new_activation_key.user = current_user
sync_task(::Actions::Katello::ActivationKey::Create, @new_activation_key)
@new_activation_key.reload
sync_task(::Actions::Katello::ActivationKey::Update, @new_activation_key,
:service_level => @activation_key.service_level,
:release_version => @activation_key.release_version
)
@activation_key.pools.each do |pool|
@new_activation_key.subscribe(pool[:id])
end
@new_activation_key.set_content_overrides(@activation_key.content_overrides) unless @activation_key.content_overrides.blank?
respond_for_create(:resource => @new_activation_key)
end
|
#create ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 63
def create
@activation_key = ActivationKey.new(activation_key_params) do |activation_key|
activation_key.content_view_environments = @content_view_environments if update_cves?
activation_key.organization = @organization
activation_key.user = current_user
end
sync_task(::Actions::Katello::ActivationKey::Create, @activation_key, service_level: activation_key_params['service_level'])
@activation_key.reload
respond_for_create(:resource => @activation_key)
end
|
#destroy ⇒ Object
96
97
98
99
100
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 96
def destroy
task = sync_task(::Actions::Katello::ActivationKey::Destroy,
@activation_key)
respond_for_async(:resource => task)
end
|
#index ⇒ Object
55
56
57
58
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 55
def index
activation_key_includes = [:content_view_environments, :host_collections, :organization]
respond(:collection => scoped_search(index_relation.distinct, :name, :asc, :includes => activation_key_includes))
end
|
#index_relation ⇒ Object
220
221
222
223
224
225
226
227
228
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 220
def index_relation
activation_keys = ActivationKey.readable
activation_keys = activation_keys.where(:name => params[:name]) if params[:name]
activation_keys = activation_keys.where(:organization_id => @organization) if @organization
activation_keys = activation_keys.with_content_view_environments(@content_view_environments) if @content_view_environments
activation_keys = activation_keys.with_content_views(params[:content_view_id]) if params[:content_view_id]
activation_keys = activation_keys.with_environments(params[:lifecycle_environments]) if params[:lifecycle_environments]
activation_keys
end
|
#product_content ⇒ Object
215
216
217
218
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 215
def product_content
end
|
#remove_host_collections ⇒ Object
173
174
175
176
177
178
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 173
def remove_host_collections
ids = activation_key_params[:host_collection_ids]
@activation_key.host_collection_ids = (@activation_key.host_collection_ids - ids).uniq
@activation_key.save!
respond_for_show(:resource => @activation_key)
end
|
#show ⇒ Object
106
107
108
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 106
def show
respond(:resource => @activation_key)
end
|
#update ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 79
def update
if @content_view_environments.present? || update_cves?
if single_assignment? && @content_view_environments.length == 1
@activation_key.assign_single_environment(
content_view: @content_view_environments.first.content_view,
lifecycle_environment: @content_view_environments.first.lifecycle_environment
)
else
@activation_key.update!(content_view_environments: @content_view_environments)
end
end
sync_task(::Actions::Katello::ActivationKey::Update, @activation_key, activation_key_params)
respond_for_show(:resource => @activation_key)
end
|