mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 16:53:37 +02:00
Merge branch 'contact_ident'
Conflicts: db/schema.rb
This commit is contained in:
commit
8a4b91c3b7
8 changed files with 45 additions and 6 deletions
|
@ -12,6 +12,7 @@ module Epp::ContactsHelper
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@contact.name = ph[:postalInfo][:name]
|
@contact.name = ph[:postalInfo][:name]
|
||||||
|
@contact.ident_type = ident_type
|
||||||
|
|
||||||
@contact.addresses << Address.new(
|
@contact.addresses << Address.new(
|
||||||
country_id: Country.find_by(iso: ph[:postalInfo][:cc]),
|
country_id: Country.find_by(iso: ph[:postalInfo][:cc]),
|
||||||
|
@ -53,4 +54,16 @@ module Epp::ContactsHelper
|
||||||
render 'epp/error'
|
render 'epp/error'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ident_type
|
||||||
|
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)
|
||||||
|
|
||||||
|
return nil unless result
|
||||||
|
|
||||||
|
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,10 +7,17 @@ class Contact < ActiveRecord::Base
|
||||||
validate :ident_must_be_valid
|
validate :ident_must_be_valid
|
||||||
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
|
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
|
||||||
|
|
||||||
|
IDENT_TYPES = [
|
||||||
|
"ico", #Company registry code (or similar)
|
||||||
|
"op", #Estonian ID
|
||||||
|
"passport", #Passport number
|
||||||
|
"birthday" #Birthday date
|
||||||
|
]
|
||||||
|
|
||||||
def ident_must_be_valid
|
def ident_must_be_valid
|
||||||
#TODO Ident can also be passport number or company registry code.
|
#TODO Ident can also be passport number or company registry code.
|
||||||
#so have to make changes to validations (and doc/schema) accordingly
|
#so have to make changes to validations (and doc/schema) accordingly
|
||||||
return true unless ident.present?
|
return true unless ident.present? && ident_type.present? && ident_type == "op"
|
||||||
code = Isikukood.new(ident)
|
code = Isikukood.new(ident)
|
||||||
errors.add(:ident, 'bad format') unless code.valid?
|
errors.add(:ident, 'bad format') unless code.valid?
|
||||||
end
|
end
|
||||||
|
|
5
db/migrate/20140730082532_add_ident_type_to_contact.rb
Normal file
5
db/migrate/20140730082532_add_ident_type_to_contact.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddIdentTypeToContact < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :contacts, :ident_type, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20140730082358) do
|
ActiveRecord::Schema.define(version: 20140730082532) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20140730082358) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "ident"
|
t.string "ident"
|
||||||
|
t.string "ident_type"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: true do |t|
|
create_table "countries", force: true do |t|
|
||||||
|
|
|
@ -72,9 +72,20 @@
|
||||||
</restriction>
|
</restriction>
|
||||||
</simpleType>
|
</simpleType>
|
||||||
|
|
||||||
<simpleType name="identType">
|
<complexType name="identType">
|
||||||
<restriction base="normalizedString">
|
<simpleContent>
|
||||||
<maxLength value="11"/>
|
<extension base="eppcom:clIDType">
|
||||||
|
<attribute name="type" type="contact:identAttrType"/>
|
||||||
|
</extension>
|
||||||
|
</simpleContent>
|
||||||
|
</complexType>
|
||||||
|
|
||||||
|
<simpleType name="identAttrType">
|
||||||
|
<restriction base="token">
|
||||||
|
<enumeration value="ico"/>
|
||||||
|
<enumeration value="op"/>
|
||||||
|
<enumeration value="passport"/>
|
||||||
|
<enumeration value="birthday"/>
|
||||||
</restriction>
|
</restriction>
|
||||||
</simpleType>
|
</simpleType>
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe 'EPP Contact', epp: true do
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
|
|
||||||
expect(Contact.first.name).to eq("John Doe")
|
expect(Contact.first.name).to eq("John Doe")
|
||||||
|
expect(Contact.first.ident_type).to eq("op")
|
||||||
|
|
||||||
expect(Contact.count).to eq(1)
|
expect(Contact.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<contact:voice x="1234">+123.7035555555</contact:voice>
|
<contact:voice x="1234">+123.7035555555</contact:voice>
|
||||||
<contact:fax>+1.7035555556</contact:fax>
|
<contact:fax>+1.7035555556</contact:fax>
|
||||||
<contact:email>jdoe@example.com</contact:email>
|
<contact:email>jdoe@example.com</contact:email>
|
||||||
<contact:ident>37605030299</contact:ident>
|
<contact:ident type="op">37605030299</contact:ident>
|
||||||
<contact:authInfo>
|
<contact:authInfo>
|
||||||
<contact:pw>2fooBAR</contact:pw>
|
<contact:pw>2fooBAR</contact:pw>
|
||||||
</contact:authInfo>
|
</contact:authInfo>
|
||||||
|
|
|
@ -4,4 +4,5 @@ Fabricator(:contact) do
|
||||||
email Faker::Internet.email
|
email Faker::Internet.email
|
||||||
ident '37605030299'
|
ident '37605030299'
|
||||||
code 'sh8913'
|
code 'sh8913'
|
||||||
|
ident_type 'op'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue