Attach nameservers to domain

This commit is contained in:
Martin Lensment 2014-08-01 17:52:35 +03:00
parent f6ce3b4c4e
commit d01944fe21
5 changed files with 22 additions and 3 deletions

View file

@ -3,7 +3,7 @@ module Epp::DomainsHelper
@domain = Domain.new(domain_create_params) @domain = Domain.new(domain_create_params)
Domain.transaction do Domain.transaction do
if @domain.save && @domain.attach_contacts(domain_contacts) if @domain.save && @domain.attach_contacts(domain_contacts) && @domain.attach_nameservers(domain_nameservers)
render '/epp/domains/create' render '/epp/domains/create'
else else
handle_errors handle_errors
@ -50,6 +50,11 @@ module Epp::DomainsHelper
res res
end end
def domain_nameservers
ph = params_hash['epp']['command']['create']['create']['ns']
ph[:hostObj]
end
def handle_errors def handle_errors
super({ super({
'2302' => [:epp_domain_taken, :epp_domain_reserved], '2302' => [:epp_domain_taken, :epp_domain_reserved],

View file

@ -61,6 +61,13 @@ class Domain < ActiveRecord::Base
) )
end end
def attach_nameservers(nameservers)
nameservers.each do |x|
self.nameservers << Nameserver.find_or_create_by(hostname: x)
end
save!
end
def validate_admin_contacts_count def validate_admin_contacts_count
errors.add(:admin_contacts, :blank) if admin_contacts.empty? errors.add(:admin_contacts, :blank) if admin_contacts.empty?
end end

View file

@ -0,0 +1,5 @@
class RenameNameserverName < ActiveRecord::Migration
def change
rename_column :nameservers, :name, :hostname
end
end

View file

@ -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: 20140731081816) do ActiveRecord::Schema.define(version: 20140801140249) 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"
@ -102,7 +102,7 @@ ActiveRecord::Schema.define(version: 20140731081816) do
end end
create_table "nameservers", force: true do |t| create_table "nameservers", force: true do |t|
t.string "name" t.string "hostname"
t.string "ip" t.string "ip"
t.integer "ns_set_id" t.integer "ns_set_id"
t.datetime "created_at" t.datetime "created_at"

View file

@ -41,6 +41,8 @@ describe 'EPP Domain', epp: true do
expect(Domain.first.registrar.name).to eq('Zone Media OÜ') expect(Domain.first.registrar.name).to eq('Zone Media OÜ')
expect(Domain.first.tech_contacts.count).to eq 2 expect(Domain.first.tech_contacts.count).to eq 2
expect(Domain.first.admin_contacts.count).to eq 1 expect(Domain.first.admin_contacts.count).to eq 1
expect(Domain.first.nameservers.count).to eq(2)
end end
it 'does not create duplicate domain' do it 'does not create duplicate domain' do