mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Story#107192666 - validation for settings that DS data allowed and Allow key data cannot be both true
This commit is contained in:
parent
e01599fb1a
commit
e31087bf60
3 changed files with 26 additions and 6 deletions
|
@ -7,12 +7,18 @@ class Admin::SettingsController < AdminController
|
|||
end
|
||||
|
||||
def create
|
||||
casted_settings.each do |k, v|
|
||||
Setting[k] = v
|
||||
end
|
||||
@errors = Setting.params_errors(casted_settings)
|
||||
if @errors.empty?
|
||||
casted_settings.each do |k, v|
|
||||
Setting[k] = v
|
||||
end
|
||||
|
||||
flash[:notice] = I18n.t('records_updated')
|
||||
redirect_to [:admin, :settings]
|
||||
flash[:notice] = I18n.t('records_updated')
|
||||
redirect_to [:admin, :settings]
|
||||
else
|
||||
flash[:alert] = @errors.values.uniq.join(", ")
|
||||
render "admin/settings/index"
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
|
|
@ -6,4 +6,18 @@ class Setting < RailsSettings::CachedSettings
|
|||
Rails.cache.delete_matched('settings:.*')
|
||||
STDOUT << "#{Time.zone.now.utc} - Settings cache cleared\n"
|
||||
end
|
||||
|
||||
|
||||
# cannot do instance validation because CachedSetting use save!
|
||||
def self.params_errors(params)
|
||||
errors = {}
|
||||
# DS data allowed and Allow key data cannot be both true
|
||||
if !!params["key_data_allowed"] && params["key_data_allowed"] == params["ds_data_allowed"]
|
||||
msg = "#{I18n.t(:key_data_allowed)} and #{I18n.t(:ds_data_with_key_allowed)} cannot be both true"
|
||||
errors["key_data_allowed"] = msg
|
||||
errors["ds_data_allowed"] = msg
|
||||
end
|
||||
|
||||
return errors
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- value = Setting.send(var)
|
||||
%tr
|
||||
%tr{class: (@errors && @errors.has_key?(var.to_s) && "danger")}
|
||||
%td= t(var)
|
||||
- if [TrueClass, FalseClass].include?(value.class)
|
||||
%td
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue