Commit 948150f0 authored by Bob Van Landuyt's avatar Bob Van Landuyt

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.
parent 8891fbd0
---
title: Fix forking projects when no restricted visibility levels are defined applicationwide
merge_request: 16881
author:
type: fixed
......@@ -60,7 +60,7 @@ module Gitlab
def allowed_levels
restricted_levels = current_application_settings.restricted_visibility_levels
self.values - restricted_levels
self.values - Array(restricted_levels)
end
def closest_allowed_level(target_level)
......
......@@ -57,6 +57,15 @@ describe Gitlab::VisibilityLevel do
expect(described_class.allowed_levels)
.to contain_exactly(described_class::PRIVATE, described_class::PUBLIC)
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
describe '.closest_allowed_level' 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