Commit 4e0635c6 authored by Terri Chu's avatar Terri Chu Committed by Robert Speicher

Update Elasticsearch document for issues

This change requires that the Elasticsearch
mapping has been updated using a data
migration. The json used to generate issue
documents is updated to send two new fields:
gitlab_migration_version and issues_access_level.
parent 2df84ef4
......@@ -14,6 +14,15 @@ module Elastic
data['assignee_id'] = safely_read_attribute_for_elasticsearch(:assignee_ids)
# protect against missing project_feature and set visibility to PRIVATE
# if the project_feature is missing on a project
begin
data['issues_access_level'] = target.project.project_feature.issues_access_level
rescue NoMethodError => e
Gitlab::ErrorTracking.track_exception(e, project_id: target.project_id, issue_id: target.id)
data['issues_access_level'] = ProjectFeature::PRIVATE
end
data.merge(generic_attributes)
end
end
......
......@@ -56,7 +56,7 @@ RSpec.describe Issue, :elastic do
end
end
it "searches issues" do
it "searches issues", :aggregate_failures do
Sidekiq::Testing.inline! do
create :issue, title: 'bla-bla term1', project: project
create :issue, description: 'bla-bla term2', project: project
......@@ -129,10 +129,20 @@ RSpec.describe Issue, :elastic do
})
expected_hash['assignee_id'] = [assignee.id]
expected_hash['issues_access_level'] = issue.project.project_feature.issues_access_level
expect(issue.__elasticsearch__.as_indexed_json).to eq(expected_hash)
end
it 'handles a project missing project_feature' do
issue = create :issue, project: project
allow(issue.project).to receive(:project_feature).and_return(nil)
expect(Gitlab::ErrorTracking).to receive(:track_exception)
expect(issue.__elasticsearch__.as_indexed_json['issues_access_level']).to eq(ProjectFeature::PRIVATE)
end
context 'field length limits' do
context 'when there is an elasticsearch_indexed_field_length limit' do
it 'truncates to the default plan limit' do
......
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