Commit c41cb549 authored by Dylan Griffith's avatar Dylan Griffith Committed by Arturo Herrero

Default note *_access_level to DISABLED instead of nil

This relates to some more possible edge cases we may have in our data.
Since we are running a migration to backfill all these settings that
will run forever unless a value is set it is better to always have some
fallback that isn't `nil` as the migration will never finish.

In this case we can be sure that anything that is required to have a
project but doesn't for whatever reason shouldn't show up in searches
and therefore it's safe to just set `*_access_level = DISABLED`.
parent 8f5cdb12
......@@ -57,7 +57,7 @@ module Elastic
# protect against missing project and project_feature and set visibility to PRIVATE
# if the project_feature is missing on a project
def safely_read_project_feature_for_elasticsearch(feature)
return unless target.project
return ProjectFeature::DISABLED unless target.project
if target.project.project_feature
target.project.project_feature.access_level(feature)
......
......@@ -181,6 +181,19 @@ RSpec.describe Note, :elastic do
expect(note_json).to have_key('visibility_level')
expect(note_json['visibility_level']).to eq(expected_visibility_level)
end
context 'when the project does not exist' do
before do
note.project = nil
end
it 'has DISABLED access_level' do
if access_level
expect(note_json).to have_key(access_level)
expect(note_json[access_level]).to eq(ProjectFeature::DISABLED)
end
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