diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-02-02 11:23:05 +0100 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-02-02 13:17:32 +0100 |
commit | 948150f050d14811f6fe1b327387e3c2c1b1fe31 (patch) | |
tree | cea5fcebe31e084a58e698e3e802f194883b5ffb | |
parent | 8891fbd0a95bd1d2725d6d6187ff4eb21572c3cc (diff) | |
download | gitlab-ce-948150f050d14811f6fe1b327387e3c2c1b1fe31.tar.gz |
Avoid error when no restricted levels are definedbvl-fix-500-on-fork-without-restricted-visibility-levels
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.
-rw-r--r-- | changelogs/unreleased/bvl-fix-500-on-fork-without-restricted-visibility-levels.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/visibility_level.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/visibility_level_spec.rb | 9 |
3 files changed, 15 insertions, 1 deletions
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 |