Fix some CC issues

This commit is contained in:
Karl Erik Õunapuu 2020-08-12 12:31:11 +03:00
parent a703c312a0
commit b7f03dfa69
3 changed files with 31 additions and 13 deletions

View file

@ -5,10 +5,28 @@ module Concerns
module Migratable
extend ActiveSupport::Concern
VALIDATION_SETTINGS = %w[admin_contacts_min_count admin_contacts_max_count tech_contacts_min_count tech_contacts_max_count orphans_contacts_in_months ds_data_allowed key_data_allowed dnskeys_min_count dnskeys_max_count nameserver_required ns_min_count ns_max_count expire_pending_confirmation legal_document_is_mandatory].freeze
EXPIRATION_SETTINGS = %w[days_to_renew_domain_before_expire expire_warning_period redemption_grace_period expiration_reminder_mail].freeze
BILLING_SETTINGS = %w[invoice_number_min invoice_number_max directo_monthly_number_min directo_monthly_number_max directo_monthly_number_last days_to_keep_invoices_active 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_bank_code registry_iban registry_swift].freeze
CONTACTS_SETTINGS = %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
VALIDATION_SETTINGS =
%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_SETTINGS =
%w[days_to_renew_domain_before_expire expire_warning_period redemption_grace_period
expiration_reminder_mail].freeze
BILLING_SETTINGS =
%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_SETTINGS =
%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_SETTINGS =
%w[
@ -52,7 +70,8 @@ module Concerns
class_methods do
def copy_from_legacy
sql = 'SELECT var, value, created_at, updated_at, creator_str, updator_str FROM settings ORDER BY settings.id ASC'
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|
@ -63,12 +82,8 @@ module Concerns
entry[:format] = 'integer' if INTEGER_SETTINGS.include? entry.code
entry[:group] = 'other'
if VALIDATION_SETTINGS.include? entry.code
entry[:group] = 'domain_validation'
end
if EXPIRATION_SETTINGS.include? entry.code
entry[:group] = 'domain_expiration'
end
entry[:group] = 'domain_validation' if VALIDATION_SETTINGS.include? entry.code
entry[:group] = 'domain_expiration' if EXPIRATION_SETTINGS.include? entry.code
entry[:group] = 'billing' if BILLING_SETTINGS.include? entry.code
entry[:group] = 'contacts' if CONTACTS_SETTINGS.include? entry.code

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
class Setting < SettingEntry
# Bridge Setting calls to SettingEntry, so we don't have to drop legacy settings yet
end

View file

@ -23,11 +23,12 @@ class SettingEntry < ApplicationRecord
SettingEntry.order(id: :asc).where(group: group_name)
end
# rubocop:disable Style/MethodMissingSuper
def self.method_missing(method, *args)
super(method, *args)
rescue NoMethodError
if method.to_s[-1] == "="
stg_code = method.to_s.sub("=", "")
if method.to_s[-1] == '='
stg_code = method.to_s.sub('=', '')
stg_value = args[0].to_s
SettingEntry.find_by!(code: stg_code).update(value: stg_value)
else
@ -35,6 +36,7 @@ class SettingEntry < ApplicationRecord
stg ? stg.retrieve : nil
end
end
# rubocop:enable Style/MethodMissingSuper
# Validators
def valid_value_format