add users search results to global search

This commit is contained in:
Alexis Reigel 2018-08-14 15:43:46 +02:00
parent c537043984
commit 70261ff11c
No known key found for this signature in database
GPG key ID: 55ADA7C7B683B329
6 changed files with 58 additions and 1 deletions

View file

@ -23,7 +23,7 @@ module Search
def allowed_scopes
strong_memoize(:allowed_scopes) do
%w[issues merge_requests milestones]
%w[issues merge_requests milestones users]
end
end

View file

@ -78,3 +78,8 @@
= _("Milestones")
%span.badge.badge-pill
= limited_count(@search_results.limited_milestones_count)
%li{ class: active_when(@scope == 'users') }
= link_to search_filter_path(scope: 'users') do
Users
%span.badge.badge-pill
= limited_count(@search_results.limited_users_count)

View file

@ -0,0 +1,8 @@
%ul.content-list
%li
.avatar-cell.d-none.d-sm-block
= user_avatar(user: user, user_name: user.name, css_class: 'd-none d-sm-inline avatar s40')
.user-info
= link_to user_path(user), class: 'd-none d-sm-inline' do
.item-title= user.name
.cgray= user.to_reference

View file

@ -32,6 +32,8 @@ module Gitlab
merge_requests.page(page).per(per_page)
when 'milestones'
milestones.page(page).per(per_page)
when 'users'
users.page(page).per(per_page)
else
Kaminari.paginate_array([]).page(page).per(per_page)
end
@ -71,6 +73,12 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def limited_users_count
@limited_users_count ||= users.limit(count_limit).count
end
# rubocop:enable CodeReuse/ActiveRecord
def single_commit_result?
false
end
@ -129,6 +137,12 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
def users
return [] unless Ability.allowed?(current_user, :read_users_list)
UsersFinder.new(current_user, search: query).execute
end
def default_scope
'projects'
end

View file

@ -25,4 +25,22 @@ describe 'Global search' do
expect(page).to have_selector('.gl-pagination .next')
end
end
describe 'users search' do
it 'shows the found user under the Users tab' do
create(:user, username: 'gob_bluth', name: 'Gob Bluth')
visit dashboard_projects_path
fill_in 'search', with: 'gob'
click_button 'Go'
expect(page).to have_content('Users 1')
click_on('Users 1')
expect(page).to have_content('Gob Bluth')
expect(page).to have_content('@gob_bluth')
end
end
end

View file

@ -121,6 +121,18 @@ describe Gitlab::SearchResults do
results.objects('issues')
end
end
describe '#users' do
it 'returns an empty array when the current_user is not allowed to read users list' do
expect(results.objects('users')).to be_empty
end
it 'calls the UsersFinder' do
expect(UsersFinder).to receive(:new).with(user, search: 'foo').and_call_original
results.objects('users')
end
end
end
it 'does not list issues on private projects' do