Avoid error when no restricted levels are defined

When no visibility levels are defined they could sometimes return
`nil` instead of an empty array. In this case we want to allow all
levels.
This commit is contained in:
Bob Van Landuyt 2018-02-02 11:23:05 +01:00
parent 8891fbd0a9
commit 948150f050
3 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
title: Fix forking projects when no restricted visibility levels are defined applicationwide
merge_request: 16881
author:
type: fixed

View file

@ -60,7 +60,7 @@ module Gitlab
def allowed_levels def allowed_levels
restricted_levels = current_application_settings.restricted_visibility_levels restricted_levels = current_application_settings.restricted_visibility_levels
self.values - restricted_levels self.values - Array(restricted_levels)
end end
def closest_allowed_level(target_level) def closest_allowed_level(target_level)

View file

@ -57,6 +57,15 @@ describe Gitlab::VisibilityLevel do
expect(described_class.allowed_levels) expect(described_class.allowed_levels)
.to contain_exactly(described_class::PRIVATE, described_class::PUBLIC) .to contain_exactly(described_class::PRIVATE, described_class::PUBLIC)
end end
it 'returns all levels when no visibility level was set' do
allow(described_class)
.to receive_message_chain('current_application_settings.restricted_visibility_levels')
.and_return(nil)
expect(described_class.allowed_levels)
.to contain_exactly(described_class::PRIVATE, described_class::INTERNAL, described_class::PUBLIC)
end
end end
describe '.closest_allowed_level' do describe '.closest_allowed_level' do