Index: app/controllers/search_controller.rb
===================================================================
--- app/controllers/search_controller.rb (revision 1366)
+++ app/controllers/search_controller.rb (working copy)
@@ -28,6 +28,7 @@
@question.strip!
@all_words = params[:all_words] || (params[:submit] ? false : true)
@titles_only = !params[:titles_only].nil?
+ @all_projects = !@project || !params[:all_projects].nil?
offset = nil
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
@@ -38,17 +39,23 @@
return
end
- if @project
- # only show what the user is allowed to view
- @object_types = %w(issues news documents changesets wiki_pages messages)
- @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
-
- @scope = @object_types.select {|t| params[t]}
- @scope = @object_types if @scope.empty?
+ @object_types = %w(issues news documents changesets wiki_pages messages)
+
+ # only show what the user is allowed to view
+ if !@all_projects
+ @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
else
- @object_types = @scope = %w(projects)
+ @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, nil, {:global => true})}
end
+ #allow searching for projects when not inside one
+ if !@project
+ @object_types << "projects"
+ end
+
+ @scope = @object_types.select {|t| params[t]}
+ @scope = @object_types if @scope.empty?
+
# extract tokens from the question
# eg. hello "bye bye" => ["hello", "bye bye"]
@tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
@@ -62,37 +69,36 @@
like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
@results = []
limit = 10
- if @project
- @scope.each do |s|
- @results += s.singularize.camelcase.constantize.search(like_tokens, @project,
- :all_words => @all_words,
- :titles_only => @titles_only,
- :limit => (limit+1),
- :offset => offset,
- :before => params[:previous].nil?)
+
+ @scope.each do |s|
+
+ if @all_projects
+ projects_to_search = Project.find :all
+ projects_to_search.select {|p| User.current.allowed_to?("view_#{s}".to_sym, p)}
+ else
+ projects_to_search = @project
end
- @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
- if params[:previous].nil?
- @pagination_previous_date = @results[0].event_datetime if offset && @results[0]
- if @results.size > limit
- @pagination_next_date = @results[limit-1].event_datetime
- @results = @results[0, limit]
- end
- else
- @pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
- if @results.size > limit
- @pagination_previous_date = @results[-(limit)].event_datetime
- @results = @results[-(limit), limit]
- end
+
+ @results += s.singularize.camelcase.constantize.search(like_tokens, projects_to_search,
+ :all_words => @all_words,
+ :titles_only => @titles_only,
+ :limit => (limit+1),
+ :offset => offset,
+ :before => params[:previous].nil?)
+ end
+ @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
+ if params[:previous].nil?
+ @pagination_previous_date = @results[0].event_datetime if offset && @results[0]
+ if @results.size > limit
+ @pagination_next_date = @results[limit-1].event_datetime
+ @results = @results[0, limit]
end
else
- operator = @all_words ? ' AND ' : ' OR '
- @results += Project.find(:all,
- :limit => limit,
- :conditions => [ (["(#{Project.visible_by(User.current)}) AND (LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
- ) if @scope.include? 'projects'
- # if only one project is found, user is redirected to its overview
- redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
+ @pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
+ if @results.size > limit
+ @pagination_previous_date = @results[-(limit)].event_datetime
+ @results = @results[-(limit), limit]
+ end
end
else
@question = ""
Index: app/views/search/index.rhtml
===================================================================
--- app/views/search/index.rhtml (revision 1366)
+++ app/views/search/index.rhtml (working copy)
@@ -11,6 +11,9 @@
+<% if @project %>
+
+<% end%>
<%= link_to highlight_tokens(truncate(e.event_title, 255), @tokens), e.event_url %>
<%= highlight_tokens(e.event_description, @tokens) %>
+ <% if @all_projects and e.respond_to?('project') %>
+