Class: Search::ProjectService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, Filter
Defined in:
app/services/search/project_service.rb

Constant Summary collapse

ALLOWED_SCOPES =
%w[blobs issues merge_requests wiki_blobs commits notes milestones users].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, project_or_projects, params) ⇒ ProjectService

Returns a new instance of ProjectService.



12
13
14
15
16
# File 'app/services/search/project_service.rb', line 12

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

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



10
11
12
# File 'app/services/search/project_service.rb', line 10

def current_user
  @current_user
end

#paramsObject

Returns the value of attribute params.



10
11
12
# File 'app/services/search/project_service.rb', line 10

def params
  @params
end

#projectObject

Returns the value of attribute project.



10
11
12
# File 'app/services/search/project_service.rb', line 10

def project
  @project
end

Instance Method Details

#allowed_scopesObject



29
30
31
# File 'app/services/search/project_service.rb', line 29

def allowed_scopes
  ALLOWED_SCOPES
end

#executeObject



18
19
20
21
22
23
24
25
26
27
# File 'app/services/search/project_service.rb', line 18

def execute
  Gitlab::ProjectSearchResults.new(current_user,
    params[:search],
    project: project,
    repository_ref: params[:repository_ref],
    order_by: params[:order_by],
    sort: params[:sort],
    filters: filters
  )
end

#scopeObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/search/project_service.rb', line 33

def scope
  strong_memoize(:scope) do
    search_navigation = Search::Navigation.new(user: current_user, project: project)
    scope = params[:scope]
    next scope if allowed_scopes.include?(scope) && search_navigation.tab_enabled_for_project?(scope.to_sym)

    allowed_scopes.find do |s|
      search_navigation.tab_enabled_for_project?(s.to_sym)
    end
  end
end