diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-03-17 03:03:55 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-03-17 03:03:55 +0300 |
commit | 39772a01646e35a6d26d843edc9195c79f960970 (patch) | |
tree | d941a8a89afb993a891121dc202a173d43cabf22 /app | |
parent | ba0d2a461b07c32419a9641da7d6160a2a96a62f (diff) | |
parent | 2e672c39a09577a0a16e75a10a249c923d8ee863 (diff) |
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
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/visibility_level_helper.rb | 2 | ||||
-rw-r--r-- | app/models/application_setting.rb | 8 |
3 files changed, 9 insertions, 5 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 8f7d5e8006f..9a5685877f8 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -21,7 +21,9 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController def application_setting_params 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| level.to_i end diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index 7c090dc594c..0d573e72a80 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -62,6 +62,6 @@ module VisibilityLevelHelper def restricted_visibility_levels(show_all = false) return [] if current_user.is_admin? && !show_all - current_application_settings.restricted_visibility_levels + current_application_settings.restricted_visibility_levels || [] end end diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 6abdf0c755a..1c87db613ae 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -27,9 +27,11 @@ class ApplicationSetting < ActiveRecord::Base if: :home_page_url_column_exist validates_each :restricted_visibility_levels do |record, attr, value| - value.each do |level| - unless Gitlab::VisibilityLevel.options.has_value?(level) - record.errors.add(attr, "'#{level}' is not a valid visibility level") + unless value.nil? + value.each do |level| + unless Gitlab::VisibilityLevel.options.has_value?(level) + record.errors.add(attr, "'#{level}' is not a valid visibility level") + end end end end |