Merge branch '111864739-history_legal_doc' into staging

* 111864739-history_legal_doc:
  111864739-contact_and_domain_create
This commit is contained in:
Stas 2016-02-17 18:40:32 +02:00
commit 0c63f0fa54
5 changed files with 67 additions and 18 deletions

View file

@ -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

View file

@ -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,

View file

@ -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,
@ -527,8 +531,13 @@ class Contact < ActiveRecord::Base
end
def update_related_whois_records
names = related_domain_descriptions.keys
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
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

View file

@ -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
@ -153,6 +150,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
@ -214,4 +217,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

View file

@ -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