Class: Katello::Api::V2::ProductsController
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
#create ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 80
def create
params[:product][:label] = labelize_params(product_params) if product_params
product = Product.new(product_params.to_h)
sync_task(::Actions::Katello::Product::Create, product, @organization)
respond_for_create(:resource => product)
end
|
#destroy ⇒ Object
109
110
111
112
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 109
def destroy
task = async_task(::Actions::Katello::Product::Destroy, @product)
respond_for_async :resource => task
end
|
#index ⇒ Object
45
46
47
48
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 45
def index
options = {:includes => [:sync_plan, :provider]}
respond(:collection => scoped_search(index_relation.distinct, :name, :asc, options))
end
|
#index_relation ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 50
def index_relation
query = Product.readable.where(:organization_id => @organization.id)
query = query.custom if ::Foreman::Cast.to_bool params[:custom]
query = query.redhat if ::Foreman::Cast.to_bool params[:redhat_only]
query = query.where(:name => params[:name]) if params[:name]
query = query.enabled if ::Foreman::Cast.to_bool params[:enabled]
query = query.where(:id => @activation_key.products) if @activation_key
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
92
93
94
95
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 92
def show
find_product(:includes => [{:root_repositories => {:repositories => :environment}}])
respond_for_show(:resource => @product)
end
|
#sync ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 116
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
101
102
103
104
105
|
# File 'app/controllers/katello/api/v2/products_controller.rb', line 101
def update
sync_task(::Actions::Katello::Product::Update, @product, product_params.to_h)
respond(:resource => @product.reload)
end
|