summaryrefslogtreecommitdiff
path: root/app/services/search/global_service.rb
blob: a3c655493a5d228f0d0b76bcf976eea219983338 (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
module Search
  class GlobalService
    attr_accessor :current_user, :params

    def initialize(user, params)
      @current_user, @params = user, params.dup
    end

    def execute
      group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
      projects = ProjectsFinder.new.execute(current_user)

      if group
        projects = projects.inside_path(group.full_path)
      end

      Gitlab::SearchResults.new(current_user, projects, params[:search])
    end

    def scope
      @scope ||= %w[issues merge_requests milestones].delete(params[:scope]) { 'projects' }
    end
  end
end