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,15 +1,16 @@
|
|||
module Epp::DomainsHelper
|
||||
def create_domain
|
||||
@domain = Domain.new(domain_create_params)
|
||||
@domain.create_contacts(domain_contacts)
|
||||
|
||||
if @domain.save
|
||||
Domain.transaction do
|
||||
if @domain.save && @domain.attach_contacts(domain_contacts)
|
||||
render '/epp/domains/create'
|
||||
else
|
||||
handle_domain_name_errors
|
||||
render '/epp/error'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_domain
|
||||
ph = params_hash['epp']['command']['check']['check']
|
||||
|
@ -37,11 +38,11 @@ module Epp::DomainsHelper
|
|||
|
||||
res = {tech: [], admin: []}
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
res
|
||||
|
|
|
@ -3,6 +3,8 @@ class Contact < ActiveRecord::Base
|
|||
#TODO Phone number validation, in first phase very minimam in order to support current registries
|
||||
|
||||
has_many :addresses
|
||||
has_many :domain_contacts
|
||||
has_many :domains, through: :domain_contacts
|
||||
|
||||
validates_presence_of :code, :name, :phone, :email, :ident
|
||||
|
||||
|
@ -16,6 +18,10 @@ class Contact < ActiveRecord::Base
|
|||
"birthday" #Birthday date
|
||||
]
|
||||
|
||||
CONTACT_TYPE_TECH = 'tech'
|
||||
CONTACT_TYPE_ADMIN = 'admin'
|
||||
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||
|
||||
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
|
||||
|
|
|
@ -5,8 +5,17 @@ class Domain < ActiveRecord::Base
|
|||
belongs_to :registrar
|
||||
belongs_to :ns_set
|
||||
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
|
||||
|
||||
|
@ -21,9 +30,19 @@ class Domain < ActiveRecord::Base
|
|||
write_attribute(:name_dirty, value)
|
||||
end
|
||||
|
||||
def create_contacts(contacts)
|
||||
def attach_contacts(contacts)
|
||||
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
|
||||
|
||||
|
|
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.
|
||||
|
||||
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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -47,6 +47,14 @@ ActiveRecord::Schema.define(version: 20140730104916) do
|
|||
t.datetime "updated_at"
|
||||
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|
|
||||
t.string "name"
|
||||
t.integer "registrar_id"
|
||||
|
|
|
@ -31,6 +31,19 @@ describe 'EPP Domain', epp: true do
|
|||
expect(response[:clTRID]).to eq('ABC-12345')
|
||||
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
|
||||
response = epp_request('domains/check.xml')
|
||||
expect(response[:result_code]).to eq('1000')
|
||||
|
|
|
@ -3,9 +3,9 @@ require "rails_helper"
|
|||
describe Domain do
|
||||
it { should belong_to(:registrar) }
|
||||
it { should belong_to(:ns_set) }
|
||||
it { should belong_to(:admin_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
|
||||
d = Fabricate(:domain)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue