mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Merge pull request #1659 from internetee/1629-change-settings-storage-mechanism
Replace rails-settings-cached with custom approach
This commit is contained in:
commit
8da95a5e43
23 changed files with 1050 additions and 258 deletions
|
@ -21,7 +21,6 @@ before_script:
|
|||
- "echo \"ca_key_password: 'password'\" >> config/application.yml"
|
||||
- "cp config/database_travis.yml config/database.yml"
|
||||
- "bundle exec rake db:setup:all"
|
||||
- "bundle exec rake data:migrate"
|
||||
- "curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter"
|
||||
- "chmod +x ./cc-test-reporter"
|
||||
- "./cc-test-reporter before-build"
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -21,7 +21,6 @@ gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and
|
|||
|
||||
# 0.7.3 is the latest for Rails 4.2, however, it is absent on Rubygems server
|
||||
# https://github.com/huacnlee/rails-settings-cached/issues/165
|
||||
gem 'rails-settings-cached', '0.7.2'
|
||||
gem 'nokogiri'
|
||||
|
||||
# style
|
||||
|
|
|
@ -357,8 +357,6 @@ GEM
|
|||
nokogiri (>= 1.6)
|
||||
rails-html-sanitizer (1.3.0)
|
||||
loofah (~> 2.3)
|
||||
rails-settings-cached (0.7.2)
|
||||
rails (>= 4.2.0)
|
||||
railties (6.0.3.2)
|
||||
actionpack (= 6.0.3.2)
|
||||
activesupport (= 6.0.3.2)
|
||||
|
@ -538,7 +536,6 @@ DEPENDENCIES
|
|||
que-web
|
||||
railroady (= 1.3.0)
|
||||
rails (~> 6.0)
|
||||
rails-settings-cached (= 0.7.2)
|
||||
ransack (~> 2.3)
|
||||
rest-client
|
||||
sass-rails
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,7 +8,7 @@ module Concerns
|
|||
end
|
||||
|
||||
def legaldoc_not_mandatory?
|
||||
setting = Setting.find_by(var: 'legal_document_is_mandatory')&.value
|
||||
setting = Setting.legal_document_is_mandatory
|
||||
legaldoc_optout || !setting
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,74 +1,5 @@
|
|||
class Setting < RailsSettings::Base
|
||||
include Versions # version/setting_version.rb
|
||||
source Rails.root.join('config', 'app.yml')
|
||||
# frozen_string_literal: true
|
||||
|
||||
# When config/app.yml has changed, you need change this prefix to v2, v3 ... to expires caches
|
||||
cache_prefix { 'v2' }
|
||||
|
||||
def self.reload_settings!
|
||||
STDOUT << "#{Time.zone.now.utc} - Clearing settings cache\n"
|
||||
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
|
||||
|
||||
def self.integer_settings
|
||||
%i[
|
||||
admin_contacts_min_count
|
||||
admin_contacts_max_count
|
||||
tech_contacts_min_count
|
||||
tech_contacts_max_count
|
||||
orphans_contacts_in_months
|
||||
ds_digest_type
|
||||
dnskeys_min_count
|
||||
dnskeys_max_count
|
||||
ns_min_count
|
||||
ns_max_count
|
||||
transfer_wait_time
|
||||
invoice_number_min
|
||||
invoice_number_max
|
||||
days_to_keep_invoices_active
|
||||
days_to_keep_overdue_invoices_active
|
||||
days_to_renew_domain_before_expire
|
||||
expire_warning_period
|
||||
redemption_grace_period
|
||||
expire_pending_confirmation
|
||||
dispute_period_in_months
|
||||
]
|
||||
end
|
||||
|
||||
def self.float_settings
|
||||
%i[
|
||||
registry_vat_prc
|
||||
minimum_deposit
|
||||
]
|
||||
end
|
||||
|
||||
def self.boolean_settings
|
||||
%i[
|
||||
ds_data_allowed
|
||||
key_data_allowed
|
||||
client_side_status_editing_enabled
|
||||
registrar_ip_whitelist_enabled
|
||||
api_ip_whitelist_enabled
|
||||
request_confrimation_on_registrant_change_enabled
|
||||
request_confirmation_on_domain_deletion_enabled
|
||||
nameserver_required
|
||||
address_processing
|
||||
legal_document_is_mandatory
|
||||
]
|
||||
end
|
||||
class Setting < SettingEntry
|
||||
# Bridge Setting calls to SettingEntry, so we don't have to drop legacy settings yet
|
||||
end
|
||||
|
|
92
app/models/setting_entry.rb
Normal file
92
app/models/setting_entry.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
class SettingEntry < ApplicationRecord
|
||||
include Versions
|
||||
validates :code, presence: true, uniqueness: true, format: { with: /\A([a-z])[a-z|_]+[a-z]\z/ }
|
||||
validates :format, presence: true
|
||||
validates :group, presence: true
|
||||
validate :validate_value_format
|
||||
validate :validate_code_is_not_using_reserved_name
|
||||
before_update :replace_boolean_nil_with_false
|
||||
|
||||
VALUE_FORMATS = {
|
||||
string: :string_format,
|
||||
integer: :integer_format,
|
||||
float: :float_format,
|
||||
boolean: :boolean_format,
|
||||
hash: :hash_format,
|
||||
array: :array_format,
|
||||
}.with_indifferent_access.freeze
|
||||
|
||||
def retrieve
|
||||
method = VALUE_FORMATS[format]
|
||||
return false if self.format == 'boolean' && value.blank?
|
||||
return if value.blank?
|
||||
|
||||
send(method)
|
||||
end
|
||||
|
||||
def self.with_group(group_name)
|
||||
SettingEntry.order(id: :asc).where(group: group_name)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/MethodMissingSuper
|
||||
# rubocop:disable Style/MissingRespondToMissing
|
||||
def self.method_missing(method, *args)
|
||||
super(method, *args)
|
||||
rescue NoMethodError
|
||||
get_or_set(method.to_s, args[0])
|
||||
end
|
||||
# rubocop:enable Style/MissingRespondToMissing
|
||||
# rubocop:enable Style/MethodMissingSuper
|
||||
|
||||
def self.get_or_set(method_name, arg)
|
||||
if method_name[-1] == '='
|
||||
SettingEntry.find_by!(code: method_name.sub('=', '')).update(value: arg.to_s)
|
||||
else
|
||||
stg = SettingEntry.find_by(code: method_name)
|
||||
stg ? stg.retrieve : nil
|
||||
end
|
||||
end
|
||||
|
||||
# Hooks
|
||||
def replace_boolean_nil_with_false
|
||||
return unless self.format == 'boolean'
|
||||
return if value == 'true'
|
||||
|
||||
self.value = 'false'
|
||||
end
|
||||
|
||||
def validate_code_is_not_using_reserved_name
|
||||
disallowed = []
|
||||
ActiveRecord::Base.instance_methods.sort.each { |m| disallowed << m.to_s }
|
||||
errors.add(:code, :invalid) if disallowed.include? code
|
||||
end
|
||||
|
||||
def validate_value_format
|
||||
formats = VALUE_FORMATS.with_indifferent_access
|
||||
errors.add(:format, :invalid) unless formats.keys.any? format
|
||||
end
|
||||
|
||||
def string_format
|
||||
value
|
||||
end
|
||||
|
||||
def integer_format
|
||||
value.to_i
|
||||
end
|
||||
|
||||
def float_format
|
||||
value.to_f
|
||||
end
|
||||
|
||||
def boolean_format
|
||||
value == 'true'
|
||||
end
|
||||
|
||||
def hash_format
|
||||
JSON.parse(value)
|
||||
end
|
||||
|
||||
def array_format
|
||||
JSON.parse(value).to_a
|
||||
end
|
||||
end
|
4
app/models/version/setting_entry_version.rb
Normal file
4
app/models/version/setting_entry_version.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class SettingEntryVersion < PaperTrail::Version
|
||||
self.table_name = :log_setting_entries
|
||||
self.sequence_name = :log_setting_entries
|
||||
end
|
|
@ -1,9 +1,8 @@
|
|||
- value = Setting.send(var)
|
||||
%tr{class: (@errors && @errors.has_key?(var.to_s) && "danger")}
|
||||
%td.col-md-6= var.to_s.humanize
|
||||
- if [TrueClass, FalseClass].include?(value.class)
|
||||
%tr{class: (@errors && @errors.has_key?(setting.code) && "danger")}
|
||||
%td.col-md-6= setting.code.humanize
|
||||
- if [TrueClass, FalseClass].include?(setting.retrieve.class)
|
||||
%td.col-md-6
|
||||
= hidden_field_tag("[settings][#{var}]", '', id: nil)
|
||||
= check_box_tag("[settings][#{var}]", true, value)
|
||||
= hidden_field_tag("[settings][#{setting.id}]", '', id: nil)
|
||||
= check_box_tag("[settings][#{setting.id}]", true, setting.retrieve)
|
||||
- else
|
||||
%td.col-md-6= text_field_tag("[settings][#{var}]", value, class: 'form-control')
|
||||
%td.col-md-6= text_field_tag("[settings][#{setting.id}]", setting.value, class: 'form-control')
|
||||
|
|
|
@ -9,20 +9,8 @@
|
|||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%tbody
|
||||
= render 'setting_row', var: :admin_contacts_min_count
|
||||
= render 'setting_row', var: :admin_contacts_max_count
|
||||
= render 'setting_row', var: :tech_contacts_min_count
|
||||
= render 'setting_row', var: :tech_contacts_max_count
|
||||
= render 'setting_row', var: :orphans_contacts_in_months
|
||||
= render 'setting_row', var: :ds_data_allowed
|
||||
= render 'setting_row', var: :key_data_allowed
|
||||
= render 'setting_row', var: :dnskeys_min_count
|
||||
= render 'setting_row', var: :dnskeys_max_count
|
||||
= render 'setting_row', var: :nameserver_required
|
||||
= render 'setting_row', var: :ns_min_count
|
||||
= render 'setting_row', var: :ns_max_count
|
||||
= render 'setting_row', var: :expire_pending_confirmation
|
||||
= render 'setting_row', var: :legal_document_is_mandatory
|
||||
- @validation_settings.each do |setting|
|
||||
= render 'setting_row', setting: setting
|
||||
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
|
@ -30,10 +18,8 @@
|
|||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%tbody
|
||||
= render 'setting_row', var: :days_to_renew_domain_before_expire
|
||||
= render 'setting_row', var: :expire_warning_period
|
||||
= render 'setting_row', var: :redemption_grace_period
|
||||
= render 'setting_row', var: :expiration_reminder_mail
|
||||
- @expiration_settings.each do |setting|
|
||||
= render 'setting_row', setting: setting
|
||||
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
|
@ -41,19 +27,12 @@
|
|||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%tbody
|
||||
= render 'setting_row', var: :transfer_wait_time
|
||||
= render 'setting_row', var: :ds_digest_type
|
||||
= render 'setting_row', var: :client_side_status_editing_enabled
|
||||
= render 'setting_row', var: :api_ip_whitelist_enabled
|
||||
= render 'setting_row', var: :registrar_ip_whitelist_enabled
|
||||
= render 'setting_row', var: :request_confrimation_on_registrant_change_enabled
|
||||
= render 'setting_row', var: :request_confirmation_on_domain_deletion_enabled
|
||||
= render 'setting_row', var: :address_processing
|
||||
= render 'setting_row', var: :dispute_period_in_months
|
||||
- @other_settings.each do |setting|
|
||||
= render 'setting_row', setting: setting
|
||||
%tr
|
||||
%td.col-md-6= label_tag :default_language
|
||||
%td.col-md-6
|
||||
= select_tag '[settings][default_language]',
|
||||
= select_tag "[settings][#{SettingEntry.find_by(code: 'default_language').id || 1}]",
|
||||
options_for_select(available_languages, Setting.default_language),
|
||||
class: 'form-control'
|
||||
|
||||
|
@ -63,25 +42,8 @@
|
|||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%tbody
|
||||
= render 'setting_row', var: :invoice_number_min
|
||||
= render 'setting_row', var: :invoice_number_max
|
||||
= render 'setting_row', var: :directo_monthly_number_min
|
||||
= render 'setting_row', var: :directo_monthly_number_max
|
||||
= render 'setting_row', var: :directo_monthly_number_last
|
||||
= render 'setting_row', var: :days_to_keep_invoices_active
|
||||
= render 'setting_row', var: :days_to_keep_overdue_invoices_active
|
||||
= render 'setting_row', var: :minimum_deposit
|
||||
= render 'setting_row', var: :directo_receipt_payment_term
|
||||
= render 'setting_row', var: :directo_receipt_product_name
|
||||
= render 'setting_row', var: :directo_sales_agent
|
||||
= render 'setting_row', var: :registry_billing_email
|
||||
= render 'setting_row', var: :registry_invoice_contact
|
||||
= render 'setting_row', var: :registry_vat_no
|
||||
= render 'setting_row', var: :registry_vat_prc
|
||||
= render 'setting_row', var: :registry_bank
|
||||
= render 'setting_row', var: :registry_bank_code
|
||||
= render 'setting_row', var: :registry_iban
|
||||
= render 'setting_row', var: :registry_swift
|
||||
- @billing_settings.each do |setting|
|
||||
= render 'setting_row', setting: setting
|
||||
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
|
@ -89,17 +51,8 @@
|
|||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%tbody
|
||||
= render 'setting_row', var: :registry_juridical_name
|
||||
= render 'setting_row', var: :registry_reg_no
|
||||
= render 'setting_row', var: :registry_email
|
||||
= render 'setting_row', var: :registry_phone
|
||||
= render 'setting_row', var: :registry_url
|
||||
= render 'setting_row', var: :registry_street
|
||||
= render 'setting_row', var: :registry_city
|
||||
= render 'setting_row', var: :registry_state
|
||||
= render 'setting_row', var: :registry_zip
|
||||
= render 'setting_row', var: :registry_country_code
|
||||
= render 'setting_row', var: :registry_whois_disclaimer
|
||||
- @contacts_settings.each do |setting|
|
||||
= render 'setting_row', setting: setting
|
||||
|
||||
.row
|
||||
.col-md-12.text-right
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
# config/app.yml for rails-settings-cached
|
||||
defaults: &defaults
|
||||
admin_contacts_min_count: 1
|
||||
admin_contacts_max_count: 10
|
||||
tech_contacts_min_count: 1
|
||||
tech_contacts_max_count: 10
|
||||
orphans_contacts_in_months: 6
|
||||
expire_pending_confirmation: 48
|
||||
legal_document_is_mandatory: true
|
||||
|
||||
ds_digest_type: 2
|
||||
ds_data_allowed: false
|
||||
key_data_allowed: true
|
||||
|
||||
dnskeys_min_count: 0
|
||||
dnskeys_max_count: 9
|
||||
ns_min_count: 2
|
||||
ns_max_count: 11
|
||||
|
||||
transfer_wait_time: 0
|
||||
request_confrimation_on_registrant_change_enabled: true
|
||||
request_confirmation_on_domain_deletion_enabled: true
|
||||
address_processing: true
|
||||
default_language: en
|
||||
nameserver_required: false
|
||||
|
||||
client_side_status_editing_enabled: false
|
||||
|
||||
invoice_number_min: 131050
|
||||
invoice_number_max: 149999
|
||||
directo_monthly_number_min: 309901
|
||||
directo_monthly_number_max: 309999
|
||||
directo_monthly_number_last: 309901
|
||||
days_to_keep_invoices_active: 30
|
||||
minimum_deposit: 0.0
|
||||
directo_receipt_payment_term: R
|
||||
directo_receipt_product_name: ETTEM06
|
||||
directo_sales_agent: JAANA
|
||||
|
||||
days_to_renew_domain_before_expire: 90
|
||||
expire_warning_period: 15
|
||||
redemption_grace_period: 30
|
||||
expiration_reminder_mail: 2
|
||||
|
||||
registrar_ip_whitelist_enabled: false
|
||||
api_ip_whitelist_enabled: false
|
||||
|
||||
dispute_period_in_months: 36
|
||||
|
||||
registry_juridical_name: "Eesti Interneti SA"
|
||||
registry_reg_no: "90010019"
|
||||
registry_email: "info@internet.ee"
|
||||
registry_billing_email: "info@internet.ee"
|
||||
registry_phone: "+372 727 1000"
|
||||
registry_country_code: "EE"
|
||||
registry_state: "Harjumaa"
|
||||
registry_street: "Paldiski mnt 80"
|
||||
registry_city: "Tallinn"
|
||||
registry_zip: "10617"
|
||||
registry_vat_no: "EE101286464"
|
||||
registry_url: "www.internet.ee"
|
||||
registry_vat_prc: 0.2
|
||||
registry_iban: "EE557700771000598731"
|
||||
registry_bank: "LHV Pank"
|
||||
registry_bank_code: "689"
|
||||
registry_swift: "LHVBEE22"
|
||||
registry_invoice_contact: "Martti Õigus"
|
||||
registry_whois_disclaimer: "Search results may not be used for commercial, advertising, recompilation, repackaging, redistribution, reuse, obscuring or other similar activities."
|
||||
|
||||
development:
|
||||
<<: *defaults
|
||||
|
||||
test:
|
||||
<<: *defaults
|
||||
|
||||
production:
|
||||
<<: *defaults
|
|
@ -1,9 +1,11 @@
|
|||
class AddLegalDocumentMandatorySetting < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
Setting.legal_document_is_mandatory = true
|
||||
Setting.create(code: 'legal_document_is_mandatory',
|
||||
value: 'true', format: 'boolean',
|
||||
group: 'domain_validation')
|
||||
end
|
||||
|
||||
def down
|
||||
Setting.find_by(var: 'legal_document_is_mandatory').delete
|
||||
Setting.find_by(code: 'legal_document_is_mandatory').destroy
|
||||
end
|
||||
end
|
||||
|
|
87
db/data/20200812093540_copy_legacy_settings_to_new_model.rb
Normal file
87
db/data/20200812093540_copy_legacy_settings_to_new_model.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
class CopyLegacySettingsToNewModel < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
validation_group =
|
||||
%w[admin_contacts_min_count admin_contacts_max_count tech_contacts_min_count ns_min_count
|
||||
tech_contacts_max_count orphans_contacts_in_months key_data_allowed dnskeys_min_count
|
||||
dnskeys_max_count nameserver_required expire_pending_confirmation ds_data_allowed
|
||||
legal_document_is_mandatory ns_max_count].freeze
|
||||
|
||||
expiration_group =
|
||||
%w[days_to_renew_domain_before_expire expire_warning_period redemption_grace_period
|
||||
expiration_reminder_mail].freeze
|
||||
|
||||
billing_group =
|
||||
%w[invoice_number_min invoice_number_max directo_monthly_number_min
|
||||
directo_monthly_number_last days_to_keep_invoices_active directo_monthly_number_max
|
||||
days_to_keep_overdue_invoices_active minimum_deposit directo_receipt_payment_term
|
||||
directo_receipt_product_name directo_sales_agent registry_billing_email
|
||||
registry_invoice_contact registry_vat_no registry_vat_prc registry_bank
|
||||
registry_iban registry_swift directo_monthly_number_max registry_bank_code].freeze
|
||||
|
||||
contacts_group =
|
||||
%w[registry_juridical_name registry_reg_no registry_email registry_phone registry_url
|
||||
registry_street registry_city registry_state registry_zip registry_country_code
|
||||
registry_whois_disclaimer].freeze
|
||||
|
||||
integer_vars =
|
||||
%w[admin_contacts_min_count admin_contacts_max_count tech_contacts_min_count
|
||||
tech_contacts_max_count orphans_contacts_in_months ds_digest_type dnskeys_min_count
|
||||
dnskeys_max_count ns_min_count ns_max_count transfer_wait_time invoice_number_min
|
||||
invoice_number_max days_to_keep_invoices_active days_to_keep_overdue_invoices_active
|
||||
days_to_renew_domain_before_expire expire_warning_period redemption_grace_period
|
||||
expire_pending_confirmation dispute_period_in_months].freeze
|
||||
|
||||
float_vars = %w[registry_vat_prc minimum_deposit].freeze
|
||||
|
||||
boolean_vars =
|
||||
%w[
|
||||
ds_data_allowed
|
||||
key_data_allowed
|
||||
client_side_status_editing_enabled
|
||||
registrar_ip_whitelist_enabled
|
||||
api_ip_whitelist_enabled
|
||||
request_confrimation_on_registrant_change_enabled
|
||||
request_confirmation_on_domain_deletion_enabled
|
||||
nameserver_required
|
||||
address_processing
|
||||
legal_document_is_mandatory
|
||||
].freeze
|
||||
|
||||
sql = 'SELECT var, value, created_at, updated_at, creator_str, updator_str FROM' \
|
||||
' settings ORDER BY settings.id ASC'
|
||||
old_settings = ActiveRecord::Base.connection.execute(sql)
|
||||
|
||||
old_settings.each do |origin|
|
||||
next if origin['var'] == 'days_to_keep_business_registry_cache'
|
||||
entry = SettingEntry.find_or_initialize_by(code: origin['var'])
|
||||
entry[:format] = 'string'
|
||||
entry[:format] = 'boolean' if boolean_vars.include? entry.code
|
||||
entry[:format] = 'float' if float_vars.include? entry.code
|
||||
entry[:format] = 'integer' if integer_vars.include? entry.code
|
||||
|
||||
entry[:group] = 'other'
|
||||
entry[:group] = 'domain_validation' if validation_group.include? entry.code
|
||||
entry[:group] = 'domain_expiration' if expiration_group.include? entry.code
|
||||
entry[:group] = 'billing' if billing_group.include? entry.code
|
||||
entry[:group] = 'contacts' if contacts_group.include? entry.code
|
||||
|
||||
%w[value created_at updated_at creator_str updator_str].each do |field|
|
||||
entry[field] = origin[field]
|
||||
next if field != 'value'
|
||||
|
||||
entry.value = origin[field].gsub('--- ', '').strip.gsub("'", '')
|
||||
end
|
||||
|
||||
if entry.save
|
||||
logger.info "Legacy setting '#{entry.code}' successfully migrated to SettingEntry"
|
||||
else
|
||||
logger.error "!!! Failed to migrate setting '#{entry.code}': " \
|
||||
"#{entry.errors.full_messages.join(', ')}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
16
db/migrate/20200811074839_create_setting_entries.rb
Normal file
16
db/migrate/20200811074839_create_setting_entries.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class CreateSettingEntries < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :setting_entries do |t|
|
||||
t.string :code, null: false, index: { unique: true }
|
||||
t.string :value
|
||||
t.string :group, null: false
|
||||
t.string :format, null: false
|
||||
|
||||
# Versioning related
|
||||
t.string :creator_str
|
||||
t.string :updator_str
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeSettingEntryValueToAllowNil < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_column :setting_entries, :value, :string, null: true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
class CreateVersionsForSettingEntries < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
create_table :log_setting_entries, force: :cascade do |t|
|
||||
t.string :item_type, null: false
|
||||
t.integer :item_id, null: false
|
||||
t.string :event, null: false
|
||||
t.string :whodunnit
|
||||
t.json :object
|
||||
t.json :object_changes
|
||||
t.datetime :created_at
|
||||
t.string :session
|
||||
t.json :children
|
||||
t.string :uuid
|
||||
end
|
||||
|
||||
add_index 'log_setting_entries', ['item_type', 'item_id'], name: 'index_log_setting_entries_on_item_type_and_item_id', using: :btree
|
||||
add_index 'log_setting_entries', ['whodunnit'], name: 'index_log_setting_entries_on_whodunnit', using: :btree
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :log_setting_entries, name: 'index_log_setting_entries_on_item_type_and_item_id'
|
||||
remove_index :log_setting_entries, name: 'index_log_setting_entries_on_whodunnit'
|
||||
|
||||
drop_table :log_setting_entries
|
||||
end
|
||||
end
|
65
db/seeds.rb
65
db/seeds.rb
|
@ -2,6 +2,66 @@
|
|||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
ActiveRecord::Base.transaction do
|
||||
# Create dynamic Setting objects
|
||||
SettingEntry.create(code: 'registry_vat_prc', value: '0.2', format: 'float', group: 'billing')
|
||||
SettingEntry.create(code: 'directo_sales_agent', value: 'HELEN', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'admin_contacts_min_count', value: '1', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'admin_contacts_max_count', value: '10', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'tech_contacts_min_count', value: '1', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'tech_contacts_max_count', value: '10', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'orphans_contacts_in_months', value: '6', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'ds_data_allowed', value: 'false', format: 'boolean', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'key_data_allowed', value: 'true', format: 'boolean', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'dnskeys_min_count', value: '0', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'dnskeys_max_count', value: '9', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'nameserver_required', value: 'false', format: 'boolean', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'ns_min_count', value: '2', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'ns_max_count', value: '11', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'expire_pending_confirmation', value: '48', format: 'integer', group: 'domain_validation')
|
||||
SettingEntry.create(code: 'days_to_renew_domain_before_expire', value: '90', format: 'integer', group: 'domain_expiration')
|
||||
SettingEntry.create(code: 'expire_warning_period', value: '15', format: 'integer', group: 'domain_expiration')
|
||||
SettingEntry.create(code: 'redemption_grace_period', value: '30', format: 'integer', group: 'domain_expiration')
|
||||
SettingEntry.create(code: 'transfer_wait_time', value: '0', format: 'integer', group: 'other')
|
||||
SettingEntry.create(code: 'ds_digest_type', value: '2', format: 'integer', group: 'other')
|
||||
SettingEntry.create(code: 'client_side_status_editing_enabled', value: 'false', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'api_ip_whitelist_enabled', value: 'false', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'registrar_ip_whitelist_enabled', value: 'false', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'request_confrimation_on_registrant_change_enabled', value: 'true', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'request_confirmation_on_domain_deletion_enabled', value: 'true', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'default_language', value: 'en', format: 'string', group: 'other')
|
||||
SettingEntry.create(code: 'invoice_number_min', value: '131050', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'invoice_number_max', value: '149999', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'days_to_keep_invoices_active', value: '30', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'days_to_keep_overdue_invoices_active', value: '0', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'minimum_deposit', value: '0.0', format: 'float', group: 'billing')
|
||||
SettingEntry.create(code: 'directo_receipt_payment_term', value: 'R', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'directo_receipt_product_name', value: 'ETTEM06', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_billing_email', value: 'info@internet.ee', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_invoice_contact', value: 'Martti Õigus', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_vat_no', value: 'EE101286464', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_bank', value: 'LHV Pank', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_iban', value: 'EE557700771000598731', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_swift', value: 'LHVBEE22', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_email', value: 'info@internet.ee', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_phone', value: '+372 727 1000', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_url', value: 'www.internet.ee', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_street', value: 'Paldiski mnt 80', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_city', value: 'Tallinn', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_state', value: 'Harjumaa', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_country_code', value: 'EE', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'expiration_reminder_mail', value: '2', format: 'integer', group: 'domain_expiration')
|
||||
SettingEntry.create(code: 'directo_monthly_number_min', value: '309901', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'directo_monthly_number_max', value: '309999', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_bank_code', value: '689', format: 'string', group: 'billing')
|
||||
SettingEntry.create(code: 'registry_reg_no', value: '90010019', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_zip', value: '10617', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'registry_juridical_name', value: 'Eesti Interneti SA', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'address_processing', value: 'true', format: 'boolean', group: 'other')
|
||||
SettingEntry.create(code: 'directo_monthly_number_last', value: '309901', format: 'integer', group: 'billing')
|
||||
SettingEntry.create(code: 'dispute_period_in_months', value: '36', format: 'integer', group: 'other')
|
||||
SettingEntry.create(code: 'registry_whois_disclaimer', value: 'Search results may not be used for commercial, advertising, recompilation, repackaging, redistribution, reuse, obscuring or other similar activities.', format: 'string', group: 'contacts')
|
||||
SettingEntry.create(code: 'legal_document_is_mandatory', value: 'true', format: 'boolean', group: 'domain_validation')
|
||||
|
||||
AdminUser.where(username: 'admin').first_or_create!(
|
||||
username: 'admin',
|
||||
email: 'admin@domain.tld',
|
||||
|
@ -11,10 +71,7 @@ ActiveRecord::Base.transaction do
|
|||
country_code: 'EE',
|
||||
roles: ['admin']
|
||||
)
|
||||
# Required for creating registrar
|
||||
Setting.where(var: 'registry_vat_prc').first_or_create(
|
||||
value: '0.2'
|
||||
)
|
||||
|
||||
# First registrar
|
||||
Registrar.where(name: 'Registrar First').first_or_create!(
|
||||
name: 'Registrar First',
|
||||
|
|
138
db/structure.sql
138
db/structure.sql
|
@ -31,6 +31,14 @@ COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
|||
|
||||
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';
|
||||
|
||||
|
||||
--
|
||||
-- Name: citext; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
@ -1812,6 +1820,44 @@ CREATE SEQUENCE public.log_reserved_domains_id_seq
|
|||
ALTER SEQUENCE public.log_reserved_domains_id_seq OWNED BY public.log_reserved_domains.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_setting_entries; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE public.log_setting_entries (
|
||||
id bigint NOT NULL,
|
||||
item_type character varying NOT NULL,
|
||||
item_id integer NOT NULL,
|
||||
event character varying NOT NULL,
|
||||
whodunnit character varying,
|
||||
object json,
|
||||
object_changes json,
|
||||
created_at timestamp without time zone,
|
||||
session character varying,
|
||||
children json,
|
||||
uuid character varying
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_setting_entries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.log_setting_entries_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_setting_entries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.log_setting_entries_id_seq OWNED BY public.log_setting_entries.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_settings; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -2254,6 +2300,42 @@ CREATE TABLE public.schema_migrations (
|
|||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: setting_entries; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE public.setting_entries (
|
||||
id bigint NOT NULL,
|
||||
code character varying NOT NULL,
|
||||
value character varying,
|
||||
"group" character varying NOT NULL,
|
||||
format character varying NOT NULL,
|
||||
creator_str character varying,
|
||||
updator_str character varying,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: setting_entries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.setting_entries_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: setting_entries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.setting_entries_id_seq OWNED BY public.setting_entries.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: settings; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -2778,6 +2860,13 @@ ALTER TABLE ONLY public.log_registrars ALTER COLUMN id SET DEFAULT nextval('publ
|
|||
ALTER TABLE ONLY public.log_reserved_domains ALTER COLUMN id SET DEFAULT nextval('public.log_reserved_domains_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.log_setting_entries ALTER COLUMN id SET DEFAULT nextval('public.log_setting_entries_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2855,6 +2944,13 @@ ALTER TABLE ONLY public.registrars ALTER COLUMN id SET DEFAULT nextval('public.r
|
|||
ALTER TABLE ONLY public.reserved_domains ALTER COLUMN id SET DEFAULT nextval('public.reserved_domains_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.setting_entries ALTER COLUMN id SET DEFAULT nextval('public.setting_entries_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -3233,6 +3329,14 @@ ALTER TABLE ONLY public.log_reserved_domains
|
|||
ADD CONSTRAINT log_reserved_domains_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_setting_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.log_setting_entries
|
||||
ADD CONSTRAINT log_setting_entries_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -3321,6 +3425,14 @@ ALTER TABLE ONLY public.reserved_domains
|
|||
ADD CONSTRAINT reserved_domains_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: setting_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.setting_entries
|
||||
ADD CONSTRAINT setting_entries_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -3923,6 +4035,20 @@ CREATE INDEX index_log_reserved_domains_on_item_type_and_item_id ON public.log_r
|
|||
CREATE INDEX index_log_reserved_domains_on_whodunnit ON public.log_reserved_domains USING btree (whodunnit);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_log_setting_entries_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_log_setting_entries_on_item_type_and_item_id ON public.log_setting_entries USING btree (item_type, item_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_log_setting_entries_on_whodunnit; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_log_setting_entries_on_whodunnit ON public.log_setting_entries USING btree (whodunnit);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_log_settings_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -3993,6 +4119,13 @@ CREATE INDEX index_registrant_verifications_on_created_at ON public.registrant_v
|
|||
CREATE INDEX index_registrant_verifications_on_domain_id ON public.registrant_verifications USING btree (domain_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_setting_entries_on_code; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_setting_entries_on_code ON public.setting_entries USING btree (code);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_settings_on_thing_type_and_thing_id_and_var; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
@ -4712,6 +4845,9 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200610090110'),
|
||||
('20200630081231'),
|
||||
('20200714115338'),
|
||||
('20200807110611');
|
||||
('20200807110611'),
|
||||
('20200811074839'),
|
||||
('20200812090409'),
|
||||
('20200812125810');
|
||||
|
||||
|
||||
|
|
464
test/fixtures/setting_entries.yml
vendored
Normal file
464
test/fixtures/setting_entries.yml
vendored
Normal file
|
@ -0,0 +1,464 @@
|
|||
registry_vat_prc:
|
||||
code: registry_vat_prc
|
||||
value: '0.2'
|
||||
group: billing
|
||||
format: float
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_sales_agent:
|
||||
code: directo_sales_agent
|
||||
value: HELEN
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
admin_contacts_min_count:
|
||||
code: admin_contacts_min_count
|
||||
value: '1'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
admin_contacts_max_count:
|
||||
code: admin_contacts_max_count
|
||||
value: '10'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
tech_contacts_min_count:
|
||||
code: tech_contacts_min_count
|
||||
value: '1'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
tech_contacts_max_count:
|
||||
code: tech_contacts_max_count
|
||||
value: '10'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
orphans_contacts_in_months:
|
||||
code: orphans_contacts_in_months
|
||||
value: '6'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
ds_data_allowed:
|
||||
code: ds_data_allowed
|
||||
value: 'false'
|
||||
group: domain_validation
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
key_data_allowed:
|
||||
code: key_data_allowed
|
||||
value: 'true'
|
||||
group: domain_validation
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
dnskeys_min_count:
|
||||
code: dnskeys_min_count
|
||||
value: '0'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
dnskeys_max_count:
|
||||
code: dnskeys_max_count
|
||||
value: '9'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
nameserver_required:
|
||||
code: nameserver_required
|
||||
value: 'false'
|
||||
group: domain_validation
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
ns_min_count:
|
||||
code: ns_min_count
|
||||
value: '2'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
ns_max_count:
|
||||
code: ns_max_count
|
||||
value: '11'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
expire_pending_confirmation:
|
||||
code: expire_pending_confirmation
|
||||
value: '48'
|
||||
group: domain_validation
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
days_to_renew_domain_before_expire:
|
||||
code: days_to_renew_domain_before_expire
|
||||
value: '90'
|
||||
group: domain_expiration
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
expire_warning_period:
|
||||
code: expire_warning_period
|
||||
value: '15'
|
||||
group: domain_expiration
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
redemption_grace_period:
|
||||
code: redemption_grace_period
|
||||
value: '30'
|
||||
group: domain_expiration
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
transfer_wait_time:
|
||||
code: transfer_wait_time
|
||||
value: '0'
|
||||
group: other
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
ds_digest_type:
|
||||
code: ds_digest_type
|
||||
value: '2'
|
||||
group: other
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
client_side_status_editing_enabled:
|
||||
code: client_side_status_editing_enabled
|
||||
value: 'false'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
api_ip_whitelist_enabled:
|
||||
code: api_ip_whitelist_enabled
|
||||
value: 'false'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registrar_ip_whitelist_enabled:
|
||||
code: registrar_ip_whitelist_enabled
|
||||
value: 'false'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
request_confrimation_on_registrant_change_enabled:
|
||||
code: request_confrimation_on_registrant_change_enabled
|
||||
value: 'true'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
request_confirmation_on_domain_deletion_enabled:
|
||||
code: request_confirmation_on_domain_deletion_enabled
|
||||
value: 'true'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
default_language:
|
||||
code: default_language
|
||||
value: en
|
||||
group: other
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
invoice_number_min:
|
||||
code: invoice_number_min
|
||||
value: '131050'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
invoice_number_max:
|
||||
code: invoice_number_max
|
||||
value: '149999'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
days_to_keep_invoices_active:
|
||||
code: days_to_keep_invoices_active
|
||||
value: '30'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
days_to_keep_overdue_invoices_active:
|
||||
code: days_to_keep_overdue_invoices_active
|
||||
value: '0'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
minimum_deposit:
|
||||
code: minimum_deposit
|
||||
value: '0.0'
|
||||
group: billing
|
||||
format: float
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_receipt_payment_term:
|
||||
code: directo_receipt_payment_term
|
||||
value: R
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_receipt_product_name:
|
||||
code: directo_receipt_product_name
|
||||
value: ETTEM06
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_billing_email:
|
||||
code: registry_billing_email
|
||||
value: info@internet.ee
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_invoice_contact:
|
||||
code: registry_invoice_contact
|
||||
value: 'Martti Õigus'
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_vat_no:
|
||||
code: registry_vat_no
|
||||
value: EE101286464
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_bank:
|
||||
code: registry_bank
|
||||
value: 'LHV Pank'
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_iban:
|
||||
code: registry_iban
|
||||
value: EE557700771000598731
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_swift:
|
||||
code: registry_swift
|
||||
value: LHVBEE22
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_email:
|
||||
code: registry_email
|
||||
value: info@internet.ee
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_phone:
|
||||
code: registry_phone
|
||||
value: '+372 727 1000'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_url:
|
||||
code: registry_url
|
||||
value: www.internet.ee
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_street:
|
||||
code: registry_street
|
||||
value: 'Paldiski mnt 80'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_city:
|
||||
code: registry_city
|
||||
value: Tallinn
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_state:
|
||||
code: registry_state
|
||||
value: Harjumaa
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_country_code:
|
||||
code: registry_country_code
|
||||
value: US
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
expiration_reminder_mail:
|
||||
code: expiration_reminder_mail
|
||||
value: '2'
|
||||
group: domain_expiration
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_monthly_number_min:
|
||||
code: directo_monthly_number_min
|
||||
value: '309901'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_monthly_number_max:
|
||||
code: directo_monthly_number_max
|
||||
value: '309999'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_bank_code:
|
||||
code: registry_bank_code
|
||||
value: '689'
|
||||
group: billing
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_reg_no:
|
||||
code: registry_reg_no
|
||||
value: '90010019'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_zip:
|
||||
code: registry_zip
|
||||
value: '10617'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_juridical_name:
|
||||
code: registry_juridical_name
|
||||
value: 'Eesti Interneti SA'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
address_processing:
|
||||
code: address_processing
|
||||
value: 'false'
|
||||
group: other
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
directo_monthly_number_last:
|
||||
code: directo_monthly_number_last
|
||||
value: '309901'
|
||||
group: billing
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
dispute_period_in_months:
|
||||
code: dispute_period_in_months
|
||||
value: '36'
|
||||
group: other
|
||||
format: integer
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
registry_whois_disclaimer:
|
||||
code: registry_whois_disclaimer
|
||||
value: 'Search results may not be used for commercial, advertising, recompilation,
|
||||
repackaging, redistribution, reuse, obscuring or other similar activities.'
|
||||
group: contacts
|
||||
format: string
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
|
||||
legal_document_is_mandatory:
|
||||
code: legal_document_is_mandatory
|
||||
value: 'true'
|
||||
group: domain_validation
|
||||
format: boolean
|
||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05') %>
|
|
@ -3,8 +3,6 @@ require 'test_helper'
|
|||
class EppDomainCreateBaseTest < EppTestCase
|
||||
|
||||
def test_not_registers_domain_without_legaldoc
|
||||
old_value = Setting.legal_document_is_mandatory
|
||||
Setting.legal_document_is_mandatory = true
|
||||
now = Time.zone.parse('2010-07-05')
|
||||
travel_to now
|
||||
name = "new.#{dns_zones(:one).origin}"
|
||||
|
@ -31,7 +29,6 @@ class EppDomainCreateBaseTest < EppTestCase
|
|||
end
|
||||
|
||||
assert_epp_response :required_parameter_missing
|
||||
Setting.legal_document_is_mandatory = old_value
|
||||
end
|
||||
|
||||
def test_registers_new_domain_with_required_attributes
|
||||
|
@ -121,8 +118,6 @@ class EppDomainCreateBaseTest < EppTestCase
|
|||
name = "new.#{dns_zones(:one).origin}"
|
||||
contact = contacts(:john)
|
||||
registrant = contact.becomes(Registrant)
|
||||
old_value = Setting.legal_document_is_mandatory
|
||||
Setting.legal_document_is_mandatory = true
|
||||
registrar = registrant.registrar
|
||||
|
||||
assert registrar.legaldoc_mandatory?
|
||||
|
@ -155,8 +150,6 @@ class EppDomainCreateBaseTest < EppTestCase
|
|||
post epp_create_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
end
|
||||
|
||||
Setting.legal_document_is_mandatory = old_value
|
||||
end
|
||||
|
||||
def test_registers_reserved_domain_with_registration_code
|
||||
|
|
|
@ -8,7 +8,6 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def teardown
|
||||
Setting.clear_cache
|
||||
Setting.directo_monthly_number_min = 309901
|
||||
Setting.directo_monthly_number_max = 309999
|
||||
Setting.directo_monthly_number_last = 309901
|
||||
|
|
120
test/models/setting_entry_test.rb
Normal file
120
test/models/setting_entry_test.rb
Normal file
|
@ -0,0 +1,120 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SettingEntryTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@new_setting = SettingEntry.new(code: 'new_setting', value: 'looks great', format: 'string', group: 'other')
|
||||
end
|
||||
|
||||
def test_fixture_is_valid
|
||||
assert setting_entries(:legal_document_is_mandatory).valid?
|
||||
end
|
||||
|
||||
def test_can_be_retrieved_via_class_method
|
||||
setting = setting_entries(:legal_document_is_mandatory)
|
||||
assert setting.retrieve, Setting.legal_document_is_mandatory
|
||||
end
|
||||
|
||||
def test_can_be_updated_via_class_method
|
||||
setting = setting_entries(:legal_document_is_mandatory)
|
||||
setting.update(value: 'false')
|
||||
setting.reload
|
||||
|
||||
Setting.legal_document_is_mandatory = true
|
||||
setting.reload
|
||||
assert true, setting.retrieve
|
||||
end
|
||||
|
||||
def test_setting_code_is_required
|
||||
assert @new_setting.valid?
|
||||
@new_setting.code = nil
|
||||
assert_not @new_setting.valid?
|
||||
end
|
||||
|
||||
def test_setting_code_can_only_include_underscore_and_characters
|
||||
assert @new_setting.valid?
|
||||
@new_setting.code = 'a b'
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.code = 'ab_'
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.code = '_ab'
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.code = '1_2'
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.code = 'a_b'
|
||||
assert @new_setting.valid?
|
||||
end
|
||||
|
||||
def test_setting_value_can_be_nil
|
||||
assert @new_setting.valid?
|
||||
@new_setting.value = nil
|
||||
assert @new_setting.valid?
|
||||
end
|
||||
|
||||
def test_setting_format_is_required
|
||||
assert @new_setting.valid?
|
||||
@new_setting.format = nil
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.format = 'nonexistant'
|
||||
assert_not @new_setting.valid?
|
||||
end
|
||||
|
||||
def test_setting_group_is_required
|
||||
assert @new_setting.valid?
|
||||
@new_setting.group = nil
|
||||
assert_not @new_setting.valid?
|
||||
|
||||
@new_setting.group = 'random'
|
||||
assert @new_setting.valid?
|
||||
end
|
||||
|
||||
def test_returns_nil_for_unknown_setting
|
||||
assert_nil Setting.unknown_and_definitely_not_saved_setting
|
||||
end
|
||||
|
||||
def test_throws_error_if_updating_unknown_setting
|
||||
assert_raises ActiveRecord::RecordNotFound do
|
||||
Setting.unknown_and_definitely_not_saved_setting = 'hope it fails'
|
||||
end
|
||||
end
|
||||
|
||||
def test_parses_string_format
|
||||
Setting.create(code: 'string_format', value: '1', format: 'string', group: 'random')
|
||||
assert Setting.string_format.is_a? String
|
||||
end
|
||||
|
||||
def test_parses_integer_format
|
||||
Setting.create(code: 'integer_format', value: '1', format: 'integer', group: 'random')
|
||||
assert Setting.integer_format.is_a? Integer
|
||||
end
|
||||
|
||||
def test_parses_float_format
|
||||
Setting.create(code: 'float_format', value: '0.5', format: 'float', group: 'random')
|
||||
assert Setting.float_format.is_a? Float
|
||||
end
|
||||
|
||||
def test_parses_boolean_format
|
||||
Setting.create(code: 'boolean_format', value: 'true', format: 'boolean', group: 'random')
|
||||
assert_equal true, Setting.boolean_format
|
||||
|
||||
Setting.boolean_format = 'false'
|
||||
assert_equal false, Setting.boolean_format
|
||||
|
||||
Setting.boolean_format = nil
|
||||
assert_equal false, Setting.boolean_format
|
||||
end
|
||||
|
||||
def test_parses_hash_format
|
||||
Setting.create(code: 'hash_format', value: '{"hello": "there"}', format: 'hash', group: 'random')
|
||||
assert Setting.hash_format.is_a? Hash
|
||||
end
|
||||
|
||||
def test_parses_array_format
|
||||
Setting.create(code: 'array_format', value: '[1, 2, 3]', format: 'array', group: 'random')
|
||||
assert Setting.array_format.is_a? Array
|
||||
end
|
||||
end
|
|
@ -26,9 +26,6 @@ require 'rake'
|
|||
Rake::Task.clear
|
||||
Rails.application.load_tasks
|
||||
|
||||
Setting.address_processing = false
|
||||
Setting.registry_country_code = 'US'
|
||||
|
||||
class CompanyRegisterClientStub
|
||||
Company = Struct.new(:registration_number)
|
||||
|
||||
|
@ -47,7 +44,6 @@ class ActiveSupport::TestCase
|
|||
|
||||
teardown do
|
||||
travel_back
|
||||
Setting.address_processing = false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,14 +57,9 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
|
|||
WebMock.reset!
|
||||
Capybara.reset_sessions!
|
||||
Capybara.use_default_driver
|
||||
Setting.address_processing = false
|
||||
end
|
||||
end
|
||||
|
||||
class EppTestCase < ActionDispatch::IntegrationTest
|
||||
include Assertions::EppAssertions
|
||||
|
||||
teardown do
|
||||
Setting.address_processing = false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue