Commit 04e5eb3b authored by Stan Hu's avatar Stan Hu

Fix 500 error accessing restricted visibility levels

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/22522 introduced a
regression that caused a 500 error if the
`application_settings.restricted_visibility_levels` column were `nil`.
Since there is no NOT NULL constraint, there's no guarantee that it is
populated with the proper serialized YAML data.

To fix this specific problem, we can account for `nil` values, but we
should fix this at the database level.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/215552
parent 5b91a85c
......@@ -52,7 +52,7 @@ module ExploreHelper
end
def public_visibility_restricted?
Gitlab::CurrentSettings.restricted_visibility_levels.include? Gitlab::VisibilityLevel::PUBLIC
Gitlab::CurrentSettings.restricted_visibility_levels&.include? Gitlab::VisibilityLevel::PUBLIC
end
private
......
---
title: Fix 500 error on accessing restricted levels
merge_request: 30313
author:
type: fixed
......@@ -17,4 +17,25 @@ describe ExploreHelper do
expect(helper.explore_nav_links).to contain_exactly(*menu_items)
end
end
describe '#public_visibility_restricted?' do
using RSpec::Parameterized::TableSyntax
where(:visibility_levels, :expected_status) do
nil | nil
[Gitlab::VisibilityLevel::PRIVATE] | false
[Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::INTERNAL] | false
[Gitlab::VisibilityLevel::PUBLIC] | true
end
with_them do
before do
stub_application_setting(restricted_visibility_levels: visibility_levels)
end
it 'returns the expected status' do
expect(helper.public_visibility_restricted?).to eq(expected_status)
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