summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-07-11 06:16:59 -0700
committerStan Hu <stanhu@gmail.com>2015-07-11 06:19:32 -0700
commit96644c1fc146b55795d36cf4c03a80d2d58d112e (patch)
tree3b0e89647acbe79ef92bf58dd7b0e8f01c7ab424 /app
parentd0b240136a444a61c3c8960cba33f987022fa0f4 (diff)
downloadgitlab-ce-96644c1fc146b55795d36cf4c03a80d2d58d112e.tar.gz
Better handle unknown projects and groups for autocomplete
Diffstat (limited to 'app')
-rw-r--r--app/controllers/autocomplete_controller.rb37
1 files changed, 23 insertions, 14 deletions
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb
index 8b12643bb97..52e9c58b47c 100644
--- a/app/controllers/autocomplete_controller.rb
+++ b/app/controllers/autocomplete_controller.rb
@@ -2,25 +2,34 @@ class AutocompleteController < ApplicationController
skip_before_action :authenticate_user!, only: [:users]
def users
- @users =
- if params[:project_id].present?
- project = Project.find(params[:project_id])
+ begin
+ @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_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
+ if can?(current_user, :read_group, group)
+ group.users
+ end
+ elsif current_user
+ User.all
end
- elsif current_user
- User.all
- else
- User.none
+ rescue ActiveRecord::RecordNotFound
+ if current_user
+ return render json: {}, status: 404
end
+ end
+
+ if @users.nil? && current_user.nil?
+ authenticate_user!
+ end
+ @users ||= User.none
@users = @users.search(params[:search]) if params[:search].present?
@users = @users.active
@users = @users.page(params[:page]).per(PER_PAGE)