Commit 70261ff1 authored by Alexis Reigel's avatar Alexis Reigel

add users search results to global search

parent c5370439
...@@ -23,7 +23,7 @@ module Search ...@@ -23,7 +23,7 @@ module Search
def allowed_scopes def allowed_scopes
strong_memoize(:allowed_scopes) do strong_memoize(:allowed_scopes) do
%w[issues merge_requests milestones] %w[issues merge_requests milestones users]
end end
end end
......
...@@ -78,3 +78,8 @@ ...@@ -78,3 +78,8 @@
= _("Milestones") = _("Milestones")
%span.badge.badge-pill %span.badge.badge-pill
= limited_count(@search_results.limited_milestones_count) = 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)
%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
...@@ -32,6 +32,8 @@ module Gitlab ...@@ -32,6 +32,8 @@ module Gitlab
merge_requests.page(page).per(per_page) merge_requests.page(page).per(per_page)
when 'milestones' when 'milestones'
milestones.page(page).per(per_page) milestones.page(page).per(per_page)
when 'users'
users.page(page).per(per_page)
else else
Kaminari.paginate_array([]).page(page).per(per_page) Kaminari.paginate_array([]).page(page).per(per_page)
end end
...@@ -71,6 +73,12 @@ module Gitlab ...@@ -71,6 +73,12 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # 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? def single_commit_result?
false false
end end
...@@ -129,6 +137,12 @@ module Gitlab ...@@ -129,6 +137,12 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # 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 def default_scope
'projects' 'projects'
end end
......
...@@ -25,4 +25,22 @@ describe 'Global search' do ...@@ -25,4 +25,22 @@ describe 'Global search' do
expect(page).to have_selector('.gl-pagination .next') expect(page).to have_selector('.gl-pagination .next')
end end
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 end
...@@ -121,6 +121,18 @@ describe Gitlab::SearchResults do ...@@ -121,6 +121,18 @@ describe Gitlab::SearchResults do
results.objects('issues') results.objects('issues')
end end
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 end
it 'does not list issues on private projects' do it 'does not list issues on private projects' do
......
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