111864739-legal_doc_for_pt

This commit is contained in:
Stas 2016-01-19 16:51:19 +02:00
parent e7aef75b25
commit 07d6805aa6
3 changed files with 45 additions and 0 deletions

View file

@ -7,6 +7,8 @@ class Domain < ActiveRecord::Base
attr_accessor :roles attr_accessor :roles
attr_accessor :legal_document_id
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
# TODO: most inputs should be trimmed before validatation, probably some global logic? # TODO: most inputs should be trimmed before validatation, probably some global logic?
@ -821,6 +823,7 @@ class Domain < ActiveRecord::Base
log[:admin_contacts] = admin_contact_ids log[:admin_contacts] = admin_contact_ids
log[:tech_contacts] = tech_contact_ids log[:tech_contacts] = tech_contact_ids
log[:nameservers] = nameserver_ids log[:nameservers] = nameserver_ids
log[:legal_documents]= [legal_document_id]
log[:registrant] = [registrant_id] log[:registrant] = [registrant_id]
log[:domain_statuses] = domain_status_ids log[:domain_statuses] = domain_status_ids
log log

View file

@ -476,6 +476,7 @@ class Epp::Domain < Domain
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame)) if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
self.legal_document_id = doc.id
end end
at_add = attrs_from(frame.css('add'), current_user, 'add') at_add = attrs_from(frame.css('add'), current_user, 'add')

41
lib/tasks/documents.rake Normal file
View file

@ -0,0 +1,41 @@
namespace :documents do
desc 'Generate all'
task all: :environment do
Rake::Task['documents:log'].invoke
end
desc 'Generate legaldoc versions'
task log: :environment do
start = Time.zone.now.to_f
puts '-----> Adding documets id for PaperTrail log...'
count = 0
LegalDocument.all.each do |x|
next if x.documentable_id.blank?
dc = DomainVersion.where(item_id: x.documentable_id)
dc.each do |y|
if x.created_at < (y.created_at + (2*60)) &&
x.created_at > (y.created_at - (2*60))
y.children[:legal_documents] = [x.id]
y.save
count =+1
else
y.children[:legal_documents] = []
y.save
end
end
end
puts "-----> Log changed for #{count} rows in #{(Time.zone.now.to_f - start).round(2)} seconds"
end
end