mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
111864739-contact_and_domain_create
This commit is contained in:
parent
59f7f364ad
commit
6ebcaf69d0
5 changed files with 67 additions and 17 deletions
|
@ -19,6 +19,8 @@ class Epp::ContactsController < EppController
|
|||
authorize! :create, Epp::Contact
|
||||
@contact = Epp::Contact.new(params[:parsed_frame], current_user.registrar)
|
||||
|
||||
@contact.add_legal_file_to_new(params[:parsed_frame])
|
||||
|
||||
if @contact.save
|
||||
render_epp_response '/epp/contacts/create'
|
||||
else
|
||||
|
|
|
@ -30,6 +30,8 @@ class Epp::DomainsController < EppController
|
|||
handle_errors and return unless balance_ok?('create') # loads pricelist in this method
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@domain.add_legal_file_to_new(params[:parsed_frame])
|
||||
|
||||
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
|
||||
current_user.registrar.debit!({
|
||||
sum: @domain_pricelist.price.amount,
|
||||
|
|
|
@ -12,6 +12,10 @@ class Contact < ActiveRecord::Base
|
|||
# TODO: remove later
|
||||
has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy
|
||||
|
||||
has_paper_trail class_name: "ContactVersion", meta: { children: :children_log }
|
||||
|
||||
attr_accessor :legal_document_id
|
||||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
validates :name, :phone, :email, :ident, :ident_type,
|
||||
|
@ -497,8 +501,14 @@ class Contact < ActiveRecord::Base
|
|||
]).present?
|
||||
end
|
||||
|
||||
def update_related_whois_records
|
||||
related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) }
|
||||
end
|
||||
def update_related_whois_records
|
||||
related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) }
|
||||
end
|
||||
|
||||
def children_log
|
||||
log = HashWithIndifferentAccess.new
|
||||
log[:legal_documents]= [legal_document_id]
|
||||
log
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -36,10 +36,7 @@ class Epp::Contact < Contact
|
|||
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
|
||||
legal_frame = f.css('legalDocument').first
|
||||
if legal_frame.present?
|
||||
at[:legal_documents_attributes] = legal_document_attrs(legal_frame)
|
||||
end
|
||||
|
||||
at.merge!(ident_attrs(f.css('ident').first)) if new_record
|
||||
at
|
||||
end
|
||||
|
@ -152,6 +149,12 @@ class Epp::Contact < Contact
|
|||
|
||||
legal_frame = frame.css('legalDocument').first
|
||||
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||
|
||||
if doc = attach_legal_document(parse_legal_document_from_frame(frame))
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
self.deliver_emails = true # turn on email delivery for epp
|
||||
|
||||
|
||||
|
@ -213,4 +216,34 @@ class Epp::Contact < Contact
|
|||
|
||||
status_list
|
||||
end
|
||||
|
||||
def attach_legal_document(legal_document_data)
|
||||
return unless legal_document_data
|
||||
|
||||
legal_documents.create(
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
end
|
||||
|
||||
def add_legal_file_to_new frame
|
||||
if doc = attach_legal_document(parse_legal_document_from_frame(frame))
|
||||
raise ActiveRecord::Rollback if doc && doc.id.nil?
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
end
|
||||
|
||||
def parse_legal_document_from_frame frame
|
||||
ld = frame.css('legalDocument').first
|
||||
return nil unless ld
|
||||
return nil if ld.text.starts_with?(ENV['legal_documents_dir'])
|
||||
|
||||
{
|
||||
body: ld.text,
|
||||
type: ld['type']
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -194,9 +194,21 @@ class Epp::Domain < Domain
|
|||
end
|
||||
|
||||
at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action)
|
||||
at[:legal_documents_attributes] = legal_document_from(frame)
|
||||
|
||||
at
|
||||
end
|
||||
|
||||
|
||||
# Adding legal doc to domain and
|
||||
# if something goes wrong - raise Rollback error
|
||||
def add_legal_file_to_new frame
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
raise ActiveRecord::Rollback if doc && doc.id.nil?
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/MethodLength
|
||||
|
@ -456,15 +468,6 @@ class Epp::Domain < Domain
|
|||
status_list
|
||||
end
|
||||
|
||||
def legal_document_from(frame)
|
||||
ld = frame.css('legalDocument').first
|
||||
return [] unless ld
|
||||
|
||||
[{
|
||||
body: ld.text,
|
||||
document_type: ld['type']
|
||||
}]
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue