improve search
This commit is contained in:
parent
6339880d49
commit
92db8c7968
|
@ -8,6 +8,7 @@ class SearchController < ApplicationController
|
|||
Search.by_term_and_type(
|
||||
@query,
|
||||
@type,
|
||||
current_ability,
|
||||
{page: params[:page]}
|
||||
).each do |k, v|
|
||||
var = :"@#{k}"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class Search
|
||||
TYPES = ['projects', 'users', 'groups', 'platforms']
|
||||
|
||||
def self.by_term_and_type(term, type, paginate_params)
|
||||
def self.by_term_and_type(term, type, ability, paginate_params)
|
||||
results = {}
|
||||
case type
|
||||
when 'all'
|
||||
TYPES.each{ |t| results[t] = find_collection(t, term, paginate_params) }
|
||||
TYPES.each{ |t| results[t] = find_collection(t, term, ability, paginate_params) }
|
||||
when *TYPES
|
||||
results[type] = find_collection(type, term, paginate_params)
|
||||
results[type] = find_collection(type, term, ability, paginate_params)
|
||||
end
|
||||
results
|
||||
end
|
||||
|
@ -15,11 +15,14 @@ class Search
|
|||
class << self
|
||||
protected
|
||||
|
||||
def find_collection(type, term, paginate_params)
|
||||
type.classify.constantize.opened.
|
||||
search(term).
|
||||
search_order.
|
||||
paginate(paginate_params)
|
||||
def find_collection(type, term, ability, paginate_params)
|
||||
if type == 'users'
|
||||
User.opened
|
||||
else
|
||||
type.classify.constantize.accessible_by(ability, :read)
|
||||
end.search(term).
|
||||
search_order.
|
||||
paginate(paginate_params)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue