Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-27 05:06:19 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-03-27 05:06:19 +0300
commit26053c870530ebb6d276a364ea9d40d202ead0de (patch)
tree72ea7fa39b9c89ed76bbee181ffab45475b4a469 /app/controllers/autocomplete_controller.rb
parentdfb4fcb68544717d5cc74a2035a9d9c5bd61fc21 (diff)
Add autocomplete controller
Diffstat (limited to 'app/controllers/autocomplete_controller.rb')
-rw-r--r--app/controllers/autocomplete_controller.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb
new file mode 100644
index 00000000000..11af9895261
--- /dev/null
+++ b/app/controllers/autocomplete_controller.rb
@@ -0,0 +1,30 @@
+class AutocompleteController < ApplicationController
+ def users
+ @users =
+ if params[:project_id].present?
+ project = Project.find(params[:project_id])
+
+ if can?(current_user, :read_project, project)
+ project.team.users
+ end
+ elsif params[:group_id]
+ group = Group.find(params[:group_id])
+
+ if can?(current_user, :read_group, group)
+ group.users
+ end
+ else
+ User.all
+ end
+
+ @users = @users.search(params[:search]) if params[:search].present?
+ @users = @users.active
+ @users = @users.page(params[:page]).per(PER_PAGE)
+ render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
+ end
+
+ def user
+ @user = User.find(params[:id])
+ render json: @user, only: [:name, :username, :id], methods: [:avatar_url]
+ end
+end