Class: Autocomplete::MoveToProjectFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/autocomplete/move_to_project_finder.rb

Overview

Finder that retrieves a list of projects that an issue can be moved to.

Constant Summary collapse

LIMIT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params = {}) ⇒ MoveToProjectFinder

current_user - The User object of the user that wants to view the list of

projects.

params - A Hash containing additional parameters to set.

The following parameters can be set (as Symbols):

  • search: An optional search query to apply to the list of projects.

  • project_id: The ID of a project to exclude from the returned relation.



19
20
21
22
23
# File 'app/finders/autocomplete/move_to_project_finder.rb', line 19

def initialize(current_user, params = {})
  @current_user = current_user
  @search = params[:search]
  @project_id = params[:project_id]
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/finders/autocomplete/move_to_project_finder.rb', line 6

def current_user
  @current_user
end

#project_idObject (readonly)

Returns the value of attribute project_id.



6
7
8
# File 'app/finders/autocomplete/move_to_project_finder.rb', line 6

def project_id
  @project_id
end

#searchObject (readonly)

Returns the value of attribute search.



6
7
8
# File 'app/finders/autocomplete/move_to_project_finder.rb', line 6

def search
  @search
end

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
33
# File 'app/finders/autocomplete/move_to_project_finder.rb', line 25

def execute
  current_user
    .projects_where_can_admin_issues
    .optionally_search(search, include_namespace: true)
    .excluding_project(project_id)
    .eager_load_namespace_and_owner
    .sorted_by_stars_desc
    .limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end