Class: Api::V2::SccProductsController

Inherits:
BaseController
  • Object
show all
Includes:
Api::Version2, Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/api/v2/scc_products_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



28
29
30
31
32
# File 'app/controllers/api/v2/scc_products_controller.rb', line 28

def index
  scope = resource_scope
  scope = scope.where.not(:product_id => nil) if ::Foreman::Cast.to_bool(params[:subscribed_only])
  @scc_products = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
end

#metadata_subtotalObject



15
16
17
18
19
20
21
# File 'app/controllers/api/v2/scc_products_controller.rb', line 15

def 
  if @scc_products.present?
    @scc_products.count
  else
    super
  end
end

#showObject



37
38
# File 'app/controllers/api/v2/scc_products_controller.rb', line 37

def show
end

#subscribeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/api/v2/scc_products_controller.rb', line 43

def subscribe
  subcribe_task = ForemanTasks.async_task(::Actions::SccManager::SubscribeProduct, @scc_product, {}) if @scc_product
  respond_to do |format|
    if subcribe_task
      format.json { render json: subcribe_task.to_json, status: :ok }
    else
      format.json { render json: 'Failed to subscribe product'.to_json, status: :not_found }
    end
  end
rescue ::Foreman::Exception => e
  render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity
rescue ForemanTasks::Lock::LockConflict => e
  render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity
end