Commit 8cac0b16 authored by Dylan Griffith's avatar Dylan Griffith

De-normalize project visibility_level in issues in Elasticsearch

This is necessary to search issues correctly without joining to the
parent project. The previous case where we only set
`issues_access_level` will not correctly handle "Internal" projects
because "Internal" does not change the `issues_access_level` of the
project and we need a way to ensure that issues from "Internal" projects
are only found by logged in users.
parent 780e7fd5
...@@ -13,6 +13,7 @@ module Elastic ...@@ -13,6 +13,7 @@ module Elastic
end end
data['assignee_id'] = safely_read_attribute_for_elasticsearch(:assignee_ids) data['assignee_id'] = safely_read_attribute_for_elasticsearch(:assignee_ids)
data['visibility_level'] = target.project.visibility_level
# protect against missing project_feature and set visibility to PRIVATE # protect against missing project_feature and set visibility to PRIVATE
# if the project_feature is missing on a project # if the project_feature is missing on a project
......
...@@ -107,6 +107,7 @@ RSpec.describe Issue, :elastic do ...@@ -107,6 +107,7 @@ RSpec.describe Issue, :elastic do
it "returns json with all needed elements" do it "returns json with all needed elements" do
assignee = create(:user) assignee = create(:user)
project = create(:project, :internal)
issue = create :issue, project: project, assignees: [assignee] issue = create :issue, project: project, assignees: [assignee]
expected_hash = issue.attributes.extract!( expected_hash = issue.attributes.extract!(
...@@ -129,7 +130,8 @@ RSpec.describe Issue, :elastic do ...@@ -129,7 +130,8 @@ RSpec.describe Issue, :elastic do
}) })
expected_hash['assignee_id'] = [assignee.id] expected_hash['assignee_id'] = [assignee.id]
expected_hash['issues_access_level'] = issue.project.project_feature.issues_access_level expected_hash['issues_access_level'] = ProjectFeature::ENABLED
expected_hash['visibility_level'] = Gitlab::VisibilityLevel::INTERNAL
expect(issue.__elasticsearch__.as_indexed_json).to eq(expected_hash) expect(issue.__elasticsearch__.as_indexed_json).to eq(expected_hash)
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