Merge pull request #1659 from internetee/1629-change-settings-storage-mechanism

Replace rails-settings-cached with custom approach
This commit is contained in:
Timo Võhmar 2020-08-26 12:56:33 +03:00 committed by GitHub
commit 8da95a5e43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1050 additions and 258 deletions

View file

@ -3,21 +3,23 @@ module Admin
load_and_authorize_resource
def index
@settings = Setting.unscoped
@settings = SettingEntry.unscoped
@validation_settings = SettingEntry.with_group('domain_validation')
@expiration_settings = SettingEntry.with_group('domain_expiration')
@other_settings = SettingEntry.with_group('other')
.where.not(code: 'default_language')
@billing_settings = SettingEntry.with_group('billing')
@contacts_settings = SettingEntry.with_group('contacts')
end
def create
@errors = Setting.params_errors(casted_settings)
if @errors.empty?
casted_settings.each do |k, v|
Setting[k] = v
end
update = SettingEntry.update(casted_settings.keys, casted_settings.values)
if update
flash[:notice] = t('.saved')
redirect_to [:admin, :settings]
redirect_to %i[admin settings]
else
flash[:alert] = @errors.values.uniq.join(", ")
render "admin/settings/index"
flash[:alert] = update.errors.values.uniq.join(', ')
render 'admin/settings/index'
end
end
@ -27,10 +29,7 @@ module Admin
settings = {}
params[:settings].each do |k, v|
settings[k] = v
settings[k] = v.to_i if Setting.integer_settings.include?(k.to_sym)
settings[k] = v.to_f if Setting.float_settings.include?(k.to_sym)
settings[k] = (v == 'true' ? true : false) if Setting.boolean_settings.include?(k.to_sym)
settings[k] = { value: v }
end
settings