add users search results to group scoped search
This commit is contained in:
parent
a52d1dbb0f
commit
a8818bab76
4 changed files with 84 additions and 0 deletions
|
@ -11,6 +11,12 @@ module Search
|
||||||
@group = group
|
@group = group
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
Gitlab::GroupSearchResults.new(
|
||||||
|
current_user, projects, group, params[:search], default_project_filter: default_project_filter
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def projects
|
def projects
|
||||||
return Project.none unless group
|
return Project.none unless group
|
||||||
return @projects if defined? @projects
|
return @projects if defined? @projects
|
||||||
|
|
17
lib/gitlab/group_search_results.rb
Normal file
17
lib/gitlab/group_search_results.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Gitlab
|
||||||
|
class GroupSearchResults < SearchResults
|
||||||
|
def initialize(current_user, limit_projects, group, query, default_project_filter: false, per_page: 20)
|
||||||
|
super(current_user, limit_projects, query, default_project_filter: default_project_filter, per_page: per_page)
|
||||||
|
|
||||||
|
@group = group
|
||||||
|
end
|
||||||
|
|
||||||
|
# rubocop:disable CodeReuse/ActiveRecord
|
||||||
|
def users
|
||||||
|
super.where(id: @group.users_with_descendants)
|
||||||
|
end
|
||||||
|
# rubocop:enable CodeReuse/ActiveRecord
|
||||||
|
end
|
||||||
|
end
|
|
@ -50,4 +50,34 @@ describe 'User searches for users' do
|
||||||
expect(page).not_to have_content('@gob_2018')
|
expect(page).not_to have_content('@gob_2018')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when on the group page' do
|
||||||
|
it 'finds the user belonging to the group' do
|
||||||
|
group = create(:group)
|
||||||
|
|
||||||
|
user1 = create(:user, username: 'gob_bluth', name: 'Gob Bluth')
|
||||||
|
create(:group_member, :developer, user: user1, group: group)
|
||||||
|
|
||||||
|
user2 = create(:user, username: 'michael_bluth', name: 'Michael Bluth')
|
||||||
|
create(:group_member, :developer, user: user2, group: group)
|
||||||
|
|
||||||
|
create(:user, username: 'gob_2018', name: 'George Oscar Bluth')
|
||||||
|
|
||||||
|
sign_in(user1)
|
||||||
|
|
||||||
|
visit group_path(group)
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
31
spec/lib/gitlab/group_search_results_spec.rb
Normal file
31
spec/lib/gitlab/group_search_results_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Gitlab::GroupSearchResults do
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
describe 'user search' do
|
||||||
|
let(:group) { create(:group) }
|
||||||
|
|
||||||
|
it 'returns the users belonging to the group matching the search query' do
|
||||||
|
user1 = create(:user, username: 'gob_bluth')
|
||||||
|
create(:group_member, :developer, user: user1, group: group)
|
||||||
|
|
||||||
|
user2 = create(:user, username: 'michael_bluth')
|
||||||
|
create(:group_member, :developer, user: user2, group: group)
|
||||||
|
|
||||||
|
create(:user, username: 'gob_2018')
|
||||||
|
|
||||||
|
expect(described_class.new(user, anything, group, 'gob').objects('users')).to eq [user1]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the user belonging to the subgroup matching the search query', :nested_groups do
|
||||||
|
user1 = create(:user, username: 'gob_bluth')
|
||||||
|
subgroup = create(:group, parent: group)
|
||||||
|
create(:group_member, :developer, user: user1, group: subgroup)
|
||||||
|
|
||||||
|
create(:user, username: 'gob_2018')
|
||||||
|
|
||||||
|
expect(described_class.new(user, anything, group, 'gob').objects('users')).to eq [user1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue