Commit df0b99e2 authored by Sean McGivern's avatar Sean McGivern Committed by Regis

Merge branch '2337-fix-external-users-elasticsearch' into 'security-9-1-ee'

Respect the external user setting in elasticsearch

See merge request !512
parent 86051969
......@@ -208,7 +208,7 @@ module Elastic
{ term: { visibility_level: Project::PUBLIC } }
end
if current_user
if current_user && !current_user.external?
conditions << if feature
{
bool: {
......
---
title: Respect the external user setting in Elasticsearch
merge_request:
author:
......@@ -214,7 +214,7 @@ module Gitlab
}
}
if current_user
if current_user && !current_user.external?
conditions << {
bool: {
filter: [
......
......@@ -5,7 +5,9 @@ describe 'GlobalSearch' do
let(:admin) { create :user, admin: true }
let(:auditor) {create :user, auditor: true }
let(:non_member) { create :user }
let(:external_non_member) { create :user, external: true }
let(:member) { create :user }
let(:external_member) { create :user, external: true }
let(:guest) { create :user }
before do
......@@ -13,6 +15,7 @@ describe 'GlobalSearch' do
Gitlab::Elastic::Helper.create_empty_index
project.team << [member, :developer]
project.team << [external_member, :developer]
project.team << [guest, :guest]
end
......@@ -32,8 +35,10 @@ describe 'GlobalSearch' do
expect_no_items_to_be_found(admin)
expect_no_items_to_be_found(auditor)
expect_no_items_to_be_found(member)
expect_no_items_to_be_found(external_member)
expect_no_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
......@@ -43,8 +48,10 @@ describe 'GlobalSearch' do
expect_items_to_be_found(admin)
expect_items_to_be_found(auditor)
expect_items_to_be_found(member)
expect_items_to_be_found(external_member)
expect_non_code_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
end
......@@ -59,8 +66,10 @@ describe 'GlobalSearch' do
expect_no_items_to_be_found(admin)
expect_no_items_to_be_found(auditor)
expect_no_items_to_be_found(member)
expect_no_items_to_be_found(external_member)
expect_no_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
......@@ -70,8 +79,10 @@ describe 'GlobalSearch' do
expect_items_to_be_found(admin)
expect_items_to_be_found(auditor)
expect_items_to_be_found(member)
expect_items_to_be_found(external_member)
expect_items_to_be_found(guest)
expect_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
......@@ -81,8 +92,10 @@ describe 'GlobalSearch' do
expect_items_to_be_found(admin)
expect_items_to_be_found(auditor)
expect_items_to_be_found(member)
expect_items_to_be_found(external_member)
expect_non_code_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
end
......@@ -97,8 +110,10 @@ describe 'GlobalSearch' do
expect_no_items_to_be_found(admin)
expect_no_items_to_be_found(auditor)
expect_no_items_to_be_found(member)
expect_no_items_to_be_found(external_member)
expect_no_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
......@@ -108,8 +123,10 @@ describe 'GlobalSearch' do
expect_items_to_be_found(admin)
expect_items_to_be_found(auditor)
expect_items_to_be_found(member)
expect_items_to_be_found(external_member)
expect_items_to_be_found(guest)
expect_items_to_be_found(non_member)
expect_items_to_be_found(external_non_member)
expect_items_to_be_found(nil)
end
......@@ -119,8 +136,10 @@ describe 'GlobalSearch' do
expect_items_to_be_found(admin)
expect_items_to_be_found(auditor)
expect_items_to_be_found(member)
expect_items_to_be_found(external_member)
expect_non_code_items_to_be_found(guest)
expect_no_items_to_be_found(non_member)
expect_no_items_to_be_found(external_non_member)
expect_no_items_to_be_found(nil)
end
end
......@@ -166,15 +185,15 @@ describe 'GlobalSearch' do
end
def expect_non_code_items_to_be_found(user)
results = search(guest, 'term')
results = search(user, 'term')
expect(results.issues_count).not_to eq(0)
expect(results.wiki_blobs_count).not_to eq(0)
expect(results.merge_requests_count).to eq(0)
expect(search(guest, 'def').blobs_count).to eq(0)
expect(search(guest, 'add').commits_count).to eq(0)
expect(search(user, 'def').blobs_count).to eq(0)
expect(search(user, 'add').commits_count).to eq(0)
end
def search(user, search)
Search::GlobalService.new(user, search: search).execute
def search(user, search, snippets: false)
SearchService.new(user, search: search, snippets: snippets ? 'true' : 'false').search_results
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