Class: Katello::Api::V2::ActivationKeysController
Constant Summary
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary
collapse
#auto_complete_search
#full_result_response, #resource_class, #scoped_search
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
147
148
149
150
151
152
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 147
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
172
173
174
175
176
177
178
179
180
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 172
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
109
110
111
112
113
114
115
116
117
118
119
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 109
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, :desc, :resource_class => HostCollection))
end
|
#available_releases ⇒ Object
123
124
125
126
127
128
129
130
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 123
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
204
205
206
207
208
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 204
def content_override
content_override = validate_content_overrides(params[:content_override])
@activation_key.set_content_override(content_override[:content_label], 'enabled', content_override[:value])
respond_for_show(:resource => @activation_key)
end
|
#copy ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 86
def copy
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.content_overrides.each do |content|
@new_activation_key.set_content_override(content['contentLabel'], content[:name], content[:value])
end
@activation_key.subscriptions.each do |subscription|
@new_activation_key.subscribe(subscription[:id])
end
respond_for_show(:resource => @new_activation_key)
end
|
#create ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 39
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)
@activation_key.reload
respond(:resource => @activation_key)
end
|
#destroy ⇒ Object
69
70
71
72
73
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 69
def destroy
task = sync_task(::Actions::Katello::ActivationKey::Destroy,
@activation_key)
respond_for_async(:resource => task)
end
|
#find_activation_key ⇒ Object
231
232
233
234
235
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 231
def find_activation_key
@activation_key = ActivationKey.find(params[:id])
fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:id] if @activation_key.nil?
@activation_key
end
|
#index ⇒ Object
25
26
27
28
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 25
def index
activation_key_includes = [:content_view, :environment, :host_collections, :organization]
respond(:collection => scoped_search(index_relation.uniq, :name, :desc, :includes => activation_key_includes))
end
|
#index_relation ⇒ Object
210
211
212
213
214
215
216
217
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 210
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
134
135
136
137
138
139
140
141
142
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 134
def product_content
content = @activation_key.available_content
response = {
:results => content,
:total => content.size,
:subtotal => content.size
}
respond_for_index :collection => response
end
|
#remove_host_collections ⇒ Object
157
158
159
160
161
162
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 157
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
188
189
190
191
192
193
194
195
196
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 188
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
78
79
80
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 78
def show
respond(:resource => @activation_key)
end
|
#subscriptions ⇒ Object
221
222
223
224
225
226
227
228
229
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 221
def subscriptions
subscriptions = @activation_key.get_key_pools.map { |sub| ActivationKeySubscriptionPresenter.new(sub) }
collection = subscriptions.map(&:subscription)
@collection = { :results => collection,
:total => collection.count,
:page => 1,
:per_page => collection.count,
:subtotal => collection.count }
end
|
#update ⇒ Object
62
63
64
65
|
# File 'app/controllers/katello/api/v2/activation_keys_controller.rb', line 62
def update
sync_task(::Actions::Katello::ActivationKey::Update, @activation_key, activation_key_params)
respond_for_show(:resource => @activation_key)
end
|