Commit 795361152887087cc781abf8c802f3518441012d
1 parent
d8b492ac
Exists in
master
and in
29 other branches
Fix infinite loop with context variable
Showing
2 changed files
with
14 additions
and
9 deletions
Show diff stats
plugins/solr/lib/solr_plugin.rb
... | ... | @@ -6,8 +6,6 @@ class SolrPlugin < Noosfero::Plugin |
6 | 6 | |
7 | 7 | include SolrPlugin::SearchHelper |
8 | 8 | |
9 | - delegate :params, :current_user, :to => :context | |
10 | - | |
11 | 9 | def self.plugin_name |
12 | 10 | "Solr" |
13 | 11 | end |
... | ... | @@ -28,11 +26,18 @@ class SolrPlugin < Noosfero::Plugin |
28 | 26 | return if empty_query?(query, category) && klass != Product |
29 | 27 | |
30 | 28 | solr_options = solr_options(class_asset(klass), category) |
31 | - user = context.send(:logged_in?) ? context.send(:user) : nil | |
32 | 29 | solr_options.merge!(products_options(user)) if klass == Product && empty_query?(query, category) |
33 | 30 | klass.find_by_contents(query, paginate_options, solr_options.merge(options)) |
34 | 31 | end |
35 | 32 | |
33 | + def method_missing method, *args, &block | |
34 | + if self.context.respond_to? method | |
35 | + self.context.send method, *args, &block | |
36 | + else | |
37 | + super method, *args, &block | |
38 | + end | |
39 | + end | |
40 | + | |
36 | 41 | end |
37 | 42 | |
38 | 43 | Dir[File.join(SolrPlugin.root_path, 'lib', 'ext', '*.rb')].each {|file| require_dependency file } | ... | ... |
plugins/solr/lib/solr_plugin/search_helper.rb
... | ... | @@ -58,7 +58,7 @@ module SolrPlugin::SearchHelper |
58 | 58 | end |
59 | 59 | |
60 | 60 | def results_only? |
61 | - context.params[:action] == 'index' | |
61 | + params[:action] == 'index' | |
62 | 62 | end |
63 | 63 | |
64 | 64 | def empty_query?(query, category) |
... | ... | @@ -88,18 +88,18 @@ module SolrPlugin::SearchHelper |
88 | 88 | solr_options = {} |
89 | 89 | if !multiple_search? |
90 | 90 | if !results_only? and asset_class.respond_to? :facets |
91 | - solr_options.merge! asset_class.facets_find_options(context.params[:facet]) | |
91 | + solr_options.merge! asset_class.facets_find_options(params[:facet]) | |
92 | 92 | solr_options[:all_facets] = true |
93 | 93 | end |
94 | 94 | solr_options[:filter_queries] ||= [] |
95 | 95 | solr_options[:filter_queries] += filters(asset) |
96 | - solr_options[:filter_queries] << "environment_id:#{context.environment.id}" | |
96 | + solr_options[:filter_queries] << "environment_id:#{environment.id}" | |
97 | 97 | solr_options[:filter_queries] << asset_class.facet_category_query.call(category) if category |
98 | 98 | |
99 | 99 | solr_options[:boost_functions] ||= [] |
100 | - context.params[:order_by] = nil if context.params[:order_by] == 'none' | |
101 | - if context.params[:order_by] | |
102 | - order = SortOptions[asset][context.params[:order_by].to_sym] | |
100 | + params[:order_by] = nil if params[:order_by] == 'none' | |
101 | + if params[:order_by] | |
102 | + order = SortOptions[asset][params[:order_by].to_sym] | |
103 | 103 | raise "Unknown order by" if order.nil? |
104 | 104 | order[:solr_opts].each do |opt, value| |
105 | 105 | solr_options[opt] = value.is_a?(Proc) ? instance_eval(&value) : value | ... | ... |