Skip to content

Commit

Permalink
Use central method for appending legaldocs to domains/contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed Dec 29, 2020
1 parent 7caa544 commit 404e7e1
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 62 deletions.
24 changes: 24 additions & 0 deletions app/models/actions/base_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Actions
class BaseAction
def self.maybe_attach_legal_doc(entity, legal_doc)
return unless legal_doc
return if legal_doc[:body].starts_with?(ENV['legal_documents_dir'])

entity.legal_documents.create(
document_type: legal_doc[:type],
body: legal_doc[:body]
)
end

def self.attach_legal_doc_to_new(entity, legal_doc, domain: true)
return unless legal_doc

doc = LegalDocument.create(
documentable_type: domain ? Domain : Contact,
document_type: legal_doc[:type],
body: legal_doc[:body]
)
entity.legal_documents = [doc]
end
end
end
10 changes: 1 addition & 9 deletions app/models/actions/contact_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ def validate_ident_birthday
end

def maybe_attach_legal_doc
return unless legal_document

doc = LegalDocument.create(
documentable_type: Contact,
document_type: legal_document[:type], body: legal_document[:body]
)

contact.legal_documents = [doc]
contact.legal_document_id = doc.id
Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false)
end

def commit
Expand Down
10 changes: 1 addition & 9 deletions app/models/actions/contact_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ def call
end

def maybe_attach_legal_doc
return unless legal_document

document = contact.legal_documents.create(
document_type: legal_document[:type],
body: legal_document[:body]
)

contact.legal_document_id = document.id
contact.save
Actions::BaseAction.maybe_attach_legal_doc(contact, legal_document)
end

def commit
Expand Down
9 changes: 1 addition & 8 deletions app/models/actions/contact_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ def maybe_update_statuses
end

def maybe_attach_legal_doc
return unless legal_document

document = contact.legal_documents.create(
document_type: legal_document[:type],
body: legal_document[:body]
)

contact.legal_document_id = document.id
Actions::BaseAction.maybe_attach_legal_doc(contact, legal_document)
end

def maybe_update_ident
Expand Down
14 changes: 3 additions & 11 deletions app/models/actions/domain_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def call
assign_tech_contacts
domain.attach_default_contacts
assign_expiry_time
maybe_attach_legal_doc

commit
end
Expand Down Expand Up @@ -119,25 +120,16 @@ def process_auction_and_disputes
end

def maybe_attach_legal_doc
return unless legal_document

doc = LegalDocument.create(
documentable_type: Contact,
document_type: legal_document[:type], body: legal_document[:body]
)

contact.legal_documents = [doc]
contact.legal_document_id = doc.id
Actions::BaseAction.attach_legal_doc_to_new(domain, params[:legal_document], domain: true)
end

def commit
unless domain.valid?
domain.errors.delete(:name_dirty) if domain.errors[:puny_label].any?
return false if domain.errors.any?
end
# @domain.add_legal_file_to_new(params[:parsed_frame])
debit_registrar

debit_registrar
return false if domain.errors.any?

process_auction_and_disputes
Expand Down
11 changes: 2 additions & 9 deletions app/models/actions/domain_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def call
assign_tech_contact_changes
assign_requested_statuses
assign_dnssec_modifications
maybe_attach_legal_doc

commit
end
Expand Down Expand Up @@ -224,15 +225,7 @@ def verify_registrant_change?
end

def maybe_attach_legal_doc
return unless legal_document

doc = LegalDocument.create(
documentable_type: Contact,
document_type: legal_document[:type], body: legal_document[:body]
)

contact.legal_documents = [doc]
contact.legal_document_id = doc.id
Actions::BaseAction.maybe_attach_legal_doc(contact, legal_document)
end

def commit
Expand Down
15 changes: 0 additions & 15 deletions app/models/epp/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,6 @@ def attach_default_contacts
admin_contacts << registrant if admin_domain_contacts.blank? && !registrant.org?
end

# Adding legal doc to domain and
# if something goes wrong - raise Rollback error
def add_legal_file_to_new frame
legal_document_data = ::Deserializers::Xml::LegalDocument.new(frame).call
return unless legal_document_data
return if legal_document_data[:body].starts_with?(ENV['legal_documents_dir'])

doc = LegalDocument.create(documentable_type: Domain, document_type: legal_document_data[:type],
body: legal_document_data[:body])
self.legal_documents = [doc]

frame.css("legalDocument").first.content = doc.path if doc&.persisted?
self.legal_document_id = doc.id
end

def apply_pending_delete!
preclean_pendings
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
Expand Down
5 changes: 5 additions & 0 deletions lib/deserializers/xml/domain_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def call
obj[:tech_domain_contacts_attributes] = tech_contacts
obj[:nameservers_attributes] = nameservers
obj[:dnskeys_attributes] = dns_keys
obj[:legal_document] = legal_document

obj
end
Expand All @@ -42,6 +43,10 @@ def tech_contacts
def dns_keys
@dns_keys ||= ::Deserializers::Xml::DnssecKeys.new(frame).key_data
end

def legal_document
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
end
end
end
end
6 changes: 5 additions & 1 deletion lib/deserializers/xml/domain_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def call
obj = { domain: frame.css('name')&.text, registrant: registrant, contacts: contacts,
auth_info: if_present('authInfo > pw'), nameservers: nameservers,
registrar_id: registrar, statuses: statuses, dns_keys: dns_keys,
reserved_pw: if_present('reserved > pw') }
reserved_pw: if_present('reserved > pw'), legal_document: legal_document }

obj.reject { |_key, val| val.blank? }
end
Expand Down Expand Up @@ -85,6 +85,10 @@ def statuses
statuses
end

def legal_document
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
end

def if_present(css_path)
return if frame.css(css_path).blank?

Expand Down

0 comments on commit 404e7e1

Please sign in to comment.