mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Make epp code map dynamic
This commit is contained in:
parent
c166967467
commit
5258c43faa
5 changed files with 57 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -4,12 +4,6 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
include EppErrors
|
||||
|
||||
EPP_CODE_MAP = {
|
||||
'2302' => ['Contact id already exists'],
|
||||
'2303' => [:not_found, :epp_obj_does_not_exist],
|
||||
'2005' => ['Phone nr is invalid', 'Email is invalid']
|
||||
}
|
||||
|
||||
EPP_ATTR_MAP = {}
|
||||
|
||||
has_one :address
|
||||
|
@ -81,7 +75,7 @@ class Contact < ActiveRecord::Base
|
|||
relation = get_relation(model)
|
||||
return true unless relation.nil? || relation.blank?
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -94,27 +88,35 @@ class Contact < ActiveRecord::Base
|
|||
false
|
||||
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)
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
@ -159,6 +151,33 @@ class Domain < ActiveRecord::Base
|
|||
}) if cur_exp_date.to_date != valid_to
|
||||
end
|
||||
|
||||
def epp_code_map
|
||||
domain_validation_sg = SettingGroup.find_by(code: SettingGroup::DOMAIN_VALIDATION_CODE)
|
||||
|
||||
{
|
||||
'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.get(:ns_min_count), max: domain_validation_sg.get(:ns_max_count)}],
|
||||
[: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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -50,8 +50,6 @@ en:
|
|||
blank: 'Admin contact is missing'
|
||||
nameservers:
|
||||
out_of_range: 'Nameservers count must be between %{min}-%{max}'
|
||||
hostname_invalid: 'Hostname is invalid'
|
||||
ip_invalid: 'IPv4 is invalid'
|
||||
period:
|
||||
out_of_range: 'Period must add up to 1, 2 or 3 years'
|
||||
auth_info:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue