mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 07:52:04 +02:00
Move ns and status validation to separate methods
This commit is contained in:
parent
df5da8dc4b
commit
7b88e6e028
2 changed files with 36 additions and 13 deletions
|
@ -4,7 +4,12 @@ module Epp::DomainsHelper
|
|||
@domain = Domain.new(domain_create_params)
|
||||
|
||||
@domain.attach_owner_contact(@ph[:registrant]) if @ph[:registrant]
|
||||
@domain.save
|
||||
|
||||
unless @domain.save
|
||||
handle_errors(@domain)
|
||||
raise ActiveRecord::Rollback and return
|
||||
end
|
||||
|
||||
@domain.parse_and_attach_domain_dependencies(parsed_frame)
|
||||
@domain.all_dependencies_valid?
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ class Domain < ActiveRecord::Base
|
|||
validates :owner_contact, presence: true
|
||||
|
||||
validate :validate_period
|
||||
validate :validate_nameservers_uniqueness
|
||||
validate :validate_statuses_uniqueness
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
|
@ -117,24 +119,12 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def attach_nameservers(ns_list)
|
||||
ns_list.each do |ns_attrs|
|
||||
existing = nameservers.select { |x| x.hostname == ns_attrs[:hostname] }
|
||||
|
||||
nameservers.build(ns_attrs)
|
||||
|
||||
next if existing.empty?
|
||||
add_epp_error('2302', 'hostObj', ns_attrs[:hostname], [:nameservers, :taken])
|
||||
end
|
||||
end
|
||||
|
||||
def attach_statuses(status_list)
|
||||
status_list.each do |x|
|
||||
existing = domain_statuses.select { |o| o.value == x[:value] }
|
||||
|
||||
if existing.any?
|
||||
add_epp_error('2302', 'status', x[:value], [:domain_statuses, :taken])
|
||||
next
|
||||
end
|
||||
|
||||
unless DomainStatus::STATUSES.include?(x[:value])
|
||||
add_epp_error('2303', 'status', x[:value], [:domain_statuses, :not_found])
|
||||
next
|
||||
|
@ -275,6 +265,34 @@ class Domain < ActiveRecord::Base
|
|||
errors.add(:nameservers, :out_of_range, { min: min, max: max })
|
||||
end
|
||||
|
||||
def validate_statuses_uniqueness
|
||||
validated = []
|
||||
domain_statuses.each do |status|
|
||||
next if validated.include?(status.value)
|
||||
|
||||
existing = domain_statuses.select { |x| x.value == status.value }
|
||||
if existing.length > 1
|
||||
validated << status.value
|
||||
errors.add(:domain_statuses, :taken)
|
||||
add_epp_error('2302', 'status', status.value, [:domain_statuses, :taken])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def validate_nameservers_uniqueness
|
||||
validated = []
|
||||
nameservers.each do |ns|
|
||||
next if validated.include?(ns.hostname)
|
||||
|
||||
existing = nameservers.select { |x| x.hostname == ns.hostname }
|
||||
if existing.length > 1
|
||||
validated << ns.hostname
|
||||
errors.add(:nameservers, :taken)
|
||||
add_epp_error('2302', 'hostObj', ns.hostname, [:nameservers, :taken])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def validate_admin_contacts_count
|
||||
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue