diff --git a/app/controllers/katello/api/v2/api_controller.rb b/app/controllers/katello/api/v2/api_controller.rb index 03709ff8fce..63b78b2b910 100644 --- a/app/controllers/katello/api/v2/api_controller.rb +++ b/app/controllers/katello/api/v2/api_controller.rb @@ -45,6 +45,12 @@ class Api::V2::ApiController < ::Api::V2::BaseController param :object_root, String, :desc => N_("root-node of single-resource responses (optional)") param :root_name, String, :desc => N_("root-node of collection contained in responses (default: 'results')") + def resource_class + @resource_class ||= resource_name.classify.constantize + rescue NameError + @resource_class ||= "Katello::#{resource_name.classify}".constantize + end + def item_search(item_class, param_hash, options) fail "@search_service search not defined" if @search_service.nil? if param_hash[:order] @@ -79,10 +85,10 @@ def item_search(item_class, param_hash, options) } end - def scoped_search(query, default_sort_by, default_sort_order) + def scoped_search(query, default_sort_by, default_sort_order, resource = resource_class) total = query.count - sub_total = query.search_for(*search_options).count - query = query.search_for(*search_options) + sub_total = resource.search_for(*search_options).merge(query).count + query = resource.search_for(*search_options).merge(query) sort_attr = params[:sort_by] || default_sort_by sort_attr = "#{query.table_name}.#{sort_attr}" unless sort_attr.to_s.include?('.') diff --git a/app/controllers/katello/api/v2/content_view_filters_controller.rb b/app/controllers/katello/api/v2/content_view_filters_controller.rb index 5975ba7419b..ef860c630fb 100644 --- a/app/controllers/katello/api/v2/content_view_filters_controller.rb +++ b/app/controllers/katello/api/v2/content_view_filters_controller.rb @@ -98,7 +98,7 @@ def available_errata scoped = scoped.of_type(params[:types]) if params[:types] respond_for_index :template => '../errata/index', - :collection => scoped_search(scoped, 'issued', 'desc') + :collection => scoped_search(scoped, 'issued', 'desc', Erratum) end api :GET, "/content_views/:content_view_id/filters/:id/available_package_groups",