Commit 6ef49436 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'weimeng-user-autocomplete-fix' into 'master'

Only show author in autocomplete dropdown if author is active

See merge request gitlab-org/gitlab-ce!27292
parents 873df37e 1150ab80
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Autocomplete module Autocomplete
class UsersFinder class UsersFinder
include Gitlab::Utils::StrongMemoize
# The number of users to display in the results is hardcoded to 20, and # The number of users to display in the results is hardcoded to 20, and
# pagination is not supported. This ensures that performance remains # pagination is not supported. This ensures that performance remains
# consistent and removes the need for implementing keyset pagination to # consistent and removes the need for implementing keyset pagination to
...@@ -31,7 +33,7 @@ module Autocomplete ...@@ -31,7 +33,7 @@ module Autocomplete
# Include current user if available to filter by "Me" # Include current user if available to filter by "Me"
items.unshift(current_user) if prepend_current_user? items.unshift(current_user) if prepend_current_user?
if prepend_author? && (author = User.find_by_id(author_id)) if prepend_author? && author&.active?
items.unshift(author) items.unshift(author)
end end
end end
...@@ -41,6 +43,12 @@ module Autocomplete ...@@ -41,6 +43,12 @@ module Autocomplete
private private
def author
strong_memoize(:author) do
User.find_by_id(author_id)
end
end
# Returns the users based on the input parameters, as an Array. # Returns the users based on the input parameters, as an Array.
# #
# This method is separate so it is easier to extend in EE. # This method is separate so it is easier to extend in EE.
......
---
title: Only show in autocomplete when author active
merge_request: 27292
author:
type: fixed
...@@ -26,9 +26,17 @@ describe Autocomplete::UsersFinder do ...@@ -26,9 +26,17 @@ describe Autocomplete::UsersFinder do
it { is_expected.to match_array([project.owner]) } it { is_expected.to match_array([project.owner]) }
context 'when author_id passed' do context 'when author_id passed' do
context 'and author is active' do
let(:params) { { author_id: user1.id } }
it { is_expected.to match_array([project.owner, user1]) }
end
context 'and author is blocked' do
let(:params) { { author_id: user2.id } } let(:params) { { author_id: user2.id } }
it { is_expected.to match_array([project.owner, user2]) } it { is_expected.to match_array([project.owner]) }
end
end end
end end
...@@ -104,9 +112,9 @@ describe Autocomplete::UsersFinder do ...@@ -104,9 +112,9 @@ describe Autocomplete::UsersFinder do
end end
context 'when filtered by author_id' do context 'when filtered by author_id' do
let(:params) { { author_id: user2.id } } let(:params) { { author_id: user1.id } }
it { is_expected.to match_array([user2, user1, external_user, omniauth_user, current_user]) } it { is_expected.to match_array([user1, external_user, omniauth_user, current_user]) }
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment