diff options
author | Stan Hu <stanhu@gmail.com> | 2017-03-18 12:29:25 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-03-19 01:39:48 +0300 |
commit | 681af5bc4fe646a981c1d0bbbeddef00f5cee3b8 (patch) | |
tree | 9a65ccf9ccd4e2cd4836638b42613e6bc0ae77f0 /app | |
parent | 5d71d9fb9d6ca89710549fbfef62d105d9544a30 (diff) |
Fix Error 500 when application settings are saved
Due to a Rails bug, fetching the application settings from Redis
may prevent the attribute methods from being loaded for the `ApplicationSetting`
model. More details here: https://github.com/rails/rails/issues/27348
There was also a secondary problem introduced by overriding these
association methods which caused all default visibility levels to be
set to `nil`. Before, the previous implementation allowed the string
"20" to be saved as an integer, while now a table lookup happens
before that. We fix this by enforcing the integer value in the
controller and default to PRIVATE.
Closes #29674
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/application_settings_controller.rb | 12 | ||||
-rw-r--r-- | app/models/application_setting.rb | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 8d831ffdd70..11f69c14a5d 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -45,6 +45,18 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController end def application_setting_params + default_visibilities = [:default_project_visibility, :default_snippet_visibility, :default_group_visibility] + + default_visibilities.each do |visibility| + value = params[:application_setting][visibility] + params[:application_setting][visibility] = + if value.present? + value.to_i + else + Gitlab::VisibilityLevel::PRIVATE + end + end + restricted_levels = params[:application_setting][:restricted_visibility_levels] if restricted_levels.nil? params[:application_setting][:restricted_visibility_levels] = [] diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index be632930895..671a0fe98cc 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -163,6 +163,8 @@ class ApplicationSetting < ActiveRecord::Base end def self.current + ensure_cache_setup + Rails.cache.fetch(CACHE_KEY) do ApplicationSetting.last end @@ -176,9 +178,16 @@ class ApplicationSetting < ActiveRecord::Base end def self.cached + ensure_cache_setup Rails.cache.fetch(CACHE_KEY) end + def self.ensure_cache_setup + # This is a workaround for a Rails bug that causes attribute methods not + # to be loaded when read from cache: https://github.com/rails/rails/issues/27348 + ApplicationSetting.define_attribute_methods + end + def self.defaults_ce { after_sign_up_text: nil, |