mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +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
|
authorize! :create, Epp::Contact
|
||||||
@contact = Epp::Contact.new(params[:parsed_frame], current_user.registrar)
|
@contact = Epp::Contact.new(params[:parsed_frame], current_user.registrar)
|
||||||
|
|
||||||
|
@contact.add_legal_file_to_new(params[:parsed_frame])
|
||||||
|
|
||||||
if @contact.save
|
if @contact.save
|
||||||
render_epp_response '/epp/contacts/create'
|
render_epp_response '/epp/contacts/create'
|
||||||
else
|
else
|
||||||
|
|
|
@ -30,6 +30,8 @@ class Epp::DomainsController < EppController
|
||||||
handle_errors and return unless balance_ok?('create') # loads pricelist in this method
|
handle_errors and return unless balance_ok?('create') # loads pricelist in this method
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
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?
|
if @domain.save # TODO: Maybe use validate: false here because we have already validated the domain?
|
||||||
current_user.registrar.debit!({
|
current_user.registrar.debit!({
|
||||||
sum: @domain_pricelist.price.amount,
|
sum: @domain_pricelist.price.amount,
|
||||||
|
|
|
@ -12,6 +12,10 @@ class Contact < ActiveRecord::Base
|
||||||
# TODO: remove later
|
# TODO: remove later
|
||||||
has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy
|
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
|
accepts_nested_attributes_for :legal_documents
|
||||||
|
|
||||||
validates :name, :phone, :email, :ident, :ident_type,
|
validates :name, :phone, :email, :ident, :ident_type,
|
||||||
|
@ -497,8 +501,14 @@ class Contact < ActiveRecord::Base
|
||||||
]).present?
|
]).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_related_whois_records
|
def update_related_whois_records
|
||||||
related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) }
|
related_domain_descriptions.each{ |x, y| WhoisRecord.find_by(name: x).try(:save) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def children_log
|
||||||
|
log = HashWithIndifferentAccess.new
|
||||||
|
log[:legal_documents]= [legal_document_id]
|
||||||
|
log
|
||||||
|
end
|
||||||
|
|
||||||
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[: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?
|
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.merge!(ident_attrs(f.css('ident').first)) if new_record
|
||||||
at
|
at
|
||||||
end
|
end
|
||||||
|
@ -152,6 +149,12 @@ class Epp::Contact < Contact
|
||||||
|
|
||||||
legal_frame = frame.css('legalDocument').first
|
legal_frame = frame.css('legalDocument').first
|
||||||
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
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
|
self.deliver_emails = true # turn on email delivery for epp
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,4 +216,34 @@ class Epp::Contact < Contact
|
||||||
|
|
||||||
status_list
|
status_list
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -194,9 +194,21 @@ class Epp::Domain < Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action)
|
at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action)
|
||||||
at[:legal_documents_attributes] = legal_document_from(frame)
|
|
||||||
at
|
at
|
||||||
end
|
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/PerceivedComplexity
|
||||||
# rubocop: enable Metrics/CyclomaticComplexity
|
# rubocop: enable Metrics/CyclomaticComplexity
|
||||||
# rubocop: enable Metrics/MethodLength
|
# rubocop: enable Metrics/MethodLength
|
||||||
|
@ -456,15 +468,6 @@ class Epp::Domain < Domain
|
||||||
status_list
|
status_list
|
||||||
end
|
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/AbcSize
|
||||||
# rubocop: disable Metrics/CyclomaticComplexity
|
# rubocop: disable Metrics/CyclomaticComplexity
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue