From 65156bd8f6e3e633b2593601665207d2e5ece59c Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 3 Oct 2014 15:53:01 +1000 Subject: [PATCH] FIX: hide dangerous dev only site settings in production (port/force hostname/queue jobs) --- config/site_settings.yml | 12 +++++++++++- lib/site_settings/yaml_loader.rb | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/config/site_settings.yml b/config/site_settings.yml index b63f850287f..1a3991be6d5 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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 diff --git a/lib/site_settings/yaml_loader.rb b/lib/site_settings/yaml_loader.rb index f95ea3f8381..6ff21eff618 100644 --- a/lib/site_settings/yaml_loader.rb +++ b/lib/site_settings/yaml_loader.rb @@ -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 \ No newline at end of file +end