diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 3881f9f1c..395681d7e 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -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 @@ -82,7 +80,7 @@ module Epp::ContactsHelper } contact_hash = contact_hash.merge({ - name: ph[:postalInfo][:name], + name: ph[:postalInfo][:name], org_name: ph[:postalInfo][:org] }) if ph[:postalInfo].is_a? Hash diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index 7c2560cda..93c2a47f9 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index 1df21195b..0a73d6fa4 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/domain.rb b/app/models/domain.rb index 486e377e8..0a7512024 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -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' diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index 260f0a059..be807294a 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -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