mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +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
|
||||
|
|
|
@ -24,6 +24,10 @@ module Deserializers
|
|||
|
||||
# Auth info
|
||||
auth_info: if_present('authInfo pw'),
|
||||
|
||||
# statuses
|
||||
statuses_to_add: statuses_to_add,
|
||||
statuses_to_remove: statuses_to_remove,
|
||||
}
|
||||
|
||||
attributes.compact
|
||||
|
@ -34,6 +38,24 @@ module Deserializers
|
|||
|
||||
frame.css(css_path).text
|
||||
end
|
||||
|
||||
def statuses_to_add
|
||||
statuses_frame = frame.css('add')
|
||||
return unless statuses_frame.present?
|
||||
|
||||
statuses_frame.css('status').map do |status|
|
||||
status['s']
|
||||
end
|
||||
end
|
||||
|
||||
def statuses_to_remove
|
||||
statuses_frame = frame.css('rem')
|
||||
return unless statuses_frame.present?
|
||||
|
||||
statuses_frame.css('status').map do |status|
|
||||
status['s']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,4 +70,43 @@ class DeserializersXmlContactTest < ActiveSupport::TestCase
|
|||
instance = ::Deserializers::Xml::Contact.new(nokogiri_frame)
|
||||
assert_equal instance.call, { name: 'new', email: 'new@registrar.test', phone: '+1.2' }
|
||||
end
|
||||
|
||||
def test_handles_statuses
|
||||
xml_string = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||
<command>
|
||||
<update>
|
||||
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||
<contact:id>john-001</contact:id>
|
||||
<contact:chg>
|
||||
<contact:postalInfo>
|
||||
<contact:name>new name</contact:name>
|
||||
</contact:postalInfo>
|
||||
<contact:voice>+123.4</contact:voice>
|
||||
<contact:email>new-email@inbox.test</contact:email>
|
||||
</contact:chg>
|
||||
<contact:add>
|
||||
<contact:status s="clientDeleteProhibited" lang="en">Payment overdue.</contact:status>
|
||||
<contact:status s="clientUpdateProhibited"/>
|
||||
</contact:add>
|
||||
<contact:rem>
|
||||
<contact:status s="pendingDelete"/>
|
||||
</contact:rem>
|
||||
</contact:update>
|
||||
</update>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
|
||||
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||
instance = ::Deserializers::Xml::Contact.new(nokogiri_frame)
|
||||
assert_equal instance.call, { name: 'new name',
|
||||
email: 'new-email@inbox.test',
|
||||
phone: '+123.4',
|
||||
statuses_to_add: ['clientDeleteProhibited',
|
||||
'clientUpdateProhibited'],
|
||||
statuses_to_remove: ['pendingDelete']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue