diff options
author | Jakub Mendyk <jakubmendyk.szkola+git@gmail.com> | 2018-08-23 14:17:35 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-08-23 14:17:35 +0200 |
commit | 6cb3514d64ec24b164484f4eb84363b96746d5d6 (patch) | |
tree | 7de47dff8b187bb5921e7b7a331a9ef487a1cae5 /app/lib/settings | |
parent | d1c2c917d9685879d9c5cd203e416a8ef796f1e1 (diff) |
Add ability to change an instance default theme from the administration panel (#7092) (#8381)
* Add default_settings class method to ScopedSettings ScopedSettings was extended to use value of unscoped setting instead of only using defaults set in config/settings.yml for selected settings. This adds possibility for admins to set default values of users' settings, for example default theme (as requested in #7092). * Add ability to change an instance default theme Closes #7092
Diffstat (limited to 'app/lib/settings')
-rw-r--r-- | app/lib/settings/scoped_settings.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/lib/settings/scoped_settings.rb b/app/lib/settings/scoped_settings.rb index de4af3009..5ee30825d 100644 --- a/app/lib/settings/scoped_settings.rb +++ b/app/lib/settings/scoped_settings.rb @@ -2,6 +2,10 @@ module Settings class ScopedSettings + DEFAULTING_TO_UNSCOPED = %w( + theme + ).freeze + def initialize(object) @object = object end @@ -50,15 +54,22 @@ module Settings Rails.cache.fetch(Setting.cache_key(key, @object)) do db_val = thing_scoped.find_by(var: key.to_s) if db_val - default_value = Setting.default_settings[key] + default_value = ScopedSettings.default_settings[key] return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash) db_val.value else - Setting.default_settings[key] + ScopedSettings.default_settings[key] end end end + class << self + def default_settings + defaulting = DEFAULTING_TO_UNSCOPED.map { |k| [k, Setting[k]] }.to_h + Setting.default_settings.merge!(defaulting) + end + end + protected def thing_scoped |