mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
Move to new serializer
This commit is contained in:
parent
cba445ee5b
commit
d005a61888
3 changed files with 78 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'deserializers/xml/legal_document'
|
||||
require 'deserializers/xml/ident'
|
||||
require 'deserializers/xml/contact'
|
||||
|
||||
class Epp::Contact < Contact
|
||||
include EppErrors
|
||||
|
@ -23,25 +24,8 @@ class Epp::Contact < Contact
|
|||
end
|
||||
|
||||
def attrs_from(frame, new_record: false)
|
||||
f = frame
|
||||
at = {}.with_indifferent_access
|
||||
at[:name] = f.css('postalInfo name').text if f.css('postalInfo name').present?
|
||||
at[:org_name] = f.css('postalInfo org').text if f.css('postalInfo org').present?
|
||||
at[:email] = f.css('email').text if f.css('email').present?
|
||||
at[:fax] = f.css('fax').text if f.css('fax').present?
|
||||
at[:phone] = f.css('voice').text if f.css('voice').present?
|
||||
|
||||
if address_processing?
|
||||
at[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present?
|
||||
at[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present?
|
||||
at[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
|
||||
at[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
|
||||
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
end
|
||||
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
|
||||
ident_attrs = ::Deserializers::Xml::Ident.new(f).call
|
||||
at = ::Deserializers::Xml::Contact.new(frame).call
|
||||
ident_attrs = ::Deserializers::Xml::Ident.new(frame).call
|
||||
at.merge!(ident_attrs) if new_record
|
||||
at
|
||||
end
|
||||
|
@ -72,8 +56,8 @@ class Epp::Contact < Contact
|
|||
|
||||
res
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
delegate :ident_attr_valid?, to: :class
|
||||
|
||||
def epp_code_map
|
||||
|
@ -106,11 +90,11 @@ class Epp::Contact < Contact
|
|||
|
||||
def update_attributes(frame, current_user)
|
||||
return super if frame.blank?
|
||||
at = {}.with_indifferent_access
|
||||
at.deep_merge!(self.class.attrs_from(frame.css('chg'), new_record: false))
|
||||
new_attributes = self.class.attrs_from(frame, new_record: false)
|
||||
|
||||
if Setting.client_status_editing_enabled
|
||||
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
||||
new_attributes[:statuses] =
|
||||
statuses - new_attributes[:statuses_to_remove] + new_attributes[:statuses_to_add]
|
||||
end
|
||||
|
||||
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||
|
@ -118,30 +102,30 @@ class Epp::Contact < Contact
|
|||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
ident_frame = frame.css('ident').first
|
||||
ident_attributes = ::Deserializers::Xml::Ident.new(frame).call
|
||||
|
||||
# https://github.com/internetee/registry/issues/576
|
||||
if ident_frame
|
||||
if ident_attributes[:ident]
|
||||
if identifier.valid?
|
||||
submitted_ident = Ident.new(code: ident_frame.text,
|
||||
type: ident_frame.attr('type'),
|
||||
country_code: ident_frame.attr('cc'))
|
||||
submitted_ident = Ident.new(code: ident_attributes[:ident],
|
||||
type: ident_attributes[:ident_type],
|
||||
country_code: ident_attributes[:ident_country_code])
|
||||
|
||||
if submitted_ident != identifier
|
||||
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident'))
|
||||
return
|
||||
end
|
||||
else
|
||||
ident_update_attempt = ident_frame.text.present? && (ident_frame.text != ident)
|
||||
ident_update_attempt = ident_attributes[:ident] != ident
|
||||
|
||||
if ident_update_attempt
|
||||
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.ident_update'))
|
||||
return
|
||||
end
|
||||
|
||||
identifier = Ident.new(code: ident,
|
||||
type: ident_frame.attr('type'),
|
||||
country_code: ident_frame.attr('cc'))
|
||||
identifier = Ident.new(code: ident_attributes[:ident],
|
||||
type: ident_attributes[:ident_type],
|
||||
country_code: ident_attributes[:ident_country_code])
|
||||
|
||||
identifier.validate
|
||||
|
||||
|
@ -153,7 +137,7 @@ class Epp::Contact < Contact
|
|||
self.upid = current_user.registrar.id if current_user.registrar
|
||||
self.up_date = Time.zone.now
|
||||
|
||||
self.attributes = at
|
||||
self.attributes = new_attributes
|
||||
|
||||
email_changed = will_save_change_to_email?
|
||||
old_email = email_was
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue