diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index c25050aad..277ba16ec 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -94,6 +94,8 @@ class Epp::ContactsController < EppController 'postalInfo > name', 'postalInfo > addr > city', 'postalInfo > addr > cc', 'ident', 'voice', 'email' ) + @prefix = nil + requires 'extension > extdata > legalDocument' end def validate_update @@ -105,10 +107,14 @@ class Epp::ContactsController < EppController } end requires 'id', 'authInfo > pw' + @prefix = nil + requires 'extension > extdata > legalDocument' end def validate_delete @prefix = 'delete > delete >' requires 'id', 'authInfo > pw' + @prefix = nil + requires 'extension > extdata > legalDocument' end end diff --git a/app/models/contact.rb b/app/models/contact.rb index 539c0d1a2..ae47e880b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -7,10 +7,11 @@ class Contact < ActiveRecord::Base has_many :domain_contacts has_many :domains, through: :domain_contacts has_many :statuses, class_name: 'ContactStatus' + has_many :legal_documents, as: :documentable belongs_to :registrar - accepts_nested_attributes_for :address, :disclosure + accepts_nested_attributes_for :address, :disclosure, :legal_documents validates :name, :phone, :email, :ident, :address, :registrar, :ident_type, presence: true diff --git a/app/models/domain.rb b/app/models/domain.rb index ee70421f0..1453f55f0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -20,8 +20,6 @@ class Domain < ActiveRecord::Base -> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) }, through: :domain_contacts, source: :contact - # TODO: remove old - # has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add has_many :nameservers, dependent: :delete_all accepts_nested_attributes_for :nameservers, allow_destroy: true, @@ -42,11 +40,11 @@ class Domain < ActiveRecord::Base has_many :legal_documents, as: :documentable - delegate :code, to: :owner_contact, prefix: true + delegate :code, to: :owner_contact, prefix: true delegate :email, to: :owner_contact, prefix: true delegate :ident, to: :owner_contact, prefix: true delegate :phone, to: :owner_contact, prefix: true - delegate :name, to: :registrar, prefix: true + delegate :name, to: :registrar, prefix: true before_create :generate_auth_info before_create :set_validity_dates @@ -117,11 +115,6 @@ class Domain < ActiveRecord::Base attr_accessor :owner_contact_typeahead, :update_me - # TODO: remove old - # archiving - # if proc works only on changes on domain sadly - # has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version) - def tech_domain_contacts domain_contacts.select { |x| x.contact_type == DomainContact::TECH } end @@ -130,52 +123,6 @@ class Domain < ActiveRecord::Base domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN } end - # TODO: remove old - # def new_version - # return false if versions.try(:last).try(:snapshot) == create_snapshot - # true - # end - - # TODO: remove old - # def create_version - # return true unless PaperTrail.enabled? - # return true unless valid? - # touch_with_version if new_version - # end - - # TODO: remove old - # def track_nameserver_add(_nameserver) - # return true if versions.count == 0 - # return true unless valid? && new_version - - # touch_with_version - # end - - # TODO: remove old - # def create_snapshot - # oc = owner_contact.snapshot if owner_contact.is_a?(Contact) - # { - # owner_contact: oc, - # tech_contacts: tech_contacts.map(&:snapshot), - # admin_contacts: admin_contacts.map(&:snapshot), - # nameservers: nameservers.map(&:snapshot), - # domain: make_snapshot - # }.to_yaml - # end - - # TODO: remove old - # def make_snapshot - # { - # name: name, - # status: status, - # period: period, - # period_unit: period_unit, - # registrar_id: registrar.try(:id), - # valid_to: valid_to, - # valid_from: valid_from - # } - # end - def name=(value) value.strip! value.downcase! @@ -304,36 +251,36 @@ class Domain < ActiveRecord::Base # rubocop:disable Metrics/MethodLength def update_whois_body self.whois_body = <<-EOS - This Whois Server contains information on - Estonian Top Level Domain ee TLD + This Whois Server contains information on + Estonian Top Level Domain ee TLD - domain: #{name} - registrar: #{registrar} - status: - registered: - changed: #{updated_at.to_s(:db)} - expire: - outzone: - delete: + domain: #{name} + registrar: #{registrar} + status: + registered: + changed: #{updated_at.to_s(:db)} + expire: + outzone: + delete: - contact - name: - e-mail: - registrar: - created: + contact + name: + e-mail: + registrar: + created: - contact: + contact: - nsset: - nserver: + nsset: + nserver: - registrar: - org: - url: - phone: - address: - created: - changed: + registrar: + org: + url: + phone: + address: + created: + changed: EOS end # rubocop:enabled Metrics/MethodLength diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index bb0af23cd..fa11c2663 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -8,6 +8,7 @@ class Epp::Contact < Contact class << self # rubocop: disable Metrics/PerceivedComplexity # rubocop: disable Metrics/CyclomaticComplexity + # rubocop: disable Metrics/MethodLength def attrs_from(frame) f = frame at = {}.with_indifferent_access @@ -23,16 +24,28 @@ class Epp::Contact < Contact at[:ident_type] = f.css('ident').attr('type').text end - at[:address_attributes] = {} + at[:address_attributes] = {}.with_indifferent_access sat = at[:address_attributes] sat[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present? - sat[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present? + sat[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present? sat[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present? sat[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present? sat[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present? at.delete(:address_attributes) if at[:address_attributes].blank? + + legald = f.css('legalDocument').first + if legald.present? + at[:legal_documents_attributes] = {}.with_indifferent_access + lat = at[:legal_documents_attributes] + lat[0] = {}.with_indifferent_access + lat[0][:document_type] = legald['type'] + lat[0][:body] = legald.text + at.delete(:legal_documents_attributes) if at[:legal_documents_attributes].blank? + end + at end + # rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/PerceivedComplexity # rubocop: enable Metrics/CyclomaticComplexity @@ -40,16 +53,6 @@ class Epp::Contact < Contact return super if frame.blank? super(attrs_from(frame)) end - - def parse_legal_document_from_frame(parsed_frame) - ld = parsed_frame.css('legalDocument').first - return nil unless ld - - { - body: ld.text, - type: ld['type'] - } - end end def epp_code_map # rubocop:disable Metrics/MethodLength @@ -74,14 +77,5 @@ class Epp::Contact < Contact at.deep_merge!(self.class.attrs_from(frame.css('chg'))) super(at) end - - def attach_legal_document(legal_document_data) - return unless legal_document_data - - legal_documents.build( - document_type: legal_document_data[:type], - body: legal_document_data[:body] - ) - end end # rubocop: enable Metrics/ClassLength diff --git a/app/views/admin/contacts/show.haml b/app/views/admin/contacts/show.haml index 8a3e3095a..dba7dd39a 100644 --- a/app/views/admin/contacts/show.haml +++ b/app/views/admin/contacts/show.haml @@ -8,3 +8,6 @@ .col-md-6= render 'admin/contacts/partials/address' .row .col-md-12= render 'admin/contacts/partials/domains' +.row + .col-md-12 + = render 'admin/domains/partials/legal_documents', legal_documents: @contact.legal_documents diff --git a/app/views/admin/domains/partials/_legal_documents.haml b/app/views/admin/domains/partials/_legal_documents.haml index b9fe5144e..5a25ae325 100644 --- a/app/views/admin/domains/partials/_legal_documents.haml +++ b/app/views/admin/domains/partials/_legal_documents.haml @@ -8,7 +8,7 @@ %th{class: 'col-xs-8'}= t('created_at') %th{class: 'col-xs-4'}= t('type') %tbody - - @domain.legal_documents.each do |x| + - legal_documents.each do |x| %tr %td= link_to(x.created_at, [:admin, x]) %td= x.document_type diff --git a/app/views/admin/domains/show.haml b/app/views/admin/domains/show.haml index bbb790737..215ade8b1 100644 --- a/app/views/admin/domains/show.haml +++ b/app/views/admin/domains/show.haml @@ -24,4 +24,5 @@ .row .col-md-12= render 'admin/domains/partials/keyrelays' .row - .col-md-12= render 'admin/domains/partials/legal_documents' + .col-md-12 + = render 'admin/domains/partials/legal_documents', legal_documents: @domain.legal_documents diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index da6295c6f..d6bb893d6 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -17,6 +17,12 @@ describe 'EPP Contact', epp: true do Contact.skip_callback(:create, :before, :generate_auth_info) @contact = Fabricate(:contact, registrar: @registrar1) + @legal_document = { + legalDocument: { + value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==', + attrs: { type: 'pdf' } + } + } end after :all do @@ -40,7 +46,7 @@ describe 'EPP Contact', epp: true do email: { value: 'test@example.example' }, ident: { value: '37605030299', attrs: { type: 'priv' } } } - create_xml = @epp_xml.create(defaults.deep_merge(overwrites)) + create_xml = @epp_xml.create(defaults.deep_merge(overwrites), @legal_document) epp_plain_request(create_xml, :xml) end @@ -58,6 +64,8 @@ describe 'EPP Contact', epp: true do 'Required parameter missing: create > create > voice' response[:results][5][:msg].should == 'Required parameter missing: create > create > email' + response[:results][6][:msg].should == + 'Required parameter missing: extension > extdata > legalDocument' response[:results][0][:result_code].should == '2003' response[:results][1][:result_code].should == '2003' @@ -65,8 +73,9 @@ describe 'EPP Contact', epp: true do response[:results][3][:result_code].should == '2003' response[:results][4][:result_code].should == '2003' response[:results][5][:result_code].should == '2003' + response[:results][6][:result_code].should == '2003' - response[:results].count.should == 6 + response[:results].count.should == 7 end it 'successfully creates a contact' do @@ -81,6 +90,7 @@ describe 'EPP Contact', epp: true do @registrar1.api_users.should include(@contact.creator) @contact.ident.should == '37605030299' @contact.address.street.should == '123 Example' + @contact.legal_documents.count.should == 1 log = ApiLog::EppLog.last log.request_command.should == 'create' @@ -156,7 +166,7 @@ describe 'EPP Contact', epp: true do } } } - update_xml = @epp_xml.update(defaults.deep_merge(overwrites)) + update_xml = @epp_xml.update(defaults.deep_merge(overwrites), @legal_document) epp_plain_request(update_xml, :xml) end @@ -172,7 +182,10 @@ describe 'EPP Contact', epp: true do response[:results][2][:msg].should == 'Required parameter missing: update > update > authInfo > pw' response[:results][2][:result_code].should == '2003' - response[:results].count.should == 3 + response[:results][3][:msg].should == + 'Required parameter missing: extension > extdata > legalDocument' + response[:results][3][:result_code].should == '2003' + response[:results].count.should == 4 end it 'returns error if obj doesnt exist' do @@ -225,7 +238,7 @@ describe 'EPP Contact', epp: true do id: { value: @contact.code }, authInfo: { pw: { value: @contact.auth_info } } } - delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites)) + delete_xml = @epp_xml.delete(defaults.deep_merge(overwrites), @legal_document) epp_plain_request(delete_xml, :xml) end @@ -238,7 +251,10 @@ describe 'EPP Contact', epp: true do response[:results][1][:msg].should == 'Required parameter missing: delete > delete > authInfo > pw' response[:results][1][:result_code].should == '2003' - response[:results].count.should == 2 + response[:results][2][:msg].should == + 'Required parameter missing: extension > extdata > legalDocument' + response[:results][2][:result_code].should == '2003' + response[:results].count.should == 3 end it 'returns error if obj doesnt exist' do