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
- #for_host ⇒ 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
127 128 129 130 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 127 def delete_manifest task = async_task(::Actions::Katello::Organization::ManifestDelete, @organization) respond_for_async :resource => task end |
#for_host ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 139 def for_host match_attached = params[:available_for] != "host" params[:match_host] = ::Foreman::Cast.to_bool(params[:match_host]) if params[:match_host] params[:match_installed] = ::Foreman::Cast.to_bool(params[:match_installed]) if params[:match_installed] params[:no_overlap] = ::Foreman::Cast.to_bool(params[:no_overlap]) if params[:no_overlap] @host.subscription_facet.candlepin_consumer.filtered_pools(match_attached, params[:match_host], params[:match_installed], params[:no_overlap]) end |
#index ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 32 def index unless @organization || @activation_key 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, :consumed, :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', 'Consumed', '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, ) if params[:activation_key_id] key_pools = @activation_key.get_key_pools collection[:results] = collection[:results].map do |pool| ActivationKeySubscriptionsPresenter.new(pool, key_pools) end end collection[:results] = collection[:results].map do |pool| ProductHostCountPresenter.new(pool) end respond(:collection => collection) end end end |
#index_relation ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 71 def index_relation return for_host if params[:host_id] return available_for_activation_key if params[:available_for] == "activation_key" 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 = collection.for_activation_key(@activation_key) if params[:activation_key_id] collection end |
#manifest_history ⇒ Object
134 135 136 137 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 134 def manifest_history @manifest_history = @organization.manifest_history respond_with_template_collection(params[:action], "subscriptions", collection: @manifest_history) end |
#refresh_manifest ⇒ Object
120 121 122 123 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 120 def refresh_manifest task = async_task(::Actions::Katello::Organization::ManifestRefresh, @organization) respond_for_async :resource => task end |
#show ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 86 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/katello/api/v2/subscriptions_controller.rb', line 103 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 |