Skip to content
Snippets Groups Projects
Commit 5e65212f authored by Madelein van Niekerk's avatar Madelein van Niekerk Committed by John Mason
Browse files

Enable advanced user search regardless of namespace

parent c97e3f1f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,7 @@
module Search
module Elasticsearchable
SCOPES_ONLY_BASIC_SEARCH = %w(epics).freeze
SCOPES_ADVANCED_SEARCH_ALWAYS_ENABLED = %w[users].freeze
 
def use_elasticsearch?
return false if params[:basic_search]
Loading
Loading
@@ -16,6 +17,10 @@ def elasticsearchable_scope
raise NotImplementedError
end
 
def global_elasticsearchable_scope?
SCOPES_ADVANCED_SEARCH_ALWAYS_ENABLED.include?(params[:scope])
end
def advanced_user_search?
return true unless params[:scope] == 'users'
return false unless ::Feature.enabled?(:advanced_user_search, current_user, type: :ops)
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@ module GroupService
 
override :elasticsearchable_scope
def elasticsearchable_scope
group
group unless global_elasticsearchable_scope?
end
 
override :zoekt_searchable_scope
Loading
Loading
Loading
Loading
@@ -57,7 +57,7 @@ def use_default_branch?
 
override :elasticsearchable_scope
def elasticsearchable_scope
project
project unless global_elasticsearchable_scope?
end
 
override :zoekt_searchable_scope
Loading
Loading
Loading
Loading
@@ -71,6 +71,20 @@ def elasticsearchable_scope
end
end
 
describe '#global_elasticsearchable_scope?' do
it 'is false' do
expect(class_instance).not_to be_global_elasticsearchable_scope
end
context 'when scope is users' do
let(:params) { { scope: 'users' } }
it 'is true' do
expect(class_instance).to be_global_elasticsearchable_scope
end
end
end
describe "#advanced_user_search?" do
it 'is true when the scope is not users' do
expect(class_instance).to be_advanced_user_search
Loading
Loading
Loading
Loading
@@ -62,6 +62,23 @@
end
end
 
describe '#elasticsearchable_scope' do
let(:service) { described_class.new(user, group, scope: scope) }
let(:scope) { 'blobs' }
it 'is set to group' do
expect(service.elasticsearchable_scope).to eq(group)
end
context 'when the scope is users' do
let(:scope) { 'users' }
it 'is nil' do
expect(service.elasticsearchable_scope).to be_nil
end
end
end
context 'when searching with Zoekt' do
let(:service) { described_class.new(user, group, search: 'foobar', scope: scope, basic_search: basic_search, page: page) }
let(:use_zoekt) { true }
Loading
Loading
Loading
Loading
@@ -43,6 +43,25 @@
end
end
 
describe '#elasticsearchable_scope' do
let(:service) { described_class.new(user, project, scope: scope) }
let(:scope) { 'blobs' }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
it 'is set to project' do
expect(service.elasticsearchable_scope).to eq(project)
end
context 'when the scope is users' do
let(:scope) { 'users' }
it 'is nil' do
expect(service.elasticsearchable_scope).to be_nil
end
end
end
context 'when searching with Zoekt' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, namespace: user.namespace) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment