summaryrefslogtreecommitdiff
path: root/app/controllers/search_controller.rb
blob: 2a2748dc1fb0ddab3222dacfe46b7b3e35ad052c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class SearchController < ApplicationController
  def show
    project_id = params[:project_id]
    group_id = params[:group_id]

    project_ids = current_user.authorized_projects.map(&:id)

    if group_id.present?
      @group = Group.find(group_id)
      group_project_ids = @group.projects.map(&:id)
      project_ids.select! { |id| group_project_ids.include?(id)}
    elsif project_id.present?
      @project = Project.find(params[:project_id])
      project_ids.select! { |id| id == project_id.to_i}
    end

    result = SearchContext.new(project_ids, current_user, params).execute

    @projects       = result[:projects]
    @merge_requests = result[:merge_requests]
    @issues         = result[:issues]
    @wiki_pages     = result[:wiki_pages]
    @blobs          = Kaminari.paginate_array(result[:blobs]).page(params[:page]).per(20)
    @total_results = @projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count
  end
end