Class: AutocompleteController

Inherits:
ApplicationController show all
Defined in:
app/controllers/autocomplete_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Instance Method Details

#userObject


29
30
31
32
# File 'app/controllers/autocomplete_controller.rb', line 29

def user
  @user = User.find(params[:id])
  render json: @user, only: [:name, :username, :id], methods: [:avatar_url]
end

#usersObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/autocomplete_controller.rb', line 5

def users
  @users ||= User.none
  @users = @users.search(params[:search]) if params[:search].present?
  @users = @users.active
  @users = @users.reorder(:name)
  @users = @users.page(params[:page])

  if params[:search].blank?
    # Include current user if available to filter by "Me"
    if params[:current_user] && current_user
      @users = [*@users, current_user]
    end

    if params[:author_id].present?
      author = User.find_by_id(params[:author_id])
      @users = [author, *@users] if author
    end

    @users.uniq!
  end

  render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
end