diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 277ba16ec..5af05d9fd 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -94,6 +94,13 @@ class Epp::ContactsController < EppController 'postalInfo > name', 'postalInfo > addr > city', 'postalInfo > addr > cc', 'ident', 'voice', 'email' ) + ident = params[:parsed_frame].css('ident') + if ident.present? && ident.text != 'birthday' && ident.attr('cc').blank? + epp_errors << { + code: '2003', + msg: I18n.t('errors.messages.required_attribute_missing', key: 'ident country code missing') + } + end @prefix = nil requires 'extension > extdata > legalDocument' end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cc61f56db..0c51ce5a7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,4 +8,13 @@ module ApplicationHelper return '' if unstable_env.nil? "background-image: url(#{image_path(unstable_env.to_s + '.png')});" end + + def ident_indicator(contact) + case contact.ident_type + when 'birthday' + "[#{contact.ident_type}]" + else + "[#{contact.ident_country_code} #{contact.ident_type}]" + end + end end diff --git a/app/models/contact.rb b/app/models/contact.rb index ae47e880b..37b562ff6 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -19,8 +19,9 @@ class Contact < ActiveRecord::Base validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ validates :email, format: /@/ validates :ident, format: /\d{4}-\d{2}-\d{2}/, if: proc { |c| c.ident_type == 'birthday' } - validate :ident_must_be_valid + validates :ident_country_code, presence: true, if: proc { |c| %w(bic priv).include? c.ident_type } validates :code, uniqueness: { message: :epp_id_taken } + validate :ident_valid_format? delegate :street, to: :address delegate :city, to: :address @@ -29,19 +30,17 @@ class Contact < ActiveRecord::Base delegate :country_code, to: :address delegate :country, to: :address + before_validation :set_ident_country_code before_create :generate_code before_create :generate_auth_info after_create :ensure_disclosure scope :current_registrars, ->(id) { where(registrar_id: id) } - IDENT_TYPE_ICO = 'ico' + IDENT_TYPE_BIC = 'bic' IDENT_TYPES = [ - IDENT_TYPE_ICO, # Company registry code (or similar) - 'bic', # Business registry code + IDENT_TYPE_BIC, # Company registry code (or similar) 'priv', # National idendtification number - 'op', # Estonian ID, depricated - 'passport', # Passport number, depricated 'birthday' # Birthday date ] @@ -75,24 +74,27 @@ class Contact < ActiveRecord::Base name end - def ident_must_be_valid - # TODO: Ident can also be passport number or company registry code. - # so have to make changes to validations (and doc/schema) accordingly - return true unless ident.present? && ident_type.present? && ident_type == 'op' - code = Isikukood.new(ident) - errors.add(:ident, 'bad format') unless code.valid? + def ident_valid_format? + case ident_type + when 'priv' + case ident_country_code + when 'EE' + code = Isikukood.new(ident) + errors.add(:ident, :not_valid_EE_identity_format) unless code.valid? + end + end end def ensure_disclosure create_disclosure! unless disclosure end - def juridical? - ident_type == IDENT_TYPE_ICO + def bic? + ident_type == IDENT_TYPE_BIC end - def citizen? - ident_type != IDENT_TYPE_ICO + def priv? + ident_type != IDENT_TYPE_BIC end # generate random id for contact @@ -124,4 +126,14 @@ class Contact < ActiveRecord::Base end destroy end + + def set_ident_country_code + return true unless ident_country_code_changed? && ident_country_code.present? + code = Country.new(ident_country_code) + if code + self.ident_country_code = code.alpha2 + else + errors.add(:ident_country_code, 'is not following ISO_3166-1 alpha 2 format') + end + end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 1453f55f0..2d0a96673 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -211,7 +211,7 @@ class Domain < ActiveRecord::Base attach_contact(DomainContact::TECH, owner_contact) end - return unless admin_domain_contacts.count.zero? && owner_contact.citizen? + return unless admin_domain_contacts.count.zero? && owner_contact.priv? attach_contact(DomainContact::ADMIN, owner_contact) end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 62a052077..b2184eba8 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -20,8 +20,9 @@ class Epp::Contact < Contact at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present? if f.css('ident').present? && f.css('ident').attr('type').present? - at[:ident] = f.css('ident').text - at[:ident_type] = f.css('ident').attr('type').text + at[:ident] = f.css('ident').text + at[:ident_type] = f.css('ident').attr('type').try(:text) + at[:ident_country_code] = f.css('ident').attr('cc').try(:text) end at[:address_attributes] = {}.with_indifferent_access @@ -69,7 +70,8 @@ class Epp::Contact < Contact '2005' => [ # Value syntax error [:phone, :invalid], [:email, :invalid], - [:ident, :invalid] + [:ident, :invalid], + [:ident, :not_valid_EE_identity_format] ] } end diff --git a/app/models/epp/epp_domain.rb b/app/models/epp/epp_domain.rb index 7332b423f..3847d61ea 100644 --- a/app/models/epp/epp_domain.rb +++ b/app/models/epp/epp_domain.rb @@ -129,7 +129,7 @@ class Epp::EppDomain < Domain next end - if k == :admin && contact.juridical? + if k == :admin && contact.bic? add_epp_error('2306', 'contact', x[:contact], [:domain_contacts, :admin_contact_can_be_only_citizen]) next end diff --git a/app/views/admin/contacts/partials/_address.haml b/app/views/admin/contacts/partials/_address.haml index eec7e6145..aecba9a70 100644 --- a/app/views/admin/contacts/partials/_address.haml +++ b/app/views/admin/contacts/partials/_address.haml @@ -1,20 +1,24 @@ .panel.panel-default .panel-heading - %h3.panel-title= t('address') + %h3.panel-title= t(:address) .panel-body - unless @contact.address.nil? %dl.dl-horizontal - %dt= t('street') + - if @contact.bic? + %dt= t(:org_name) + %dd= @contact.org_name + + %dt= t(:street) %dd= @contact.street - %dt= t('city') + %dt= t(:city) %dd= @contact.city - %dt= t('zip') + %dt= t(:zip) %dd= @contact.zip - %dt= t('state') + %dt= t(:state) %dd= @contact.state - %dt= t('country') + %dt= t(:country) %dd= @contact.country diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index 512e7cd5d..2911ab783 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -4,7 +4,7 @@ .panel-body %dl.dl-horizontal %dt= t(:ident) - %dd= @contact.ident + ' [' + @contact.ident_type + ']' + %dd= "#{@contact.ident} #{ident_indicator(@contact)}" %br @@ -14,9 +14,6 @@ %dt= t(:phone) %dd= @contact.phone - %dt= t(:org_name) - %dd= @contact.org_name - - if @contact.fax %dt= t(:fax) %dd= @contact.fax diff --git a/config/locales/en.yml b/config/locales/en.yml index 64e195c04..ea38733b2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,7 +31,6 @@ en: activerecord: errors: models: - contact: attributes: code: @@ -46,6 +45,7 @@ en: invalid: "Email is invalid" ident: blank: "Required parameter missing - ident" + not_valid_EE_identity_format: "Ident not in valid Estonian identity format." domains: exist: 'Object association prohibits operation' @@ -237,6 +237,7 @@ en: invalid_type: 'PostalInfo type is invalid' unimplemented_command: 'Unimplemented command' domain_exists_but_belongs_to_other_registrar: 'Domain exists but belongs to other registrar' + required_attribute_missing: Required attributes missing code: 'Code' value: 'Value' diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index d6bb893d6..a025197c6 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -44,7 +44,7 @@ describe 'EPP Contact', epp: true do }, voice: { value: '+372.1234567' }, email: { value: 'test@example.example' }, - ident: { value: '37605030299', attrs: { type: 'priv' } } + ident: { value: '37605030299', attrs: { type: 'priv', cc: 'EE' } } } create_xml = @epp_xml.create(defaults.deep_merge(overwrites), @legal_document) epp_plain_request(create_xml, :xml) @@ -331,12 +331,6 @@ describe 'EPP Contact', epp: true do end context 'info command' do - before :all do - @registrar1_contact = Fabricate( - :contact, code: 'info-4444', registrar: @registrar1, - name: 'Johnny Awesome', address: Fabricate(:address)) - end - def info_request(overwrites = {}) defaults = { id: { value: @contact.code }, @@ -363,6 +357,10 @@ describe 'EPP Contact', epp: true do end it 'return info about contact' do + @registrar1_contact = Fabricate( + :contact, code: 'info-4444', registrar: @registrar1, + name: 'Johnny Awesome', address: Fabricate(:address)) + response = info_request({ id: { value: @registrar1_contact.code } }) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 90f574fab..cf49a0987 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -16,7 +16,7 @@ describe 'EPP Domain', epp: true do Fabricate(:contact, code: 'citizen_1234') Fabricate(:contact, code: 'sh8013') Fabricate(:contact, code: 'sh801333') - Fabricate(:contact, code: 'juridical_1234', ident_type: 'ico') + Fabricate(:contact, code: 'juridical_1234', ident_type: 'bic') Fabricate(:reserved_domain) @uniq_no = proc { @i ||= 0; @i += 1 } @@ -669,8 +669,8 @@ describe 'EPP Domain', epp: true do }) response = epp_plain_request(xml, :xml) - response[:result_code].should == '2004' response[:msg].should == 'Admin contacts count must be between 1-10' + response[:result_code].should == '2004' response[:clTRID].should == 'ABC-12345' Domain.count.should == domain_count @@ -686,8 +686,8 @@ describe 'EPP Domain', epp: true do }) response = epp_plain_request(xml, :xml) - response[:result_code].should == '2306' response[:msg].should == 'Admin contact can be only citizen' + response[:result_code].should == '2306' end end diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index c483ad554..0462f7a61 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -1,10 +1,11 @@ Fabricator(:contact) do + code { "sh#{Faker::Number.number(8)}" } name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } } phone '+372.12345678' email Faker::Internet.email ident '37605030299' - code { "sh#{Faker::Number.number(8)}" } - ident_type 'op' + ident_type 'priv' + ident_country_code 'EE' auth_info 'ccds4324pok' address registrar { Fabricate(:registrar, name: Faker::Company.name, reg_no: Faker::Company.duns_number) } diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index d05d0d40c..0b00e8737 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -52,6 +52,42 @@ describe Contact do @contact.errors[:phone].should == ["Phone nr is invalid"] end + it 'should require country code when bic' do + @contact.ident_type = 'bic' + @contact.valid? + @contact.errors[:ident_country_code].should == ['is missing'] + end + + it 'should require country code when priv' do + @contact.ident_type = 'priv' + @contact.valid? + @contact.errors[:ident_country_code].should == ['is missing'] + end + + it 'should validate correct country code' do + @contact.ident_type = 'bic' + @contact.ident_country_code = 'EE' + @contact.valid? + + @contact.errors[:ident_country_code].should == [] + end + + it 'should require valid country code' do + @contact.ident_type = 'bic' + @contact.ident_country_code = 'INVALID' + @contact.valid? + + @contact.errors[:ident_country_code].should == ['is not following ISO_3166-1 alpha 2 format'] + end + + it 'should convert to alpha2 country code' do + @contact.ident_type = 'bic' + @contact.ident_country_code = 'ee' + @contact.valid? + + @contact.ident_country_code.should == 'EE' + end + it 'should not have any versions' do @contact.versions.should == [] end @@ -87,18 +123,12 @@ describe Contact do @contact.relations_with_domain?.should == false end - # it 'ico should be valid' do - # @contact.ident_type = 'ico' - # @contact.ident = '1234' - # @contact.errors.full_messages.should match_array([]) - # end - - # it 'ident should return false' do - # puts @contact.ident_type - # @contact.ident = '123abc' - # @contact.valid? - # @contact.errors.full_messages.should_not == [] - # end + it 'bic should be valid' do + @contact.ident_type = 'bic' + @contact.ident = '1234' + @contact.valid? + @contact.errors.full_messages.should match_array([]) + end context 'as birthday' do before :all do @@ -177,16 +207,6 @@ describe Contact do @contact.auth_info.should == 'qwe321' end end - - context 'with creator' do - it 'should return username of creator' do - # @contact.creator_str.should == 'gitlab' - end - - it 'should return username of updater' do - # @contact.updator.should == 'gitlab' - end - end end end end