Class: Katello::Api::V2::SubscriptionsController
- Inherits:
-
ApiController
- Object
- Api::V2::BaseController
- ApiController
- Katello::Api::V2::SubscriptionsController
- Includes:
- Concerns::FilteredAutoCompleteSearch
- Defined in:
- app/controllers/katello/api/v2/subscriptions_controller.rb
Constant Summary
Constants included from Concerns::FilteredAutoCompleteSearch
Concerns::FilteredAutoCompleteSearch::PAGE_SIZE
Instance Method Summary collapse
- #delete_manifest ⇒ Object
- #index ⇒ Object
- #index_relation ⇒ Object
- #manifest_history ⇒ Object
- #refresh_manifest ⇒ Object
- #show ⇒ Object
- #upload ⇒ Object
Methods included from Concerns::FilteredAutoCompleteSearch
Methods inherited from ApiController
#empty_search_query?, #full_result_response, #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
Methods included from Katello::Api::Version2
Instance Method Details
#delete_manifest ⇒ Object
108 109 110 111 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 108 def delete_manifest task = async_task(::Actions::Katello::Organization::ManifestDelete, @organization) respond_for_async :resource => task end |
#index ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 22 def index unless @organization fail HttpErrors::NotFound, _("Organization Information not provided.") end = { resource_class: Pool, includes: [:subscription] } base_args = [index_relation.distinct, :name, :asc] respond_to do |format| format.csv do [:csv] = true collection = scoped_search(*base_args, ) fields = [:id, :subscription_id, :name, :cp_id, :organization_id, :sockets, :cores, :start_date, :end_date, :quantity, :account_number, :contract_number, :support_level, :ram, :stacking_id, :multi_entitlement, :type, :product_id, :unmapped_guest, :virt_only, :virt_who, :upstream?, :product_host_count] headers = ['Pool Id Number', 'Subscription Id', 'Name', 'Pool Id', 'Organization Id', 'Sockets', 'Cores', 'Start Date', 'End Date', 'Quantity', 'Account Number', 'Contract Number', 'Support Level', 'RAM', 'Stacking Id', 'Multi Entitlement', 'Type', 'Product Id', 'Unmapped Guest', 'Virt Only', 'Requires Virt Who', 'Upstream', 'Product Host Count'] csv_response(collection, fields, headers) end format.any do collection = scoped_search(*base_args, ) collection[:results] = collection[:results].map do |pool| ProductHostCountPresenter.new(pool) end respond(:collection => collection) end end end |
#index_relation ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 55 def index_relation collection = Pool.readable collection = collection.where("#{Katello::Subscription.table_name}.name" => params[:name]) if params[:name] collection = collection.where(:unmapped_guest => false) collection = collection.where(organization: Organization.find(params[:organization_id])) if params[:organization_id] collection end |
#manifest_history ⇒ Object
115 116 117 118 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 115 def manifest_history @manifest_history = @organization.manifest_history respond_with_template_collection(params[:action], "subscriptions", collection: @manifest_history) end |
#refresh_manifest ⇒ Object
101 102 103 104 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 101 def refresh_manifest task = async_task(::Actions::Katello::Organization::ManifestRefresh, @organization) respond_for_async :resource => task end |
#show ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 67 def show @resource = Katello::Pool.with_identifier(params[:id]) fail ActiveRecord::RecordNotFound, N_('Subscription not found') unless @resource&.readable? if params[:organization_id] && @resource.organization_id != params[:organization_id].to_i fail HttpErrors::BadRequest, N_('This subscription is not relevant to the current organization.') end @resource = ProductHostCountPresenter.new(@resource) respond(:resource => @resource) end |
#upload ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 84 def upload fail HttpErrors::BadRequest, _("No manifest file uploaded") if params[:content].blank? begin # candlepin requires that the file has a zip file extension temp_file = File.new(File.join("#{Rails.root}/tmp", "import_#{SecureRandom.hex(10)}.zip"), 'wb+', 0600) temp_file.write params[:content].read ensure temp_file.close end task = async_task(::Actions::Katello::Organization::ManifestImport, @organization, File.(temp_file.path), params[:force]) respond_for_async :resource => task end |