Commit dcd27c69 authored by Markus Koller's avatar Markus Koller

Remove ES parent relation for project snippets

https://gitlab.com/gitlab-org/gitlab/merge_requests/18459 added a join
relation on project snippets to support searching public/internal
projects.

Since this requires recreating the index this broke indexing on existing
indices, so we decided to revert this change for now.

We're keeping most of the changes from the original MR since it also
refactored the ES snippet classes to align with the other models.
parent f4255379
---
title: Revert ES support for public/internal project snippets
merge_request: 19715
author:
type: fixed
......@@ -66,7 +66,6 @@ module Elastic
blob
wiki_blob
commit
snippet
)
}
# ES6 requires a single type per index, so we implement our own "type"
......
......@@ -74,28 +74,6 @@ module Elastic
filter_conditions = []
# Include public/internal project snippets for accessible projects
filter_conditions << {
bool: {
filter: [
{ terms: { visibility_level: Gitlab::VisibilityLevel.levels_for_user(user) } },
{
has_parent: {
parent_type: 'project',
query: {
bool: project_ids_query(
user,
options[:project_ids],
options[:public_and_internal_projects],
'snippets'
)
}
}
}
]
}
}
# Include all project snippets for authorized projects
if user
filter_conditions << {
......
......@@ -30,6 +30,12 @@ module Elastic
data.merge(generic_attributes)
end
# TODO: Reenable support for public/internal project snippets
# https://gitlab.com/gitlab-org/gitlab/issues/2358
def es_parent
nil
end
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe 'Snippet elastic search', :js, :elastic, :sidekiq_might_not_need_inline do
describe 'Snippet elastic search', :js, :elastic, :aggregate_failures, :sidekiq_might_not_need_inline do
let(:public_project) { create(:project, :public) }
let(:authorized_user) { create(:user) }
let(:authorized_project) { create(:project, namespace: authorized_user.namespace) }
......@@ -31,13 +31,16 @@ describe 'Snippet elastic search', :js, :elastic, :sidekiq_might_not_need_inline
submit_search('snippet')
end
# TODO: Reenable support for public/internal project snippets
# https://gitlab.com/gitlab-org/gitlab/issues/35760
context 'as anonymous user' do
let(:current_user) { nil }
it 'finds only public snippets' do
within('.results') do
expect(page).to have_content('public personal snippet')
expect(page).to have_content('public project snippet')
expect(page).not_to have_content('public project snippet')
expect(page).not_to have_content('internal personal snippet')
expect(page).not_to have_content('internal project snippet')
......@@ -57,10 +60,10 @@ describe 'Snippet elastic search', :js, :elastic, :sidekiq_might_not_need_inline
it 'finds only public and internal snippets' do
within('.results') do
expect(page).to have_content('public personal snippet')
expect(page).to have_content('public project snippet')
expect(page).not_to have_content('public project snippet')
expect(page).to have_content('internal personal snippet')
expect(page).to have_content('internal project snippet')
expect(page).not_to have_content('internal project snippet')
expect(page).not_to have_content('private personal snippet')
expect(page).not_to have_content('private project snippet')
......@@ -77,10 +80,10 @@ describe 'Snippet elastic search', :js, :elastic, :sidekiq_might_not_need_inline
it 'finds only public, internal, and authorized private snippets' do
within('.results') do
expect(page).to have_content('public personal snippet')
expect(page).to have_content('public project snippet')
expect(page).not_to have_content('public project snippet')
expect(page).to have_content('internal personal snippet')
expect(page).to have_content('internal project snippet')
expect(page).not_to have_content('internal project snippet')
expect(page).not_to have_content('private personal snippet')
expect(page).not_to have_content('private project snippet')
......
......@@ -137,11 +137,7 @@ describe Snippet, :elastic do
'author_id',
'visibility_level'
).merge({
'type' => snippet.es_type,
'join_field' => {
'name' => snippet.es_type,
'parent' => snippet.es_parent
}
'type' => snippet.es_type
})
expect(snippet.__elasticsearch__.as_indexed_json).to eq(expected_hash)
......
......@@ -101,8 +101,7 @@ describe Elastic::IndexRecordService, :elastic do
'issue',
'merge_request',
'milestone',
'note',
'snippet'
'note'
)
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