Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-09 16:23:07 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-09 16:23:07 +0400
commit768d21654a135130a28278c46cf413dbe65f8c81 (patch)
tree40eddc6791e2f377c1eaa51683d2396744137019 /app/contexts
parentfc60c391ae93e0a9ef9a5123ee7d71cd504e4366 (diff)
Better search login for global context. Improved tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/contexts')
-rw-r--r--app/contexts/search/global_context.rb23
1 files changed, 9 insertions, 14 deletions
diff --git a/app/contexts/search/global_context.rb b/app/contexts/search/global_context.rb
index c0966bb5220..74e746018e6 100644
--- a/app/contexts/search/global_context.rb
+++ b/app/contexts/search/global_context.rb
@@ -11,22 +11,17 @@ module Search
query = Shellwords.shellescape(query) if query.present?
return result unless query.present?
-
- projects = current_user.authorized_projects
-
- if params[:group_id].present?
- group = Group.find_by_id(params[:group_id])
- projects = projects.where(namespace_id: group.id) if group
- end
-
+ authorized_projects_ids = []
+ authorized_projects_ids += current_user.authorized_projects.pluck(:id) if current_user
+ authorized_projects_ids += Project.public_or_internal_only(current_user).pluck(:id)
+
+ group = Group.find_by_id(params[:group_id]) if params[:group_id].present?
+ projects = Project.where(id: authorized_projects_ids)
+ projects = projects.where(namespace_id: group.id) if group
+ projects = projects.search(query)
project_ids = projects.pluck(:id)
- visibility_levels = if current_user
- [Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC]
- else
- [Gitlab::VisibilityLevel::PUBLIC]
- end
- result[:projects] = Project.where("projects.id in (?) OR projects.visibility_level in (?)", project_ids, visibility_levels).search(query).limit(20)
+ result[:projects] = projects.limit(20)
result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20)
result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20)
result[:total_results] = %w(projects issues merge_requests).sum { |items| result[items.to_sym].size }