Class: Katello::Api::V2::ActivationKeysController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #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
148
149
150
151
152
153
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 148
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
|
#add_subscriptions ⇒ Object
173
174
175
176
177
178
179
180
181
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 173
def add_subscriptions
if params[:subscriptions]
params[:subscriptions].each { |subscription| @activation_key.subscribe(subscription[:id], subscription[:quantity]) }
elsif params[:subscription_id]
@activation_key.subscribe(params[:subscription_id], params[:quantity])
end
respond_for_index(:collection => subscription_index, :template => 'subscriptions')
end
|
#available_host_collections ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 122
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
136
137
138
139
140
141
142
143
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 136
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 207
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).uniq
unless specified_labels.size == existing_labels.size
missing_labels = specified_labels - existing_labels.pluck(:label)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 98
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,
:auto_attach => @activation_key.auto_attach
)
@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
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 47
def create
@activation_key = ActivationKey.new(activation_key_params) do |activation_key|
activation_key.environment = @environment if @environment
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
81
82
83
84
85
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 81
def destroy
task = sync_task(::Actions::Katello::ActivationKey::Destroy,
@activation_key)
respond_for_async(:resource => task)
end
|
#index ⇒ Object
27
28
29
30
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 27
def index
activation_key_includes = [:content_view, :environment, :host_collections, :organization]
respond(:collection => scoped_search(index_relation.distinct, :name, :asc, :includes => activation_key_includes))
end
|
#index_relation ⇒ Object
239
240
241
242
243
244
245
246
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 239
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.where(:environment_id => @environment) if @environment
activation_keys = activation_keys.where(:content_view_id => @content_view) if @content_view
activation_keys
end
|
#product_content ⇒ Object
234
235
236
237
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 234
def product_content
end
|
#remove_host_collections ⇒ Object
158
159
160
161
162
163
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 158
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
|
#remove_subscriptions ⇒ Object
189
190
191
192
193
194
195
196
197
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 189
def remove_subscriptions
if params[:subscriptions]
params[:subscriptions].each { |subscription| @activation_key.unsubscribe(subscription[:id]) }
elsif params[:subscription_id]
@activation_key.unsubscribe(params[:subscription_id])
end
respond_for_index(:collection => subscription_index, :template => 'subscriptions')
end
|
#show ⇒ Object
90
91
92
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 90
def show
respond(:resource => @activation_key)
end
|
#update ⇒ Object
74
75
76
77
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 74
def update
sync_task(::Actions::Katello::ActivationKey::Update, @activation_key, activation_key_params)
respond_for_show(:resource => @activation_key)
end
|