diff options
author | Maxim Rydkin <maks.rydkin@gmail.com> | 2017-08-23 22:33:56 +0300 |
---|---|---|
committer | Maxim Rydkin <maks.rydkin@gmail.com> | 2017-09-10 18:31:05 +0300 |
commit | fbbb985a03d0b51e28a3df5a3c3f21a81540405f (patch) | |
tree | 4eeb1f2e52ae82c5917ab1cf340a493200e5e50d /app/controllers/autocomplete_controller.rb | |
parent | 5d952f756bcf0355fc5d86d819dfc6913c0ae351 (diff) | |
download | gitlab-ce-fbbb985a03d0b51e28a3df5a3c3f21a81540405f.tar.gz |
extract finder and add first test
Diffstat (limited to 'app/controllers/autocomplete_controller.rb')
-rw-r--r-- | app/controllers/autocomplete_controller.rb | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb index dfc8bd0ba81..8e945f90f76 100644 --- a/app/controllers/autocomplete_controller.rb +++ b/app/controllers/autocomplete_controller.rb @@ -6,28 +6,7 @@ class AutocompleteController < ApplicationController before_action :find_users, only: [:users] def users - @users ||= User.none - @users = @users.active - @users = @users.reorder(:name) - @users = @users.search(params[:search]) if params[:search].present? - @users = @users.where.not(id: params[:skip_users]) if params[:skip_users].present? - @users = @users.page(params[:page]).per(params[:per_page]) - - if params[:todo_filter].present? && current_user - @users = @users.todo_authors(current_user.id, params[:todo_state_filter]) - end - - if params[:search].blank? - # Include current user if available to filter by "Me" - if params[:current_user].present? && current_user - @users = [current_user, *@users].uniq - end - - if params[:author_id].present? && current_user - author = User.find_by_id(params[:author_id]) - @users = [author, *@users].uniq if author - end - end + @users = YetAnotherUsersFinder.new(params: params, current_user: current_user, users: @users).execute render json: @users, only: [:name, :username, :id], methods: [:avatar_url] end |