mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Domain has many admin and technical contacts now
This commit is contained in:
parent
22baafab6d
commit
8bff2fb34c
8 changed files with 82 additions and 20 deletions
|
@ -1,13 +1,14 @@
|
||||||
module Epp::DomainsHelper
|
module Epp::DomainsHelper
|
||||||
def create_domain
|
def create_domain
|
||||||
@domain = Domain.new(domain_create_params)
|
@domain = Domain.new(domain_create_params)
|
||||||
@domain.create_contacts(domain_contacts)
|
|
||||||
|
|
||||||
if @domain.save
|
Domain.transaction do
|
||||||
render '/epp/domains/create'
|
if @domain.save && @domain.attach_contacts(domain_contacts)
|
||||||
else
|
render '/epp/domains/create'
|
||||||
handle_domain_name_errors
|
else
|
||||||
render '/epp/error'
|
handle_domain_name_errors
|
||||||
|
render '/epp/error'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,11 +38,11 @@ module Epp::DomainsHelper
|
||||||
|
|
||||||
res = {tech: [], admin: []}
|
res = {tech: [], admin: []}
|
||||||
parsed_frame.css('contact[type="tech"]').each do |x|
|
parsed_frame.css('contact[type="tech"]').each do |x|
|
||||||
res[:tech] << Hash.from_xml(x.to_s)
|
res[:tech] << Hash.from_xml(x.to_s).with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
parsed_frame.css('contact[type="admin"]').each do |x|
|
parsed_frame.css('contact[type="admin"]').each do |x|
|
||||||
res[:admin] << Hash.from_xml(x.to_s)
|
res[:admin] << Hash.from_xml(x.to_s).with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
|
@ -1,23 +1,29 @@
|
||||||
class Contact < ActiveRecord::Base
|
class Contact < ActiveRecord::Base
|
||||||
#TODO Foreign contact will get email with activation link/username/temp password
|
#TODO Foreign contact will get email with activation link/username/temp password
|
||||||
#TODO Phone number validation, in first phase very minimam in order to support current registries
|
#TODO Phone number validation, in first phase very minimam in order to support current registries
|
||||||
|
|
||||||
has_many :addresses
|
has_many :addresses
|
||||||
|
has_many :domain_contacts
|
||||||
|
has_many :domains, through: :domain_contacts
|
||||||
|
|
||||||
validates_presence_of :code, :name, :phone, :email, :ident
|
validates_presence_of :code, :name, :phone, :email, :ident
|
||||||
|
|
||||||
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 = [
|
IDENT_TYPES = [
|
||||||
"ico", #Company registry code (or similar)
|
"ico", #Company registry code (or similar)
|
||||||
"op", #Estonian ID
|
"op", #Estonian ID
|
||||||
"passport", #Passport number
|
"passport", #Passport number
|
||||||
"birthday" #Birthday date
|
"birthday" #Birthday date
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CONTACT_TYPE_TECH = 'tech'
|
||||||
|
CONTACT_TYPE_ADMIN = 'admin'
|
||||||
|
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||||
|
|
||||||
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? && ident_type.present? && ident_type == "op"
|
return true unless ident.present? && ident_type.present? && ident_type == "op"
|
||||||
code = Isikukood.new(ident)
|
code = Isikukood.new(ident)
|
||||||
|
@ -31,7 +37,7 @@ class Contact < ActiveRecord::Base
|
||||||
res = []
|
res = []
|
||||||
codes.each do |x|
|
codes.each do |x|
|
||||||
if Contact.find_by(code: x)
|
if Contact.find_by(code: x)
|
||||||
res << {code: x, avail: 0, reason: 'in use'}
|
res << {code: x, avail: 0, reason: 'in use'}
|
||||||
else
|
else
|
||||||
res << {code: x, avail: 1}
|
res << {code: x, avail: 1}
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,8 +5,17 @@ class Domain < ActiveRecord::Base
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
belongs_to :ns_set
|
belongs_to :ns_set
|
||||||
belongs_to :owner_contact, class_name: 'Contact'
|
belongs_to :owner_contact, class_name: 'Contact'
|
||||||
belongs_to :technical_contact, class_name: 'Contact'
|
|
||||||
belongs_to :admin_contact, class_name: 'Contact'
|
has_many :domain_contacts
|
||||||
|
|
||||||
|
has_many :tech_contacts, -> {
|
||||||
|
where(domain_contacts: {contact_type: Contact::CONTACT_TYPE_TECH})
|
||||||
|
}, through: :domain_contacts, source: :contact
|
||||||
|
|
||||||
|
has_many :admin_contacts, -> {
|
||||||
|
where(domain_contacts: {contact_type: Contact::CONTACT_TYPE_ADMIN})
|
||||||
|
}, through: :domain_contacts, source: :contact
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
|
|
||||||
|
@ -21,9 +30,19 @@ class Domain < ActiveRecord::Base
|
||||||
write_attribute(:name_dirty, value)
|
write_attribute(:name_dirty, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_contacts(contacts)
|
def attach_contacts(contacts)
|
||||||
contacts[:tech].each do |x|
|
contacts[:tech].each do |x|
|
||||||
|
domain_contacts.create(
|
||||||
|
contact: Contact.find_by(code: x[:contact]),
|
||||||
|
contact_type: Contact::CONTACT_TYPE_TECH
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
contacts[:admin].each do |x|
|
||||||
|
domain_contacts.create(
|
||||||
|
contact: Contact.find_by(code: x[:contact]),
|
||||||
|
contact_type: Contact::CONTACT_TYPE_ADMIN
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
4
app/models/domain_contact.rb
Normal file
4
app/models/domain_contact.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class DomainContact < ActiveRecord::Base
|
||||||
|
belongs_to :contact
|
||||||
|
belongs_to :domain
|
||||||
|
end
|
11
db/migrate/20140730141443_add_contacts_to_domain.rb
Normal file
11
db/migrate/20140730141443_add_contacts_to_domain.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class AddContactsToDomain < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :domain_contacts do |t|
|
||||||
|
t.integer :contact_id
|
||||||
|
t.integer :domain_id
|
||||||
|
t.string :contact_type
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -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: 20140730104916) do
|
ActiveRecord::Schema.define(version: 20140730141443) 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"
|
||||||
|
@ -47,6 +47,14 @@ ActiveRecord::Schema.define(version: 20140730104916) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "domain_contacts", force: true do |t|
|
||||||
|
t.integer "contact_id"
|
||||||
|
t.integer "domain_id"
|
||||||
|
t.string "contact_type"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "domains", force: true do |t|
|
create_table "domains", force: true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
|
|
|
@ -31,6 +31,19 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:clTRID]).to eq('ABC-12345')
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates a domain with contacts' do
|
||||||
|
Fabricate(:contact, code: 'sh8013')
|
||||||
|
Fabricate(:contact, code: 'sh801333')
|
||||||
|
|
||||||
|
response = epp_request('domains/create.xml')
|
||||||
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
expect(response[:msg]).to eq('Command completed successfully')
|
||||||
|
expect(response[:clTRID]).to eq('ABC-12345')
|
||||||
|
|
||||||
|
expect(Domain.first.tech_contacts.count).to eq 2
|
||||||
|
expect(Domain.first.admin_contacts.count).to eq 1
|
||||||
|
end
|
||||||
|
|
||||||
it 'checks a domain' do
|
it 'checks a domain' do
|
||||||
response = epp_request('domains/check.xml')
|
response = epp_request('domains/check.xml')
|
||||||
expect(response[:result_code]).to eq('1000')
|
expect(response[:result_code]).to eq('1000')
|
||||||
|
|
|
@ -3,9 +3,9 @@ require "rails_helper"
|
||||||
describe Domain do
|
describe Domain do
|
||||||
it { should belong_to(:registrar) }
|
it { should belong_to(:registrar) }
|
||||||
it { should belong_to(:ns_set) }
|
it { should belong_to(:ns_set) }
|
||||||
it { should belong_to(:admin_contact) }
|
|
||||||
it { should belong_to(:owner_contact) }
|
it { should belong_to(:owner_contact) }
|
||||||
it { should belong_to(:technical_contact) }
|
it { should have_many(:tech_contacts) }
|
||||||
|
it { should have_many(:admin_contacts) }
|
||||||
|
|
||||||
it 'validates domain name' do
|
it 'validates domain name' do
|
||||||
d = Fabricate(:domain)
|
d = Fabricate(:domain)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue