mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Hosts attribute for domain info
This commit is contained in:
parent
a3cb7aed41
commit
aa2b46241a
5 changed files with 85 additions and 6 deletions
|
@ -17,6 +17,17 @@ class Epp::DomainsController < EppController
|
|||
|
||||
def info
|
||||
authorize! :info, @domain, @password
|
||||
@hosts = params[:parsed_frame].css('name').first['hosts'] || 'all'
|
||||
|
||||
case @hosts
|
||||
when 'del'
|
||||
@nameservers = @domain.delegated_nameservers
|
||||
when 'sub'
|
||||
@nameservers = @domain.subordinate_nameservers
|
||||
when 'all'
|
||||
@nameservers = @domain.nameservers
|
||||
end
|
||||
|
||||
render_epp_response '/epp/domains/info'
|
||||
end
|
||||
|
||||
|
@ -88,6 +99,7 @@ class Epp::DomainsController < EppController
|
|||
def validate_info
|
||||
@prefix = 'info > info >'
|
||||
requires('name')
|
||||
optional_attribute 'name', 'hosts', values: %(all, sub, del, none)
|
||||
end
|
||||
|
||||
def validate_check
|
||||
|
|
|
@ -139,6 +139,20 @@ class EppController < ApplicationController
|
|||
}
|
||||
end
|
||||
|
||||
def optional_attribute(element_selector, attribute_selector, options)
|
||||
element = requires(element_selector, allow_blank: options[:allow_blank])
|
||||
return unless element
|
||||
|
||||
attribute = element[attribute_selector]
|
||||
|
||||
return if (attribute && options[:values].include?(attribute)) || !attribute
|
||||
|
||||
epp_errors << {
|
||||
code: '2306',
|
||||
msg: I18n.t('attribute_is_invalid', attribute: attribute_selector)
|
||||
}
|
||||
end
|
||||
|
||||
def exactly_one_of(*selectors)
|
||||
full_selectors = create_full_selectors(*selectors)
|
||||
return if element_count(*full_selectors, use_prefix: false) == 1
|
||||
|
|
|
@ -124,6 +124,14 @@ class Domain < ActiveRecord::Base
|
|||
domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN }
|
||||
end
|
||||
|
||||
def subordinate_nameservers
|
||||
nameservers.select { |x| x.hostname.end_with?(name) }
|
||||
end
|
||||
|
||||
def delegated_nameservers
|
||||
nameservers.select { |x| !x.hostname.end_with?(name) }
|
||||
end
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
value.downcase!
|
||||
|
|
|
@ -22,12 +22,14 @@ xml.epp_head do
|
|||
xml.tag!('domain:contact', x.code, 'type' => 'admin')
|
||||
end
|
||||
|
||||
xml.tag!('domain:ns') do
|
||||
@domain.nameservers.each do |x|
|
||||
xml.tag!('domain:hostAttr') do
|
||||
xml.tag!('domain:hostName', x.hostname)
|
||||
xml.tag!('domain:hostAddr', x.ipv4, 'ip' => 'v4') if x.ipv4.present?
|
||||
xml.tag!('domain:hostAddr', x.ipv6, 'ip' => 'v6') if x.ipv6.present?
|
||||
if @nameservers && @nameservers.any?
|
||||
xml.tag!('domain:ns') do
|
||||
@nameservers.each do |x|
|
||||
xml.tag!('domain:hostAttr') do
|
||||
xml.tag!('domain:hostName', x.hostname)
|
||||
xml.tag!('domain:hostAddr', x.ipv4, 'ip' => 'v4') if x.ipv4.present?
|
||||
xml.tag!('domain:hostAddr', x.ipv6, 'ip' => 'v6') if x.ipv6.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue