Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #9167: Fix chained scopes when using scoped_search in API #4965

Merged
merged 1 commit into from
Feb 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/controllers/katello/api/v2/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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?('.')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down