FIX: hide dangerous dev only site settings in production

(port/force hostname/queue jobs)
This commit is contained in:
Sam 2014-10-03 15:53:01 +10:00
parent 81e91f3fd7
commit 65156bd8f6
2 changed files with 23 additions and 6 deletions

View File

@ -589,12 +589,22 @@ rate_limits:
max_replies_in_first_day: 10
developer:
force_hostname: ''
force_hostname:
hidden:
development: false
default: true
default: ''
port:
hidden:
development: false
default: true
default:
development: 3000
default: ''
queue_jobs:
hidden:
development: false
default: true
default:
test: false
default: true

View File

@ -6,17 +6,24 @@ class SiteSettings::YamlLoader
@file = file
end
def env_val(value)
if value.is_a?(Hash)
value.has_key?(Rails.env) ? value[Rails.env] : value['default']
else
value
end
end
def load
yaml = YAML.load_file(@file)
yaml.keys.each do |category|
yaml[category].each do |setting_name, hash|
if hash.is_a?(Hash)
# Get default value for the site setting:
value = hash.delete('default')
value = env_val(hash.delete('default'))
# If there's a different default value for each environment, choose the right one:
if value.is_a?(Hash)
value = value.has_key?(Rails.env) ? value[Rails.env] : value['default']
if hash.key?('hidden')
hash['hidden'] = env_val(hash.delete('hidden'))
end
yield category, setting_name, value, hash.symbolize_keys!
@ -27,4 +34,4 @@ class SiteSettings::YamlLoader
end
end
end
end
end