mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Merge pull request #118 from internetee/111864739-history_legal_doc
111864739 history legal doc
This commit is contained in:
commit
d20bd1e650
9 changed files with 140 additions and 21 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,
|
||||
|
@ -540,9 +544,15 @@ class Contact < ActiveRecord::Base
|
|||
]).present?
|
||||
end
|
||||
|
||||
def update_related_whois_records
|
||||
names = related_domain_descriptions.keys
|
||||
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
|
||||
end
|
||||
def update_related_whois_records
|
||||
names = related_domain_descriptions.keys
|
||||
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
|
||||
end
|
||||
|
||||
def children_log
|
||||
log = HashWithIndifferentAccess.new
|
||||
log[:legal_documents]= [legal_document_id]
|
||||
log
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,6 +7,8 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
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: most inputs should be trimmed before validatation, probably some global logic?
|
||||
|
||||
|
@ -737,6 +739,7 @@ class Domain < ActiveRecord::Base
|
|||
log[:admin_contacts] = admin_contact_ids
|
||||
log[:tech_contacts] = tech_contact_ids
|
||||
log[:nameservers] = nameserver_ids
|
||||
log[:legal_documents]= [legal_document_id]
|
||||
log[:registrant] = [registrant_id]
|
||||
log[:domain_statuses] = domain_status_ids
|
||||
log
|
||||
|
|
|
@ -37,10 +37,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
|
||||
|
@ -104,6 +101,7 @@ class Epp::Contact < Contact
|
|||
|
||||
res
|
||||
end
|
||||
|
||||
end
|
||||
delegate :ident_attr_valid?, to: :class
|
||||
|
||||
|
@ -152,8 +150,14 @@ class Epp::Contact < Contact
|
|||
at[:statuses] = statuses - statuses_attrs(frame.css('rem'), 'rem') + statuses_attrs(frame.css('add'), 'add')
|
||||
end
|
||||
|
||||
legal_frame = frame.css('legalDocument').first
|
||||
at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||
# legal_frame = frame.css('legalDocument').first
|
||||
# at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_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?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
self.deliver_emails = true # turn on email delivery for epp
|
||||
|
||||
|
||||
|
@ -217,4 +221,29 @@ 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
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
return unless legal_document_data
|
||||
|
||||
doc = LegalDocument.create(
|
||||
documentable_type: Contact,
|
||||
document_type: legal_document_data[:type],
|
||||
body: legal_document_data[:body]
|
||||
)
|
||||
self.legal_documents = [doc]
|
||||
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -195,9 +195,27 @@ 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
|
||||
legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame)
|
||||
return unless legal_document_data
|
||||
|
||||
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 && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/MethodLength
|
||||
|
@ -457,15 +475,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
|
||||
|
@ -477,6 +486,7 @@ class Epp::Domain < Domain
|
|||
|
||||
if doc = attach_legal_document(Epp::Domain.parse_legal_document_from_frame(frame))
|
||||
frame.css("legalDocument").first.content = doc.path if doc && doc.persisted?
|
||||
self.legal_document_id = doc.id
|
||||
end
|
||||
|
||||
at_add = attrs_from(frame.css('add'), current_user, 'add')
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
class LegalDocument < ActiveRecord::Base
|
||||
include EppErrors
|
||||
MIN_BODY_SIZE = (1.37 * 8.kilobytes).ceil
|
||||
|
||||
if ENV['legal_document_types'].present?
|
||||
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
|
||||
else
|
||||
|
@ -10,11 +13,22 @@ class LegalDocument < ActiveRecord::Base
|
|||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
|
||||
validates :body, length: { minimum: (1.37 * 8.kilobytes).ceil }, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
||||
validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
||||
|
||||
before_create :add_creator
|
||||
before_save :save_to_filesystem
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2306' => [
|
||||
[:body, :length]
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def val_body_length
|
||||
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
|
||||
end
|
||||
|
||||
|
||||
def save_to_filesystem
|
||||
|
|
|
@ -206,6 +206,10 @@ en:
|
|||
blank: 'Algorithm is missing'
|
||||
auth_info_pw:
|
||||
blank: 'Password is missing'
|
||||
legal_document:
|
||||
attributes:
|
||||
body:
|
||||
length: 'Parameter value policy error: legalDocument size should be more than 8kB'
|
||||
|
||||
|
||||
attributes:
|
||||
|
|
45
lib/tasks/documents.rake
Normal file
45
lib/tasks/documents.rake
Normal file
|
@ -0,0 +1,45 @@
|
|||
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.find_each do |x|
|
||||
|
||||
next if x.documentable_id.blank?
|
||||
|
||||
document_type = case x.documentable_type
|
||||
when 'Domain' then DomainVersion
|
||||
when 'Contact'then ContactVersion
|
||||
end
|
||||
|
||||
dc = document_type.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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue