Commit 22f44b50 authored by Alexis Reigel's avatar Alexis Reigel

add users search results to project scoped search

parent 70261ff1
......@@ -16,7 +16,7 @@ module Search
end
def scope
@scope ||= %w[notes issues merge_requests milestones wiki_blobs commits].delete(params[:scope]) { 'blobs' }
@scope ||= %w[notes issues merge_requests milestones wiki_blobs commits users].delete(params[:scope]) { 'blobs' }
end
end
end
......@@ -45,6 +45,12 @@
= _("Commits")
%span.badge.badge-pill
= @search_results.commits_count
- if can?(current_user, :read_users_list)
%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)
- elsif @show_snippets
%li{ class: active_when(@scope == 'snippet_blobs') }
......
......@@ -22,11 +22,17 @@ module Gitlab
paginated_blobs(wiki_blobs, page)
when 'commits'
Kaminari.paginate_array(commits).page(page).per(per_page)
when 'users'
users.page(page).per(per_page)
else
super(scope, page, false)
end
end
def users
super.where(id: @project.users)
end
def blobs_count
@blobs_count ||= blobs.count
end
......
......@@ -25,22 +25,4 @@ 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
require 'spec_helper'
describe 'User searches for users' do
context 'when on the dashboard' do
it 'finds the user' do
create(:user, username: 'gob_bluth', name: 'Gob Bluth')
sign_in(create(:user))
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
context 'when on the project page' do
it 'finds the user belonging to the project' do
project = create(:project)
user1 = create(:user, username: 'gob_bluth', name: 'Gob Bluth')
create(:project_member, :developer, user: user1, project: project)
user2 = create(:user, username: 'michael_bluth', name: 'Michael Bluth')
create(:project_member, :developer, user: user2, project: project)
create(:user, username: 'gob_2018', name: 'George Oscar Bluth')
sign_in(user1)
visit projects_path(project)
fill_in 'search', with: 'gob'
click_button 'Go'
expect(page).to have_content('Gob Bluth')
expect(page).to have_content('@gob_bluth')
expect(page).not_to have_content('Michael Bluth')
expect(page).not_to have_content('@michael_bluth')
expect(page).not_to have_content('George Oscar Bluth')
expect(page).not_to have_content('@gob_2018')
end
end
end
......@@ -412,4 +412,20 @@ describe Gitlab::ProjectSearchResults do
end
end
end
describe 'user search' do
let(:project) { create(:project) }
it 'returns the users belonging to the project matching the search query' do
user1 = create(:user, username: 'gob_bluth')
create(:project_member, :developer, user: user1, project: project)
user2 = create(:user, username: 'michael_bluth')
create(:project_member, :developer, user: user2, project: project)
create(:user, username: 'gob_2018')
expect(described_class.new(user, project, 'gob').objects('users')).to eq [user1]
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