summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-06 16:10:38 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-06 16:10:38 +0000
commitc5eb2977d7750a6f3255941f72a1002259468834 (patch)
tree0363458fc082e664f3bb7c5f7b6ed74290c772cc
parent2c46cf084bcb0f06121f2fc4374379cc6f45ea0d (diff)
parent70f5291808469a808eb2bee70e9e97acc7716bb6 (diff)
downloadgitlab-ce-c5eb2977d7750a6f3255941f72a1002259468834.tar.gz
Merge branch 'add-current-user-to-autocomplete' into 'master'
Always add current user to autocomplete controller to support filter by "Me" ### What does this MR do? This MR always adds the current user to the autocomplete list of users. ### Why was this MR needed? Normally only the members from a team or the group are shown in the autocomplete list. However, this prevents a user from filtering issues belong to him/her if the user does not belong directly to either. To make this filtering more usable, we can be sure to add the current user to the list, which the JavaScript code will move to the top of the list. ### What are the relevant issue numbers? Partial fix #2202 See merge request !1100
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/autocomplete_controller.rb2
-rw-r--r--features/steps/project/forked_merge_requests.rb5
-rw-r--r--spec/controllers/autocomplete_controller_spec.rb22
4 files changed, 28 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 2cfed16b499..a8b115519a8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased)
- Fix "Network" and "Graphs" pages for branches with encoded slashes (Stan Hu)
- Fix errors deleting and creating branches with encoded slashes (Stan Hu)
+ - Always add current user to autocomplete controller to support filter by "Me" (Stan Hu)
- Fix multi-line syntax highlighting (Stan Hu)
- Fix network graph when branch name has single quotes (Stan Hu)
- Add "Confirm user" button in user admin page (Stan Hu)
diff --git a/app/controllers/autocomplete_controller.rb b/app/controllers/autocomplete_controller.rb
index 52e9c58b47c..5c3ca8e23c9 100644
--- a/app/controllers/autocomplete_controller.rb
+++ b/app/controllers/autocomplete_controller.rb
@@ -33,6 +33,8 @@ class AutocompleteController < ApplicationController
@users = @users.search(params[:search]) if params[:search].present?
@users = @users.active
@users = @users.page(params[:page]).per(PER_PAGE)
+ # Always include current user if available to filter by "Me"
+ @users = User.find(@users.pluck(:id) + [current_user.id]).uniq if current_user
render json: @users, only: [:name, :username, :id], methods: [:avatar_url]
end
diff --git a/features/steps/project/forked_merge_requests.rb b/features/steps/project/forked_merge_requests.rb
index 3e6beb20e78..2a333222fb2 100644
--- a/features/steps/project/forked_merge_requests.rb
+++ b/features/steps/project/forked_merge_requests.rb
@@ -137,10 +137,11 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
end
step 'I should see the users from the target project ID' do
- expect(page).to have_selector('.user-result', visible: true, count: 2)
+ expect(page).to have_selector('.user-result', visible: true, count: 3)
users = page.all('.user-name')
expect(users[0].text).to eq 'Unassigned'
- expect(users[1].text).to eq @project.users.first.name
+ expect(users[1].text).to eq current_user.name
+ expect(users[2].text).to eq @project.users.first.name
end
# Verify a link is generated against the correct project
diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb
index 1230017c270..3521d690259 100644
--- a/spec/controllers/autocomplete_controller_spec.rb
+++ b/spec/controllers/autocomplete_controller_spec.rb
@@ -4,6 +4,7 @@ describe AutocompleteController do
let!(:project) { create(:project) }
let!(:user) { create(:user) }
let!(:user2) { create(:user) }
+ let!(:non_member) { create(:user) }
context 'project members' do
before do
@@ -61,6 +62,27 @@ describe AutocompleteController do
end
end
+ context 'non-member login for public project' do
+ let!(:project) { create(:project, :public) }
+
+ before do
+ sign_in(non_member)
+ project.team << [user, :master]
+ end
+
+ let(:body) { JSON.parse(response.body) }
+
+ describe 'GET #users with project ID' do
+ before do
+ get(:users, project_id: project.id)
+ end
+
+ it { expect(body).to be_kind_of(Array) }
+ it { expect(body.size).to eq 2 }
+ it { expect(body.map { |u| u['username'] }).to match_array([user.username, non_member.username]) }
+ end
+ end
+
context 'all users' do
before do
sign_in(user)