mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
- Add new setting for allowed admin contact ident types - Add validation for admin contact ident types on domain create/update - Add UI controls for managing allowed ident types - Add tests for new validation rules - Update domain model to respect new settings The changes allow configuring which identification types (private person, organization, birthday) are allowed for administrative contacts. This is enforced when creating new domains or adding new admin contacts.
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
module Admin
|
|
class SettingsController < BaseController
|
|
load_and_authorize_resource
|
|
|
|
def index
|
|
@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
|
|
update = SettingEntry.update(casted_settings.keys, casted_settings.values)
|
|
if update
|
|
flash[:notice] = t('.saved')
|
|
redirect_to %i[admin settings]
|
|
else
|
|
flash[:alert] = update.errors.values.uniq.join(', ')
|
|
render 'admin/settings/index'
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def casted_settings
|
|
settings = {}
|
|
|
|
params[:settings].each do |k, v|
|
|
setting = SettingEntry.find(k)
|
|
value = if setting.format == 'array'
|
|
processed_hash = available_options.each_with_object({}) do |option, hash|
|
|
hash[option] = (v[option] == "true")
|
|
end
|
|
processed_hash.to_json
|
|
else
|
|
v
|
|
end
|
|
settings[k] = { value: value }
|
|
end
|
|
|
|
settings
|
|
end
|
|
|
|
def available_options
|
|
%w[birthday priv org]
|
|
end
|
|
end
|
|
end
|