mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Attach nameservers with attributes
This commit is contained in:
parent
356835bebf
commit
d46640713b
6 changed files with 79 additions and 3 deletions
|
@ -53,7 +53,9 @@ module Epp::DomainsHelper
|
|||
def domain_nameservers
|
||||
ph = params_hash['epp']['command']['create']['create']['ns']
|
||||
return [] unless ph
|
||||
ph[:hostObj]
|
||||
return ph[:hostObj] if ph[:hostObj]
|
||||
return ph[:hostAttr] if ph[:hostAttr]
|
||||
[]
|
||||
end
|
||||
|
||||
def handle_errors
|
||||
|
|
|
@ -63,8 +63,20 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def attach_nameservers(ns_list)
|
||||
ns_list.each do |x|
|
||||
self.nameservers.build(hostname: x)
|
||||
ns_list.each do |ns|
|
||||
#ns with detailed attributes
|
||||
if ns.is_a?(Hash)
|
||||
attrs = {hostname: ns[:hostName]}
|
||||
|
||||
ns[:hostAddr].each do |ip|
|
||||
attrs[:ip] = ip unless attrs[:ip]
|
||||
end if ns[:hostAddr]
|
||||
|
||||
self.nameservers.build(attrs)
|
||||
#ns with just hostname
|
||||
else
|
||||
self.nameservers.build(hostname: ns)
|
||||
end
|
||||
end
|
||||
|
||||
save
|
||||
|
@ -76,6 +88,14 @@ class Domain < ActiveRecord::Base
|
|||
errors.empty?
|
||||
end
|
||||
|
||||
# def validate_nameservers
|
||||
# nameservers.each do |x|
|
||||
# x.errors.each do |err|
|
||||
# errors.add(:nameservers)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
def add_child_collection_errors(attr_key, epp_obj_name)
|
||||
send(attr_key).each do |obj|
|
||||
obj.errors.keys.each do |key|
|
||||
|
|
|
@ -3,4 +3,5 @@ class Nameserver < ActiveRecord::Base
|
|||
has_and_belongs_to_many :domains
|
||||
|
||||
validates :hostname, hostname: true
|
||||
validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true}
|
||||
end
|
||||
|
|
15
app/validators/nameserver_ip_validator.rb
Normal file
15
app/validators/nameserver_ip_validator.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
class NameserverIpValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if record.domain_
|
||||
|
||||
if !self.class.validate_format(value)
|
||||
record.errors.add(attribute, (options[:message] || :invalid))
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
!!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue