Merge branch 'fix-null-visibility' into 'master'
Handle null restricted_visibility_levels setting Fix a 500 error when the `restricted_visibility_levels` setting is null in the database - see #2134. See merge request !1705
This commit is contained in:
commit
39772a0164
|
@ -21,7 +21,9 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
|
||||||
|
|
||||||
def application_setting_params
|
def application_setting_params
|
||||||
restricted_levels = params[:application_setting][:restricted_visibility_levels]
|
restricted_levels = params[:application_setting][:restricted_visibility_levels]
|
||||||
unless restricted_levels.nil?
|
if restricted_levels.nil?
|
||||||
|
params[:application_setting][:restricted_visibility_levels] = []
|
||||||
|
else
|
||||||
restricted_levels.map! do |level|
|
restricted_levels.map! do |level|
|
||||||
level.to_i
|
level.to_i
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,6 +62,6 @@ module VisibilityLevelHelper
|
||||||
|
|
||||||
def restricted_visibility_levels(show_all = false)
|
def restricted_visibility_levels(show_all = false)
|
||||||
return [] if current_user.is_admin? && !show_all
|
return [] if current_user.is_admin? && !show_all
|
||||||
current_application_settings.restricted_visibility_levels
|
current_application_settings.restricted_visibility_levels || []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,9 +27,11 @@ class ApplicationSetting < ActiveRecord::Base
|
||||||
if: :home_page_url_column_exist
|
if: :home_page_url_column_exist
|
||||||
|
|
||||||
validates_each :restricted_visibility_levels do |record, attr, value|
|
validates_each :restricted_visibility_levels do |record, attr, value|
|
||||||
value.each do |level|
|
unless value.nil?
|
||||||
unless Gitlab::VisibilityLevel.options.has_value?(level)
|
value.each do |level|
|
||||||
record.errors.add(attr, "'#{level}' is not a valid visibility level")
|
unless Gitlab::VisibilityLevel.options.has_value?(level)
|
||||||
|
record.errors.add(attr, "'#{level}' is not a valid visibility level")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue