Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Andres Keskküla 2014-10-16 12:39:27 +03:00
commit 02e313db46
41 changed files with 237 additions and 695 deletions

View file

@ -2,7 +2,7 @@ class Admin::DomainsController < AdminController
before_action :set_domain, only: [:show, :edit, :update]
def index
@q = Domain.search(params[:q])
@q = Domain.includes(:registrar, :owner_contact).search(params[:q])
@domains = @q.result.page(params[:page])
end

View file

@ -1,30 +0,0 @@
class Admin::SettingGroupsController < AdminController
before_action :set_setting_group, only: [:show, :update]
def index
@q = SettingGroup.search(params[:q])
@setting_groups = @q.result.page(params[:page])
end
def show; end
def update
if @setting_group.update(setting_group_params)
flash[:notice] = I18n.t('shared.setting_updated')
redirect_to [:admin, @setting_group]
else
flash[:alert] = I18n.t('shared.failed_to_update_setting')
render 'show'
end
end
private
def set_setting_group
@setting_group = SettingGroup.find(params[:id])
end
def setting_group_params
params.require(:setting_group).permit(settings_attributes: [:value, :id])
end
end

View file

@ -0,0 +1,48 @@
class Admin::SettingsController < AdminController
before_action :set_setting_group, only: [:show, :update]
def index
@settings = Setting.unscoped
end
def create
casted_settings.each do |k, v|
Setting[k] = v
end
flash[:notice] = I18n.t('shared.records_updated')
redirect_to [:admin, :settings]
end
def show; end
def update
if @setting_group.update(setting_group_params)
flash[:notice] = I18n.t('shared.setting_updated')
redirect_to [:admin, @setting_group]
else
flash[:alert] = I18n.t('shared.failed_to_update_setting')
render 'show'
end
end
private
def set_setting_group
@setting_group = SettingGroup.find(params[:id])
end
def setting_group_params
params.require(:setting_group).permit(settings_attributes: [:value, :id])
end
def casted_settings
settings = {}
params[:settings].each do |k, v|
settings[k] = v.to_i if Setting[k].class == Fixnum
settings[k] = v.to_f if Setting[k].class == Float
settings[k] = (v == 'true' ? true : false) if [TrueClass, FalseClass].include?(Setting[k].class)
end
settings
end
end

View file

@ -4,7 +4,7 @@ class Client::DomainsController < ClientController
before_action :verify_deletion, only: [:destroy]
def index
@q = current_registrar.domains.search(params[:q])
@q = current_registrar.domains.includes(:owner_contact).search(params[:q])
@domains = @q.result.page(params[:page])
end

View file

@ -1,42 +0,0 @@
class DelegationSigner < ActiveRecord::Base
include EppErrors
has_one :dnskeys
validate :validate_dnskeys_uniqueness
validate :validate_dnskeys_count
def epp_code_map
sg = SettingGroup.domain_validation
{
'2004' => [ # Parameter value range error
[:dnskeys, :out_of_range,
{
min: sg.setting(Setting::DNSKEYS_MIN_COUNT).value,
max: sg.setting(Setting::DNSKEYS_MAX_COUNT).value
}
]
]
}
end
def validate_dnskeys_count
sg = SettingGroup.domain_validation
min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
end
def validate_dnskeys_uniqueness
validated = []
list = dnskeys.reject(&:marked_for_destruction?)
list.each do |dnskey|
next if dnskey.public_key.blank?
existing = list.select { |x| x.public_key == dnskey.public_key }
next unless existing.length > 1
validated << dnskey.public_key
errors.add(:dnskeys, :invalid) if errors[:dnskeys].blank?
dnskey.errors.add(:public_key, :taken)
end
end
end

View file

@ -66,11 +66,9 @@ class Dnskey < ActiveRecord::Base
hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join
bin = self.class.hex_to_bin(hex)
sg = SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value
if sg == '1'
if Setting.ds_algorithm == 1
self.ds_digest = Digest::SHA1.hexdigest(bin).upcase
elsif sg == '2'
elsif Setting.ds_algorithm == 2
self.ds_digest = Digest::SHA256.hexdigest(bin).upcase
end
end

View file

