Contact refactor to new epp errors

This commit is contained in:
Martin Lensment 2014-08-07 14:29:20 +03:00
parent 6b86af3048
commit 55decf3dd4
5 changed files with 29 additions and 19 deletions

View file

@ -5,8 +5,7 @@ module Epp::ContactsHelper
if @contact.save
render '/epp/contacts/create'
else
handle_contact_errors
render '/epp/error'
handle_errors(@contact)
end
end
@ -16,8 +15,7 @@ module Epp::ContactsHelper
if @contact.update_attributes(contact_and_address_attributes.delete_if { |k, v| v.nil? })
render 'epp/contacts/update'
else
handle_contact_errors
render '/epp/error'
handle_errors(@contact)
end
end

View file

@ -1,18 +1,6 @@
module EppErrors
extend ActiveSupport::Concern
EPP_CODE_MAP = {
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'],
'2306' => ['Registrant is missing', 'Nameservers count must be between 1-13', 'Admin contact is missing'],
'2303' => ['Contact was not found'],
'2005' => ['Hostname is invalid', 'IP is invalid']
}
EPP_OBJ_MAP = {
hostname: 'ns',
name_dirty: 'domain'
}
def construct_epp_errors
epp_errors = []
errors.messages.each do |key, values|
@ -38,7 +26,7 @@ module EppErrors
else
next unless code = find_epp_code(err)
err = {code: code, msg: err}
err[:value] = {val: send(key), obj: EPP_OBJ_MAP[key]} unless self.class.reflect_on_association(key)
err[:value] = {val: send(key), obj: self.class::EPP_OBJ} unless self.class.reflect_on_association(key)
epp_errors << err
end
end
@ -61,7 +49,7 @@ module EppErrors
end
def find_epp_code(msg)
EPP_CODE_MAP.each do |code, values|
self.class::EPP_CODE_MAP.each do |code, values|
return code if values.include?(msg)
end
nil

View file

@ -2,6 +2,16 @@ class Contact < ActiveRecord::Base
#TODO Foreign contact will get email with activation link/username/temp password
#TODO Phone number validation, in first phase very minimam in order to support current registries
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_OBJ = 'contact'
has_one :address
has_many :domain_contacts
has_many :domains, through: :domain_contacts

View file

@ -4,6 +4,14 @@ class Domain < ActiveRecord::Base
include EppErrors
EPP_CODE_MAP = {
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'],
'2306' => ['Registrant is missing', 'Nameservers count must be between 1-13', 'Admin contact is missing'],
'2303' => ['Contact was not found']
}
EPP_OBJ = 'domain'
belongs_to :registrar
belongs_to :owner_contact, class_name: 'Contact'

View file

@ -1,6 +1,12 @@
class Nameserver < ActiveRecord::Base
include EppErrors
EPP_CODE_MAP = {
'2005' => ['Hostname is invalid', 'IP is invalid']
}
EPP_OBJ = 'ns'
belongs_to :registrar
has_and_belongs_to_many :domains