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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@errors = Setting.params_errors(casted_settings)
|
||||||
|
if @errors.empty?
|
||||||
casted_settings.each do |k, v|
|
casted_settings.each do |k, v|
|
||||||
Setting[k] = v
|
Setting[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
flash[:notice] = I18n.t('records_updated')
|
flash[:notice] = I18n.t('records_updated')
|
||||||
redirect_to [:admin, :settings]
|
redirect_to [:admin, :settings]
|
||||||
|
else
|
||||||
|
flash[:alert] = @errors.values.uniq.join(", ")
|
||||||
|
render "admin/settings/index"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show; end
|
def show; end
|
||||||
|
|
|
@ -6,4 +6,18 @@ class Setting < RailsSettings::CachedSettings
|
||||||
Rails.cache.delete_matched('settings:.*')
|
Rails.cache.delete_matched('settings:.*')
|
||||||
STDOUT << "#{Time.zone.now.utc} - Settings cache cleared\n"
|
STDOUT << "#{Time.zone.now.utc} - Settings cache cleared\n"
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- value = Setting.send(var)
|
- value = Setting.send(var)
|
||||||
%tr
|
%tr{class: (@errors && @errors.has_key?(var.to_s) && "danger")}
|
||||||
%td= t(var)
|
%td= t(var)
|
||||||
- if [TrueClass, FalseClass].include?(value.class)
|
- if [TrueClass, FalseClass].include?(value.class)
|
||||||
%td
|
%td
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue