Added ident country code and improved other ident things

This commit is contained in:
Priit Tark 2015-02-18 15:26:51 +02:00
parent e9b77c5b0f
commit 44f11de5c8
13 changed files with 117 additions and 66 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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'

View file

@ -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

View file

@ -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) }

View file

@ -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