Class: Katello::Api::V2::ProductsController
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
#create ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 73
def create
params[:product][:label] = labelize_params(product_params) if product_params
product = Product.new(product_params)
sync_task(::Actions::Katello::Product::Create, product, @organization)
respond(:resource => product)
end
|
#destroy ⇒ Object
101
102
103
104
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 101
def destroy
task = async_task(::Actions::Katello::Product::Destroy, @product)
respond_for_async :resource => task
end
|
#index ⇒ Object
38
39
40
41
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 38
def index
options = {:includes => [:sync_plan, :provider]}
respond(:collection => scoped_search(index_relation.uniq, :name, :desc, options))
end
|
#index_relation ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 43
def index_relation
query = Product.readable.where(:organization_id => @organization.id)
query = query.where(:provider_id => @organization.anonymous_provider.id) if params[:custom]
query = query.where(:name => params[:name]) if params[:name]
query = query.enabled if params[:enabled]
query = query.where(:id => @activation_key.products) if @activation_key
query = query.where(:id => @system.products) if @system
if params[:subscription_id]
pool = Pool.with_identifier(params[:subscription_id])
query = query.where(:id => pool.products) if pool
end
if sync_plan_id = params[:sync_plan_id]
query = if params[:available_for] == "sync_plan"
query.enabled.where("sync_plan_id != ? OR sync_plan_id IS NULL", sync_plan_id)
else
query.where(:sync_plan_id => sync_plan_id)
end
end
query
end
|
#show ⇒ Object
84
85
86
87
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 84
def show
find_product(:includes => [{:repositories => :environment}])
respond_for_show(:resource => @product)
end
|
#sync ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 108
def sync
syncable_repos = @product.library_repositories.has_url.syncable
if syncable_repos.empty?
msg = _("Unable to synchronize any repository. You either do not have the permission to"\
" synchronize or the selected repositories do not have a feed url.")
fail HttpErrors::UnprocessableEntity, msg
end
task = async_task(::Actions::BulkAction,
::Actions::Katello::Repository::Sync,
syncable_repos)
respond_for_async(:resource => task)
end
|
#update ⇒ Object
93
94
95
96
97
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 93
def update
sync_task(::Actions::Katello::Product::Update, @product, product_params)
respond(:resource => @product.reload)
end
|