From 948150f050d14811f6fe1b327387e3c2c1b1fe31 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 2 Feb 2018 11:23:05 +0100 Subject: 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. --- .../bvl-fix-500-on-fork-without-restricted-visibility-levels.yml | 5 +++++ lib/gitlab/visibility_level.rb | 2 +- spec/lib/gitlab/visibility_level_spec.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/bvl-fix-500-on-fork-without-restricted-visibility-levels.yml diff --git a/changelogs/unreleased/bvl-fix-500-on-fork-without-restricted-visibility-levels.yml b/changelogs/unreleased/bvl-fix-500-on-fork-without-restricted-visibility-levels.yml new file mode 100644 index 00000000000..378f0ef7ce9 --- /dev/null +++ b/changelogs/unreleased/bvl-fix-500-on-fork-without-restricted-visibility-levels.yml @@ -0,0 +1,5 @@ +--- +title: Fix forking projects when no restricted visibility levels are defined applicationwide +merge_request: 16881 +author: +type: fixed diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb index 6ced06a863d..0b757b2a646 100644 --- a/lib/gitlab/visibility_level.rb +++ b/lib/gitlab/visibility_level.rb @@ -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) diff --git a/spec/lib/gitlab/visibility_level_spec.rb b/spec/lib/gitlab/visibility_level_spec.rb index d85dac630b4..2c1146ceff5 100644 --- a/spec/lib/gitlab/visibility_level_spec.rb +++ b/spec/lib/gitlab/visibility_level_spec.rb @@ -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 -- cgit v1.2.3