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