mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Extract legal doc parsing away from Epp::Domain class
This commit is contained in:
parent
67cfe76f0a
commit
043037225b
5 changed files with 99 additions and 21 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'deserializers/xml/legal_document'
|
||||||
|
|
||||||
class Contact < ApplicationRecord
|
class Contact < ApplicationRecord
|
||||||
include Versions # version/contact_version.rb
|
include Versions # version/contact_version.rb
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
@ -351,7 +353,7 @@ class Contact < ApplicationRecord
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
|
|
||||||
if legal_document_data
|
if legal_document_data
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'deserializers/xml/legal_document'
|
||||||
|
|
||||||
class Epp::Contact < Contact
|
class Epp::Contact < Contact
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ class Epp::Contact < Contact
|
||||||
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
||||||
end
|
end
|
||||||
|
|
||||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||||
self.legal_document_id = doc.id
|
self.legal_document_id = doc.id
|
||||||
end
|
end
|
||||||
|
@ -237,7 +239,7 @@ class Epp::Contact < Contact
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_legal_file_to_new frame
|
def add_legal_file_to_new frame
|
||||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
return unless legal_document_data
|
return unless legal_document_data
|
||||||
|
|
||||||
doc = LegalDocument.create(
|
doc = LegalDocument.create(
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'deserializers/xml/legal_document'
|
||||||
|
|
||||||
class Epp::Domain < Domain
|
class Epp::Domain < Domain
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ class Epp::Domain < Domain
|
||||||
# Adding legal doc to domain and
|
# Adding legal doc to domain and
|
||||||
# if something goes wrong - raise Rollback error
|
# if something goes wrong - raise Rollback error
|
||||||
def add_legal_file_to_new frame
|
def add_legal_file_to_new frame
|
||||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
return unless legal_document_data
|
return unless legal_document_data
|
||||||
|
|
||||||
doc = LegalDocument.create(
|
doc = LegalDocument.create(
|
||||||
|
@ -457,7 +459,7 @@ class Epp::Domain < Domain
|
||||||
at.deep_merge!(attrs_from(frame.css('chg'), current_user, 'chg'))
|
at.deep_merge!(attrs_from(frame.css('chg'), current_user, 'chg'))
|
||||||
at.deep_merge!(attrs_from(frame.css('rem'), current_user, 'rem'))
|
at.deep_merge!(attrs_from(frame.css('rem'), current_user, 'rem'))
|
||||||
|
|
||||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||||
self.legal_document_id = doc.id
|
self.legal_document_id = doc.id
|
||||||
end
|
end
|
||||||
|
@ -554,7 +556,7 @@ class Epp::Domain < Domain
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
if doc = attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
frame.css("legalDocument").first.content = doc.path if doc&.persisted?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -665,7 +667,7 @@ class Epp::Domain < Domain
|
||||||
self.registrar = current_user.registrar
|
self.registrar = current_user.registrar
|
||||||
end
|
end
|
||||||
|
|
||||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
save!(validate: false)
|
save!(validate: false)
|
||||||
|
|
||||||
return dt
|
return dt
|
||||||
|
@ -690,7 +692,7 @@ class Epp::Domain < Domain
|
||||||
regenerate_transfer_code
|
regenerate_transfer_code
|
||||||
self.registrar = pt.new_registrar
|
self.registrar = pt.new_registrar
|
||||||
|
|
||||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
save!(validate: false)
|
save!(validate: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -710,7 +712,7 @@ class Epp::Domain < Domain
|
||||||
status: DomainTransfer::CLIENT_REJECTED
|
status: DomainTransfer::CLIENT_REJECTED
|
||||||
)
|
)
|
||||||
|
|
||||||
attach_legal_document(self.class.parse_legal_document_from_frame(frame))
|
attach_legal_document(::Deserializers::Xml::LegalDocument.new(frame).call)
|
||||||
save!(validate: false)
|
save!(validate: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -759,18 +761,6 @@ class Epp::Domain < Domain
|
||||||
p[:unit]
|
p[:unit]
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_legal_document_from_frame(parsed_frame)
|
|
||||||
ld = parsed_frame.css('legalDocument').first
|
|
||||||
return nil unless ld
|
|
||||||
return nil if ld.text.starts_with?(ENV['legal_documents_dir']) # escape reloading
|
|
||||||
return nil if ld.text.starts_with?('/home/') # escape reloading
|
|
||||||
|
|
||||||
{
|
|
||||||
body: ld.text,
|
|
||||||
type: ld['type']
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_availability(domain_names)
|
def check_availability(domain_names)
|
||||||
domain_names = [domain_names] if domain_names.is_a?(String)
|
domain_names = [domain_names] if domain_names.is_a?(String)
|
||||||
|
|
||||||
|
|
22
lib/deserializers/xml/legal_document.rb
Normal file
22
lib/deserializers/xml/legal_document.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
module Deserializers
|
||||||
|
module Xml
|
||||||
|
# Given a nokogiri frame, extract information about legal document from it.
|
||||||
|
class LegalDocument
|
||||||
|
attr_reader :frame
|
||||||
|
|
||||||
|
def initialize(frame)
|
||||||
|
@frame = frame
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
ld = frame.css('legalDocument').first
|
||||||
|
return unless ld
|
||||||
|
|
||||||
|
{
|
||||||
|
body: ld.text,
|
||||||
|
type: ld['type']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
62
test/lib/deserializers/xml/legal_document_test.rb
Normal file
62
test/lib/deserializers/xml/legal_document_test.rb
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
require 'test_helper'
|
||||||
|
require 'deserializers/xml/legal_document'
|
||||||
|
|
||||||
|
class DeserializersXmlLegalDocumentTest < ActiveSupport::TestCase
|
||||||
|
def test_returns_nil_when_required_fields_not_present
|
||||||
|
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:update>
|
||||||
|
</update>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||||
|
instance = ::Deserializers::Xml::LegalDocument.new(nokogiri_frame)
|
||||||
|
|
||||||
|
assert_nil instance.call
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_hash_when_document_exists
|
||||||
|
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>
|
||||||
|
<delete>
|
||||||
|
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>FIRST0:SH2027223711</contact:id>
|
||||||
|
<contact:authInfo>
|
||||||
|
<contact:pw>wrong password</contact:pw>
|
||||||
|
</contact:authInfo>
|
||||||
|
</contact:delete>
|
||||||
|
</delete>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:ident type="priv" cc="EE">37605030299</eis:ident>
|
||||||
|
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
<clTRID>ABC-12345</clTRID>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
nokogiri_frame = Nokogiri::XML(xml_string).remove_namespaces!
|
||||||
|
instance = ::Deserializers::Xml::LegalDocument.new(nokogiri_frame)
|
||||||
|
expected_result = { body: "dGVzdCBmYWlsCg==", type: "pdf" }
|
||||||
|
|
||||||
|
assert_equal expected_result, instance.call
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue