Commit 563ebecfbbf1b36e59b4a481aa0ba9d9b88872ec

Authored by Macartur Sousa
1 parent b89df43e

Elasticsearch: Removed filter for admin

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
plugins/elasticsearch/helpers/elasticsearch_helper.rb
... ... @@ -89,6 +89,8 @@ module ElasticsearchHelper
89 89  
90 90 def query_method(expression="", models=[], categories=[])
91 91 query = {}
  92 + current_user ||= nil
  93 +
92 94 query[:query] = {
93 95 filtered: {
94 96 query: query_string(expression, models),
... ... @@ -99,7 +101,7 @@ module ElasticsearchHelper
99 101 }
100 102  
101 103 query[:query][:filtered][:filter][:bool] = {
102   - should: models.map {|model| model.filter(environment: @environment.id)}
  104 + should: models.map {|model| model.filter(environment: @environment.id, user: current_user )}
103 105 }
104 106  
105 107 unless categories.blank?
... ...
plugins/elasticsearch/lib/searchable_model/filter.rb
... ... @@ -10,20 +10,24 @@ module Filter
10 10 module ClassMethods
11 11  
12 12 def filter options={}
13   - environment = options[:environment].presence
14 13  
15 14 result_filter = {}
16 15 result_filter[:indices] = {:index => self.index_name, :no_match_filter => "none" }
17   - result_filter[:indices][:filter] = { :bool => self.filter_bool(environment) }
  16 + result_filter[:indices][:filter] = { :bool => self.filter_bool(options) }
18 17  
19 18 result_filter
20 19 end
21 20  
22   - def filter_bool environment
  21 + def filter_bool options={}
  22 + environment = options[:environment].presence
  23 + user = options[:user].presence
  24 +
23 25 result_filter = {}
24 26  
25 27 result_filter[:must] = [ NestedEnvironment::filter(environment) ]
26 28  
  29 + return result_filter if user and user.person.is_admin?
  30 +
27 31 self.nested_filter.each {|filter| result_filter[:must].append(filter)} if self.respond_to? :nested_filter
28 32 self.must.each {|filter| result_filter[:must].append(filter) } if self.respond_to? :must
29 33  
... ...