mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 13:44:47 +02:00
Use central method for appending legaldocs to domains/contacts
This commit is contained in:
parent
7caa544c83
commit
50bf708b6a
10 changed files with 61 additions and 73 deletions
|
@ -21,8 +21,9 @@ module Domains
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_domain
|
def update_domain
|
||||||
|
frame_json = domain.pending_json['frame']
|
||||||
user = ApiUser.find(domain.pending_json['current_user_id'])
|
user = ApiUser.find(domain.pending_json['current_user_id'])
|
||||||
frame = domain.pending_json['frame'] ? domain.pending_json['frame'].with_indifferent_access : {}
|
frame = frame_json ? frame_json.with_indifferent_access : {}
|
||||||
|
|
||||||
domain.upid = user.registrar.id if user.registrar
|
domain.upid = user.registrar.id if user.registrar
|
||||||
domain.up_date = Time.zone.now
|
domain.up_date = Time.zone.now
|
||||||
|
|
24
app/models/actions/base_action.rb
Normal file
24
app/models/actions/base_action.rb
Normal file
|
@ -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
|
|
@ -59,15 +59,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_attach_legal_doc
|
def maybe_attach_legal_doc
|
||||||
return unless legal_document
|
Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false)
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
|
|
|
@ -23,15 +23,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_attach_legal_doc
|
def maybe_attach_legal_doc
|
||||||
return unless legal_document
|
Actions::BaseAction.maybe_attach_legal_doc(contact, legal_document)
|
||||||
|
|
||||||
document = contact.legal_documents.create(
|
|
||||||
document_type: legal_document[:type],
|
|
||||||
body: legal_document[:body]
|
|
||||||
)
|
|
||||||
|
|
||||||
contact.legal_document_id = document.id
|
|
||||||
contact.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
|
|
|
@ -42,14 +42,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_attach_legal_doc
|
def maybe_attach_legal_doc
|
||||||
return unless legal_document
|
Actions::BaseAction.maybe_attach_legal_doc(contact, legal_document)
|
||||||
|
|
||||||
document = contact.legal_documents.create(
|
|
||||||
document_type: legal_document[:type],
|
|
||||||
body: legal_document[:body]
|
|
||||||
)
|
|
||||||
|
|
||||||
contact.legal_document_id = document.id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_update_ident
|
def maybe_update_ident
|
||||||
|
|
|
@ -18,6 +18,7 @@ module Actions
|
||||||
assign_tech_contacts
|
assign_tech_contacts
|
||||||
domain.attach_default_contacts
|
domain.attach_default_contacts
|
||||||
assign_expiry_time
|
assign_expiry_time
|
||||||
|
maybe_attach_legal_doc
|
||||||
|
|
||||||
commit
|
commit
|
||||||
end
|
end
|
||||||
|
@ -30,25 +31,33 @@ module Actions
|
||||||
if dn.at_auction?
|
if dn.at_auction?
|
||||||
domain.add_epp_error('2306', nil, nil, 'Parameter value policy error: domain is at auction')
|
domain.add_epp_error('2306', nil, nil, 'Parameter value policy error: domain is at auction')
|
||||||
elsif dn.awaiting_payment?
|
elsif dn.awaiting_payment?
|
||||||
domain.add_epp_error('2003', nil, nil, 'Required parameter missing; reserved>pw element required for reserved domains')
|
domain.add_epp_error('2003', nil, nil, 'Required parameter missing; reserved>pw element' \
|
||||||
|
' required for reserved domains')
|
||||||
elsif dn.pending_registration?
|
elsif dn.pending_registration?
|
||||||
if params[:reserved_pw].blank?
|
if params[:reserved_pw].blank?
|
||||||
domain.add_epp_error('2003', nil, nil, 'Required parameter missing; reserved>pw element is required')
|
domain.add_epp_error('2003', nil, nil, 'Required parameter missing; reserved>pw ' \
|
||||||
|
'element is required')
|
||||||
else
|
else
|
||||||
unless dn.available_with_code?(params[:reserved_pw])
|
unless dn.available_with_code?(params[:reserved_pw])
|
||||||
domain.add_epp_error('2202', nil, nil, 'Invalid authorization information; invalid reserved>pw value')
|
domain.add_epp_error('2202', nil, nil, 'Invalid authorization information; invalid ' \
|
||||||
|
'reserved>pw value')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_registrant
|
def assign_registrant
|
||||||
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) and return unless params[:registrant_id]
|
unless params[:registrant_id]
|
||||||
|
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing])
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
regt = Registrant.find_by(code: params[:registrant_id])
|
regt = Registrant.find_by(code: params[:registrant_id])
|
||||||
domain.add_epp_error('2303', 'registrant', params[:registrant_id], %i[registrant not_found]) and return unless regt
|
if regt
|
||||||
|
domain.registrant = regt
|
||||||
domain.registrant = regt
|
else
|
||||||
|
domain.add_epp_error('2303', 'registrant', params[:registrant_id], %i[registrant not_found])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_domain_attributes
|
def assign_domain_attributes
|
||||||
|
@ -90,8 +99,8 @@ module Actions
|
||||||
def assign_expiry_time
|
def assign_expiry_time
|
||||||
period = domain.period.to_i
|
period = domain.period.to_i
|
||||||
plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym
|
plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym
|
||||||
expire_time = (Time.zone.now.advance(plural_period_unit_name => period) + 1.day).beginning_of_day
|
exp = (Time.zone.now.advance(plural_period_unit_name => period) + 1.day).beginning_of_day
|
||||||
domain.expire_time = expire_time
|
domain.expire_time = exp
|
||||||
end
|
end
|
||||||
|
|
||||||
def debit_registrar
|
def debit_registrar
|
||||||
|
@ -119,15 +128,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_attach_legal_doc
|
def maybe_attach_legal_doc
|
||||||
return unless legal_document
|
Actions::BaseAction.attach_legal_doc_to_new(domain, params[:legal_document], domain: true)
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
|
@ -135,9 +136,8 @@ module Actions
|
||||||
domain.errors.delete(:name_dirty) if domain.errors[:puny_label].any?
|
domain.errors.delete(:name_dirty) if domain.errors[:puny_label].any?
|
||||||
return false if domain.errors.any?
|
return false if domain.errors.any?
|
||||||
end
|
end
|
||||||
# @domain.add_legal_file_to_new(params[:parsed_frame])
|
|
||||||
debit_registrar
|
|
||||||
|
|
||||||
|
debit_registrar
|
||||||
return false if domain.errors.any?
|
return false if domain.errors.any?
|
||||||
|
|
||||||
process_auction_and_disputes
|
process_auction_and_disputes
|
||||||
|
|
|
@ -18,6 +18,7 @@ module Actions
|
||||||
assign_tech_contact_changes
|
assign_tech_contact_changes
|
||||||
assign_requested_statuses
|
assign_requested_statuses
|
||||||
assign_dnssec_modifications
|
assign_dnssec_modifications
|
||||||
|
maybe_attach_legal_doc
|
||||||
|
|
||||||
commit
|
commit
|
||||||
end
|
end
|
||||||
|
@ -189,7 +190,6 @@ module Actions
|
||||||
if domain.statuses.include?(s[:status])
|
if domain.statuses.include?(s[:status])
|
||||||
rem << s[:status]
|
rem << s[:status]
|
||||||
else
|
else
|
||||||
STDOUT << 'AAAAAH'
|
|
||||||
domain.add_epp_error('2303', 'status', s[:status], %i[statuses not_found])
|
domain.add_epp_error('2303', 'status', s[:status], %i[statuses not_found])
|
||||||
invalid = true
|
invalid = true
|
||||||
end
|
end
|
||||||
|
@ -224,15 +224,7 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_attach_legal_doc
|
def maybe_attach_legal_doc
|
||||||
return unless legal_document
|
Actions::BaseAction.maybe_attach_legal_doc(domain, params[: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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
|
|
|
@ -114,21 +114,6 @@ class Epp::Domain < Domain
|
||||||
admin_contacts << registrant if admin_domain_contacts.blank? && !registrant.org?
|
admin_contacts << registrant if admin_domain_contacts.blank? && !registrant.org?
|
||||||
end
|
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!
|
def apply_pending_delete!
|
||||||
preclean_pendings
|
preclean_pendings
|
||||||
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION)
|
||||||
|
|
|
@ -19,6 +19,7 @@ module Deserializers
|
||||||
obj[:tech_domain_contacts_attributes] = tech_contacts
|
obj[:tech_domain_contacts_attributes] = tech_contacts
|
||||||
obj[:nameservers_attributes] = nameservers
|
obj[:nameservers_attributes] = nameservers
|
||||||
obj[:dnskeys_attributes] = dns_keys
|
obj[:dnskeys_attributes] = dns_keys
|
||||||
|
obj[:legal_document] = legal_document
|
||||||
|
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
@ -42,6 +43,10 @@ module Deserializers
|
||||||
def dns_keys
|
def dns_keys
|
||||||
@dns_keys ||= ::Deserializers::Xml::DnssecKeys.new(frame).key_data
|
@dns_keys ||= ::Deserializers::Xml::DnssecKeys.new(frame).key_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def legal_document
|
||||||
|
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Deserializers
|
||||||
obj = { domain: frame.css('name')&.text, registrant: registrant, contacts: contacts,
|
obj = { domain: frame.css('name')&.text, registrant: registrant, contacts: contacts,
|
||||||
auth_info: if_present('authInfo > pw'), nameservers: nameservers,
|
auth_info: if_present('authInfo > pw'), nameservers: nameservers,
|
||||||
registrar_id: registrar, statuses: statuses, dns_keys: dns_keys,
|
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? }
|
obj.reject { |_key, val| val.blank? }
|
||||||
end
|
end
|
||||||
|
@ -85,6 +85,10 @@ module Deserializers
|
||||||
statuses
|
statuses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def legal_document
|
||||||
|
@legal_document ||= ::Deserializers::Xml::LegalDocument.new(frame).call
|
||||||
|
end
|
||||||
|
|
||||||
def if_present(css_path)
|
def if_present(css_path)
|
||||||
return if frame.css(css_path).blank?
|
return if frame.css(css_path).blank?
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue