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

Conflicts:
	app/models/contact.rb
This commit is contained in:
Andres Keskküla 2014-08-22 11:31:02 +03:00
commit 7a9af5a719
20 changed files with 305 additions and 53 deletions

View file

@ -51,8 +51,12 @@ module EppErrors
end
def find_epp_code(msg)
self.class::EPP_CODE_MAP.each do |code, values|
return code if values.include?(msg)
epp_code_map.each do |code, values|
values.each do |x|
t = errors.generate_message(*x) if x.is_a?(Array)
t = x if x.is_a?(String)
return code if t == msg
end
end
nil
end

View file

@ -4,13 +4,6 @@ class Contact < ActiveRecord::Base
include EppErrors
EPP_CODE_MAP = {
'2302' => ['Contact id already exists'],
'2303' => [:not_found, :epp_obj_does_not_exist],
'2305' => ['Object association prohibits operation'],
'2005' => ['Phone nr is invalid', 'Email is invalid']
}
EPP_ATTR_MAP = {}
has_one :address
@ -88,7 +81,7 @@ class Contact < ActiveRecord::Base
relation = get_relation(model)
return true unless relation.nil? || relation.blank?
false
end
end
#should use only in transaction
def destroy_and_clean
@ -101,27 +94,35 @@ class Contact < ActiveRecord::Base
destroy
end
def epp_code_map
{
'2302' => [[:code, :epp_id_taken]],
'2303' => [:not_found, :epp_obj_does_not_exist],
'2005' => ['Phone nr is invalid', 'Email is invalid']
}
end
class << self
def extract_attributes ph, type=:create
contact_hash = {
phone: ph[:voice],
ident: ph[:ident],
email: ph[:email]
}
contact_hash = contact_hash.merge({
name: ph[:postalInfo][:name],
org_name: ph[:postalInfo][:org]
}) if ph[:postalInfo].is_a? Hash
contact_hash[:code] = ph[:id] if type == :create
contact_hash.delete_if { |k, v| v.nil? }
end
def check_availability(codes)
codes = [codes] if codes.is_a?(String)

View file

@ -4,14 +4,6 @@ class Domain < ActiveRecord::Base
include EppErrors
EPP_CODE_MAP = {
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists
'2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error
'2004' => ['Nameservers count must be between 1-13', 'Period must add up to 1, 2 or 3 years'], # Parameter value range error
'2303' => ['Registrant not found', 'Contact was not found'], # Object does not exist
'2200' => ['Authentication error']
}
EPP_ATTR_MAP = {
owner_contact: 'registrant',
name_dirty: 'name',
@ -33,6 +25,10 @@ class Domain < ActiveRecord::Base
has_and_belongs_to_many :nameservers
has_many :domain_statuses, -> {
joins(:setting).where(settings: {setting_group_id: SettingGroup.domain_statuses.id})
}
delegate :code, to: :owner_contact, prefix: true
delegate :name, to: :registrar, prefix: true
@ -53,16 +49,21 @@ class Domain < ActiveRecord::Base
write_attribute(:name_dirty, value)
end
### CREATE ###
### CREATE & UPDATE ###
def attach_objects(ph, parsed_frame)
attach_owner_contact(ph[:registrant])
attach_owner_contact(ph[:registrant]) if ph[:registrant]
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
attach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
attach_statuses(self.class.parse_statuses_from_frame(parsed_frame))
errors.empty?
end
def detach_objects(ph, parsed_frame)
detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
end
def attach_owner_contact(code)
self.owner_contact = Contact.find_by(code: code)
@ -109,6 +110,25 @@ class Domain < ActiveRecord::Base
end
end
def attach_statuses(status_list)
status_list.each do |x|
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
self.domain_statuses.build(
setting: setting,
description: x[:description]
)
end
end
def detach_nameservers(ns_list)
to_delete = []
ns_list.each do |ns_attrs|
to_delete << self.nameservers.where(ns_attrs)
end
self.nameservers.delete(to_delete)
end
### RENEW ###
def renew(cur_exp_date, period, unit='y')
@ -127,8 +147,9 @@ class Domain < ActiveRecord::Base
### VALIDATIONS ###
def validate_nameservers_count
sg = SettingGroup.find_by(code: SettingGroup::DOMAIN_VALIDATION_CODE)
min, max = sg.get(:ns_min_count).to_i, sg.get(:ns_max_count).to_i
sg = SettingGroup.domain_validation
min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i
unless nameservers.length.between?(min, max)
errors.add(:nameservers, :out_of_range, {min: min, max: max})
end
@ -159,6 +180,33 @@ class Domain < ActiveRecord::Base
}) if cur_exp_date.to_date != valid_to
end
def epp_code_map
domain_validation_sg = SettingGroup.domain_validation
{
'2302' => [ # Object exists
[:name_dirty, :taken],
[:name_dirty, :reserved]
],
'2306' => [ # Parameter policy error
[:owner_contact, :blank],
[:admin_contacts, :blank],
[:valid_to, :epp_exp_dates_do_not_match]
],
'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}],
[:period, :out_of_range]
],
'2303' => [ # Object does not exist
[:owner_contact, :epp_registrant_not_found],
[:domain_contacts, :not_found]
],
'2200' => [
[:auth_info, :wrong_pw]
]
}
end
## SHARED
# For domain transfer
@ -211,6 +259,18 @@ class Domain < ActiveRecord::Base
p[:unit]
end
def parse_statuses_from_frame(parsed_frame)
res = []
parsed_frame.css('status').each do |x|
res << {
value: x['s'],
description: x.text
}
end
res
end
def check_availability(domains)
domains = [domains] if domains.is_a?(String)
@ -227,7 +287,7 @@ class Domain < ActiveRecord::Base
end
if Domain.find_by(name: x)
res << {name: x, avail: 0, reason: 'in use'} #confirm reason with current API
res << {name: x, avail: 0, reason: 'in use'}
else
res << {name: x, avail: 1}
end

View file

@ -0,0 +1,21 @@
class DomainStatus < ActiveRecord::Base
# Domain statuses are stored as settings
include EppErrors
EPP_ATTR_MAP = {
setting: 'status'
}
belongs_to :domain
belongs_to :setting
delegate :value, :code, to: :setting
validates :setting, uniqueness: { scope: :domain_id }
def epp_code_map
{
'2302' => [[:setting, :taken]]
}
end
end

View file

@ -1,10 +1,6 @@
class Nameserver < ActiveRecord::Base
include EppErrors
EPP_CODE_MAP = {
'2005' => ['Hostname is invalid', 'IPv4 is invalid', 'IPv6 is invalid']
}
EPP_ATTR_MAP = {
hostname: 'hostName'
}
@ -15,4 +11,14 @@ class Nameserver < ActiveRecord::Base
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
validates :ipv4, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true }
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_nil: true }
def epp_code_map
{
'2005' => [
[:hostname, :invalid],
[:ipv4, :invalid],
[:ipv6, :invalid]
]
}
end
end

View file

@ -1,4 +1,6 @@
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 }
end

View file

@ -3,10 +3,19 @@ class SettingGroup < ActiveRecord::Base
accepts_nested_attributes_for :settings
DOMAIN_VALIDATION_CODE = 'domain_validation'
validates :code, uniqueness: true
def get(key)
s = settings.find_by(code: key.to_s)
s.try(:value)
def setting(key)
settings.find_by(code: key.to_s)
end
class << self
def domain_validation
find_by(code: 'domain_validation')
end
def domain_statuses
find_by(code: 'domain_statuses')
end
end
end