@ -103,9 +103,7 @@ class Domain < ActiveRecord::Base
### VALIDATIONS ###
def validate_nameservers_count
sg = SettingGroup.domain_validation
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
min, max = Setting.ns_min_count, Setting.ns_max_count
return if nameservers.reject(&:marked_for_destruction?).length.between?(min, max)
errors.add(:nameservers, :out_of_range, { min: min, max: max })
end
@ -115,8 +113,7 @@ class Domain < ActiveRecord::Base
end
def validate_dnskeys_count
sg = SettingGroup.domain_validation
min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i
min, max = Setting.dnskeys_min_count, Setting.dnskeys_max_count
return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max)
errors.add(:dnskeys, :out_of_range, { min: min, max: max })
end

View file

@ -14,7 +14,7 @@ class DomainTransfer < ActiveRecord::Base
before_create :set_wait_until
def set_wait_until
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
wait_time = Setting.transfer_wait_time
return if wait_time == 0
self.wait_until = transfer_requested_at + wait_time.hours
end

View file

@ -6,8 +6,6 @@ class Epp::EppDomain < Domain
validate :validate_admin_contacts_count
def epp_code_map # rubocop:disable Metrics/MethodLength
domain_validation_sg = SettingGroup.domain_validation
{
'2002' => [
[:base, :domain_already_belongs_to_the_querying_registrar]
@ -29,15 +27,15 @@ class Epp::EppDomain < Domain
'2004' => [ # Parameter value range error
[:nameservers, :out_of_range,
{
min: domain_validation_sg.setting(:ns_min_count).value,
max: domain_validation_sg.setting(:ns_max_count).value
min: Setting.ns_min_count,
max: Setting.ns_max_count
}
],
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
[:dnskeys, :out_of_range,
{
min: domain_validation_sg.setting(Setting::DNSKEYS_MIN_COUNT).value,
max: domain_validation_sg.setting(Setting::DNSKEYS_MAX_COUNT).value
min: Setting.dnskeys_min_count,
max: Setting.dnskeys_max_count
}
]
],
@ -189,8 +187,7 @@ class Epp::EppDomain < Domain
end
def attach_dnskeys(dnssec_data)
sg = SettingGroup.dnskeys
return false unless validate_dnssec_data(dnssec_data, sg)
return false unless validate_dnssec_data(dnssec_data)
dnssec_data[:ds_data].each do |ds_data|
dnskeys.build(ds_data)
@ -200,41 +197,35 @@ class Epp::EppDomain < Domain
dnskeys.build({
ds_key_tag: SecureRandom.hex(5),
ds_alg: 3,
ds_digest_type: sg.setting(Setting::DS_ALGORITHM).value
ds_digest_type: Setting.ds_algorithm
}.merge(x))
end
end
def validate_dnssec_data(dnssec_data, sg)
ds_data_allowed?(dnssec_data, sg)
ds_data_with_keys_allowed?(dnssec_data, sg)
key_data_allowed?(dnssec_data, sg)
def validate_dnssec_data(dnssec_data)
ds_data_allowed?(dnssec_data)
ds_data_with_keys_allowed?(dnssec_data)
key_data_allowed?(dnssec_data)
errors.empty?
end
def ds_data_allowed?(dnssec_data, sg)
ds_data_allowed = sg.setting(Setting::ALLOW_DS_DATA).value == '0' ? false : true
return if (dnssec_data[:ds_data].any? && ds_data_allowed) || dnssec_data[:ds_data].empty?
def ds_data_allowed?(dnssec_data)
return if (dnssec_data[:ds_data].any? && Setting.ds_data_allowed) || dnssec_data[:ds_data].empty?
errors.add(:base, :ds_data_not_allowed)
end
def ds_data_with_keys_allowed?(dnssec_data, sg)
ds_data_with_keys_allowed = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS).value == '0' ? false : true
def ds_data_with_keys_allowed?(dnssec_data)
dnssec_data[:ds_data].each do |ds_data|
if key_data?(ds_data) && !ds_data_with_keys_allowed
if key_data?(ds_data) && !Setting.ds_data_with_key_allowed
errors.add(:base, :ds_data_with_key_not_allowed)
return
end
end
end
def key_data_allowed?(dnssec_data, sg)
key_data_allowed = sg.setting(Setting::ALLOW_KEY_DATA).value == '0' ? false : true
return if (dnssec_data[:key_data].any? && key_data_allowed) || dnssec_data[:key_data].empty?
def key_data_allowed?(dnssec_data)
return if (dnssec_data[:key_data].any? && Setting.key_data_allowed) || dnssec_data[:key_data].empty?
errors.add(:base, :key_data_not_allowed)
end
@ -244,9 +235,7 @@ class Epp::EppDomain < Domain
end
def detach_dnskeys(dnssec_data)
sg = SettingGroup.dnskeys
return false unless validate_dnssec_data(dnssec_data, sg)
return false unless validate_dnssec_data(dnssec_data)
to_delete = []
dnssec_data[:ds_data].each do |x|
@ -305,9 +294,7 @@ class Epp::EppDomain < Domain
return true if pt
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
if wait_time > 0
if Setting.transfer_wait_time > 0
domain_transfers.create(
status: DomainTransfer::PENDING,
transfer_requested_at: Time.zone.now,

View file

@ -1,14 +1,2 @@
class Setting < ActiveRecord::Base
belongs_to :setting_group
has_many :domain_statuses
has_many :domains, through: :domain_statuses
validates :code, uniqueness: { scope: :setting_group_id }
# dnskeys
DS_ALGORITHM = 'ds_algorithm'
ALLOW_DS_DATA = 'allow_ds_data'
ALLOW_DS_DATA_WITH_KEYS = 'allow_ds_data_with_keys'
ALLOW_KEY_DATA = 'allow_key_data'
DNSKEYS_MAX_COUNT = 'dnskeys_max_count'
DNSKEYS_MIN_COUNT = 'dnskeys_min_count'
class Setting < RailsSettings::CachedSettings
end

View file

@ -1,25 +0,0 @@
class SettingGroup < ActiveRecord::Base
has_many :settings
accepts_nested_attributes_for :settings
validates :code, uniqueness: true
def setting(key)
settings.find_by(code: key.to_s)
end
class << self
def domain_validation
find_by(code: 'domain_validation')
end
def domain_general
find_by(code: 'domain_general')
end
def dnskeys
find_by(code: 'dnskeys')
end
end
end

View file

@ -1,17 +0,0 @@
%h2= t('shared.setting_groups')
%hr
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-9'}
= sort_link(@q, 'code', t('shared.setting_group'))
%th{class: 'col-xs-2'}
= t('shared.action')
%tbody
- @setting_groups.each do |x|
%tr
%td= t("setting_groups.codes.#{x.code}")
%td= link_to(t('shared.edit_settings'), admin_setting_group_path(x), class: 'btn btn-primary btn-xs')

View file

@ -1,22 +0,0 @@
%h2= t("setting_groups.codes.#{@setting_group.code}")
%hr
= form_for([:admin, @setting_group]) do |f|
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-9'}
= t('shared.setting')
%th{class: 'col-xs-2'}
= t('shared.value')
%tbody
- @setting_group.settings.order(:code).each do |setting|
= f.fields_for :settings, setting do |sf|
%tr
%td= sf.label :value, t("settings.codes.#{sf.object.code}")
%td= sf.text_field(:value, autocomplete: 'off')
.row
.col-md-12.text-right
%button.btn.btn-primary=t('shared.save')

View file

@ -0,0 +1,26 @@
%h2= t('shared.settings')
%hr
= form_tag [:admin, :settings] do
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-9'}
= t('shared.setting')
%th{class: 'col-xs-2'}
= t('shared.value')
%tbody
- @settings.each do |x|
%tr
%td= t("shared.#{x.var}")
- if [TrueClass, FalseClass].include?(x.value.class)
%td
= hidden_field_tag("[settings][#{x.var}]", '')
= check_box_tag("[settings][#{x.var}]", true, x.value)
- else
%td= text_field_tag("[settings][#{x.var}]", x.value)
.row
.col-md-12.text-right
%button.btn.btn-primary=t('shared.save')

View file

@ -36,7 +36,7 @@
%ul.dropdown-menu{role: "menu"}
%li.dropdown-header= t('shared.system')
%li
= link_to t('shared.setting_groups'), admin_setting_groups_path
= link_to t('shared.settings'), admin_settings_path
%li.divider
%li.dropdown-header= t('shared.users')
%li