From 07d6805aa60ce1c493dbfbe4e819f018ed4234c3 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 19 Jan 2016 16:51:19 +0200 Subject: [PATCH 01/16] 111864739-legal_doc_for_pt --- app/models/domain.rb | 3 +++ app/models/epp/domain.rb | 1 + lib/tasks/documents.rake | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/tasks/documents.rake diff --git a/app/models/domain.rb b/app/models/domain.rb index e4882473a..8f2010a5e 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -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? @@ -821,6 +823,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 diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 15e16163a..6cda7712f 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -476,6 +476,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') diff --git a/lib/tasks/documents.rake b/lib/tasks/documents.rake new file mode 100644 index 000000000..51ba49108 --- /dev/null +++ b/lib/tasks/documents.rake @@ -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 + From 556868da6f4c8a42f5d1cc9c589ddc0780495b99 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 20 Jan 2016 12:24:13 +0200 Subject: [PATCH 02/16] 111864739-memory_optimization --- lib/tasks/documents.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/documents.rake b/lib/tasks/documents.rake index 51ba49108..d16025785 100644 --- a/lib/tasks/documents.rake +++ b/lib/tasks/documents.rake @@ -12,7 +12,7 @@ namespace :documents do puts '-----> Adding documets id for PaperTrail log...' count = 0 - LegalDocument.all.each do |x| + LegalDocument.where(documentable_type: Domain).find_each do |x| next if x.documentable_id.blank? From 2430bfebf2f5ed3471e88f0b8ed2597b603c96e6 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 26 Jan 2016 17:17:36 +0200 Subject: [PATCH 03/16] 111864739-contact_type_added --- lib/tasks/documents.rake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tasks/documents.rake b/lib/tasks/documents.rake index d16025785..5ae8fb4df 100644 --- a/lib/tasks/documents.rake +++ b/lib/tasks/documents.rake @@ -1,6 +1,5 @@ namespace :documents do - desc 'Generate all' task all: :environment do Rake::Task['documents:log'].invoke @@ -12,11 +11,16 @@ namespace :documents do puts '-----> Adding documets id for PaperTrail log...' count = 0 - LegalDocument.where(documentable_type: Domain).find_each do |x| + LegalDocument.find_each do |x| next if x.documentable_id.blank? - dc = DomainVersion.where(item_id: x.documentable_id) + 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| From 7f9e1e0c9c689e7ddad7ac7366d15304859841c4 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 1 Feb 2016 17:47:58 +0200 Subject: [PATCH 04/16] 111864739-catcher_for_all_domain_methods --- app/models/epp/domain.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 6cda7712f..667b566ca 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -194,7 +194,10 @@ class Epp::Domain < Domain end at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action) - at[:legal_documents_attributes] = legal_document_from(frame) + + doc = legal_document_from(frame) + self.legal_document_id = doc.id if doc.id + at[:legal_documents_attributes] = doc at end # rubocop: enable Metrics/PerceivedComplexity @@ -476,7 +479,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 + self.legal_document_id = doc.id if doc.id end at_add = attrs_from(frame.css('add'), current_user, 'add') @@ -546,6 +549,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 if doc.id end if Setting.request_confirmation_on_domain_deletion_enabled && @@ -698,7 +702,8 @@ class Epp::Domain < Domain self.registrar = current_user.registrar end - attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + self.legal_document_id = doc.id if doc.id save!(validate: false) return dt @@ -726,7 +731,8 @@ class Epp::Domain < Domain generate_auth_info self.registrar = pt.transfer_to - attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + self.legal_document_id = doc.id if doc.id save!(validate: false) end @@ -747,7 +753,8 @@ class Epp::Domain < Domain status: DomainTransfer::CLIENT_REJECTED ) - attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) + self.legal_document_id = doc.id if doc.id save!(validate: false) end From f087a00bef9ee78fccbac6d926d022f89b1aebc5 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 1 Feb 2016 18:08:44 +0200 Subject: [PATCH 05/16] 111864739-legaldocs_for_contacts --- app/models/contact.rb | 11 ++++++++++- app/models/epp/contact.rb | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index ccc44851d..558e930d9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -2,6 +2,7 @@ class Contact < ActiveRecord::Base include Versions # version/contact_version.rb include EppErrors include UserEvents + has_paper_trail class_name: "ContactVersion", meta: { children: :children_log } belongs_to :registrar has_many :domain_contacts @@ -9,6 +10,8 @@ class Contact < ActiveRecord::Base has_many :legal_documents, as: :documentable has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' # when contant is registrant + attr_accessor :legal_document_id + # TODO: remove later has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy @@ -499,6 +502,12 @@ class Contact < ActiveRecord::Base def update_related_whois_records 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 diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index f4773f732..6df2e7b4d 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -38,7 +38,9 @@ class Epp::Contact < Contact legal_frame = f.css('legalDocument').first if legal_frame.present? - at[:legal_documents_attributes] = legal_document_attrs(legal_frame) + doc = legal_document_attrs(legal_frame) + self.legal_document_id = doc.id if doc.id + at[:legal_documents_attributes] = doc end at.merge!(ident_attrs(f.css('ident').first)) if new_record at From feb93b4093ab67b30b4d2d66178457f3d6ed3cfb Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 1 Feb 2016 18:39:06 +0200 Subject: [PATCH 06/16] 111864739-method_fix --- app/models/epp/domain.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 667b566ca..0e53ba264 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -194,10 +194,7 @@ class Epp::Domain < Domain end at[:dnskeys_attributes] = dnskeys_attrs(dnskey_frame, action) - - doc = legal_document_from(frame) - self.legal_document_id = doc.id if doc.id - at[:legal_documents_attributes] = doc + at[:legal_documents_attributes] = legal_document_from(frame) at end # rubocop: enable Metrics/PerceivedComplexity From 0141026408f6e4ea1e90c976c5e48c96ab218c45 Mon Sep 17 00:00:00 2001 From: Stas Date: Tue, 2 Feb 2016 16:38:16 +0200 Subject: [PATCH 07/16] 111864739-nested_id_catch --- app/models/contact.rb | 11 +++++++++++ app/models/epp/contact.rb | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 558e930d9..2400ea33a 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -17,6 +17,8 @@ class Contact < ActiveRecord::Base accepts_nested_attributes_for :legal_documents + before_save :catch_legal_doc_id + validates :name, :phone, :email, :ident, :ident_type, :street, :city, :zip, :country_code, :registrar, presence: true @@ -510,4 +512,13 @@ class Contact < ActiveRecord::Base log end + def catch_legal_doc_id + + if !legal_document_id && doc = self.legal_documents.last.new_record? + + legal_document_id = doc.id + + end +end + end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 6df2e7b4d..f4773f732 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -38,9 +38,7 @@ class Epp::Contact < Contact legal_frame = f.css('legalDocument').first if legal_frame.present? - doc = legal_document_attrs(legal_frame) - self.legal_document_id = doc.id if doc.id - at[:legal_documents_attributes] = doc + at[:legal_documents_attributes] = legal_document_attrs(legal_frame) end at.merge!(ident_attrs(f.css('ident').first)) if new_record at From 59f7f364ad3fc2c1734deeaa19ba9bc9e1a7f8ec Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 4 Feb 2016 16:32:30 +0200 Subject: [PATCH 08/16] 11186739-revert_to_2430bfebf2f5ed3471e88f0b8ed2597b603c96e6 --- app/models/contact.rb | 20 -------------------- app/models/epp/domain.rb | 12 ++++-------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 2400ea33a..fdb114673 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -2,7 +2,6 @@ class Contact < ActiveRecord::Base include Versions # version/contact_version.rb include EppErrors include UserEvents - has_paper_trail class_name: "ContactVersion", meta: { children: :children_log } belongs_to :registrar has_many :domain_contacts @@ -10,15 +9,11 @@ class Contact < ActiveRecord::Base has_many :legal_documents, as: :documentable has_many :registrant_domains, class_name: 'Domain', foreign_key: 'registrant_id' # when contant is registrant - attr_accessor :legal_document_id - # TODO: remove later has_many :depricated_statuses, class_name: 'DepricatedContactStatus', dependent: :destroy accepts_nested_attributes_for :legal_documents - before_save :catch_legal_doc_id - validates :name, :phone, :email, :ident, :ident_type, :street, :city, :zip, :country_code, :registrar, presence: true @@ -506,19 +501,4 @@ class Contact < ActiveRecord::Base 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 - - def catch_legal_doc_id - - if !legal_document_id && doc = self.legal_documents.last.new_record? - - legal_document_id = doc.id - - end -end - end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 0e53ba264..6cda7712f 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -476,7 +476,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 if doc.id + self.legal_document_id = doc.id end at_add = attrs_from(frame.css('add'), current_user, 'add') @@ -546,7 +546,6 @@ 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 if doc.id end if Setting.request_confirmation_on_domain_deletion_enabled && @@ -699,8 +698,7 @@ class Epp::Domain < Domain self.registrar = current_user.registrar end - doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) - self.legal_document_id = doc.id if doc.id + attach_legal_document(self.class.parse_legal_document_from_frame(frame)) save!(validate: false) return dt @@ -728,8 +726,7 @@ class Epp::Domain < Domain generate_auth_info self.registrar = pt.transfer_to - doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) - self.legal_document_id = doc.id if doc.id + attach_legal_document(self.class.parse_legal_document_from_frame(frame)) save!(validate: false) end @@ -750,8 +747,7 @@ class Epp::Domain < Domain status: DomainTransfer::CLIENT_REJECTED ) - doc = attach_legal_document(self.class.parse_legal_document_from_frame(frame)) - self.legal_document_id = doc.id if doc.id + attach_legal_document(self.class.parse_legal_document_from_frame(frame)) save!(validate: false) end From 6ebcaf69d08ae960933c1c6cabfd701131c475c6 Mon Sep 17 00:00:00 2001 From: Stas Date: Mon, 15 Feb 2016 17:52:30 +0200 Subject: [PATCH 09/16] 111864739-contact_and_domain_create --- app/controllers/epp/contacts_controller.rb | 2 ++ app/controllers/epp/domains_controller.rb | 2 ++ app/models/contact.rb | 16 +++++++-- app/models/epp/contact.rb | 41 +++++++++++++++++++--- app/models/epp/domain.rb | 23 ++++++------ 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 5b0a39bbf..14c6de7b6 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -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 diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 91ddeb93d..fb3441580 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -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, diff --git a/app/models/contact.rb b/app/models/contact.rb index fdb114673..5ec9c0a46 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index f4773f732..a3180a534 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -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 diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 6cda7712f..d0f83fd9f 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -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 From 7a659da6a3603e8eb7db45c8691e07d6f83cc44e Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 25 Feb 2016 14:20:19 +0200 Subject: [PATCH 10/16] Story#114471339 - change order when legal docs are saved into DB --- app/models/epp/contact.rb | 18 +++++++++++++----- app/models/epp/domain.rb | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index a3180a534..571cae45b 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -227,14 +227,22 @@ class Epp::Contact < Contact 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? + legal_document_data = Epp::Contact.parse_legal_document_from_frame(frame) + return unless legal_document_data - frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? - self.legal_document_id = doc.id - end + doc = LegalDocument.create( + documentable_type: Contact, + document_type: legal_document_data[:type], + body: legal_document_data[:body] + ) + raise ActiveRecord::Rollback if doc && doc.id.nil? + self.legal_documents = [doc] + + frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? + self.legal_document_id = doc.id end + def parse_legal_document_from_frame frame ld = frame.css('legalDocument').first return nil unless ld diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index d0f83fd9f..1ee8a2d92 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -202,12 +202,19 @@ class Epp::Domain < Domain # 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? + legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame) + return unless legal_document_data - frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? - self.legal_document_id = doc.id - end + doc = LegalDocument.create( + documentable_type: Domain, + document_type: legal_document_data[:type], + body: legal_document_data[:body] + ) + raise ActiveRecord::Rollback if doc && doc.id.nil? + 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 From 30fe6bd1e66c58176aff046117c9dc89f278bd54 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Thu, 25 Feb 2016 17:01:41 +0200 Subject: [PATCH 11/16] Story#114471339 - move parse_legal_document_from_frame to one braking point --- app/models/epp/contact.rb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 571cae45b..e3b972394 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -150,7 +150,7 @@ 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)) + 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 @@ -227,7 +227,7 @@ class Epp::Contact < Contact end def add_legal_file_to_new frame - legal_document_data = Epp::Contact.parse_legal_document_from_frame(frame) + legal_document_data = Epp::Domain.parse_legal_document_from_frame(frame) return unless legal_document_data doc = LegalDocument.create( @@ -242,16 +242,4 @@ class Epp::Contact < Contact self.legal_document_id = doc.id 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 From 14b246d6922972d83c111a4de81526deb8d8baaa Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Fri, 18 Mar 2016 14:43:21 +0200 Subject: [PATCH 12/16] Story#111864739 - do not throw an error. --- app/models/epp/contact.rb | 1 - app/models/epp/domain.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index e3b972394..145e0fd27 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -235,7 +235,6 @@ class Epp::Contact < Contact document_type: legal_document_data[:type], body: legal_document_data[:body] ) - raise ActiveRecord::Rollback if doc && doc.id.nil? self.legal_documents = [doc] frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 1ee8a2d92..ca052bfeb 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -210,7 +210,6 @@ class Epp::Domain < Domain document_type: legal_document_data[:type], body: legal_document_data[:body] ) - raise ActiveRecord::Rollback if doc && doc.id.nil? self.legal_documents = [doc] frame.css("legalDocument").first.content = doc.path if doc && doc.persisted? From 71aae06dd14a956bec4ae6662ae0e10975314d39 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Fri, 18 Mar 2016 15:59:14 +0200 Subject: [PATCH 13/16] Story#111864739 - epp validation --- app/models/legal_document.rb | 18 ++++++++++++++++++ config/locales/en.yml | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 5aef34675..32ed8e61b 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -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 @@ -9,9 +12,24 @@ class LegalDocument < ActiveRecord::Base belongs_to :documentable, polymorphic: true + + 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 2cc8b1387..ad662277d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -205,6 +205,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: From 61f08cda9a6e7cb37c8e1ad423ea7bd076e3ca27 Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 23 Mar 2016 12:15:27 +0200 Subject: [PATCH 14/16] 111864739-method_scope_changed --- app/models/epp/contact.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 145e0fd27..c0952aadd 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -100,6 +100,16 @@ class Epp::Contact < Contact res 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 + end delegate :ident_attr_valid?, to: :class @@ -217,15 +227,6 @@ 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 From 667ce870787578c8028d2f74dcf4320258f0ce7e Mon Sep 17 00:00:00 2001 From: Stas Date: Wed, 23 Mar 2016 18:17:05 +0200 Subject: [PATCH 15/16] 111864739-revert_scope --- app/models/epp/contact.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index c0952aadd..52e32da11 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -101,15 +101,6 @@ class Epp::Contact < Contact res 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 - end delegate :ident_attr_valid?, to: :class @@ -227,6 +218,15 @@ 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 From bd049968e13431131dec1f64d98321f3430b6e64 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 28 Mar 2016 20:16:27 +0300 Subject: [PATCH 16/16] story#115040421 - remove double save of legal doc on contact update --- app/models/epp/contact.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index c0952aadd..3a8cc83b9 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -157,8 +157,8 @@ 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?