Nameservers refactor

This commit is contained in:
Martin Lensment 2014-08-26 13:35:26 +03:00
parent 57e8bf81e3
commit 1e13c54eb9
9 changed files with 182 additions and 140 deletions

View file

@ -23,7 +23,8 @@ class Domain < ActiveRecord::Base
where(domain_contacts: { contact_type: DomainContact::ADMIN })
end, through: :domain_contacts, source: :contact
has_and_belongs_to_many :nameservers
has_many :domain_nameservers
has_many :nameservers, through: :domain_nameservers
has_many :domain_statuses, -> {
joins(:setting).where(settings: { setting_group_id: SettingGroup.domain_statuses.id })
@ -121,7 +122,18 @@ 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?
errors.add(:nameservers, {
code: '2302',
obj: 'hostObj',
val: ns_attrs[:hostname],
msg: errors.generate_message(:nameservers, :taken)
})
end
end