mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 01:35:10 +02:00
parent
eeb4849c1e
commit
91fab05bfb
9 changed files with 136 additions and 20 deletions
|
@ -1,16 +1,13 @@
|
|||
module DNS
|
||||
class Zone < ActiveRecord::Base
|
||||
self.auto_html5_validation = false
|
||||
|
||||
validates :origin, :ttl, :refresh, :retry, :expire, :minimum_ttl, :email, :master_nameserver, presence: true
|
||||
validates :ttl, :refresh, :retry, :expire, :minimum_ttl, numericality: { only_integer: true }
|
||||
validates :origin, uniqueness: true
|
||||
|
||||
before_destroy :check_for_dependencies
|
||||
|
||||
def check_for_dependencies
|
||||
dc = Domain.where("name ILIKE ?", "%.#{origin}").count
|
||||
return if dc == 0
|
||||
errors.add(:base, I18n.t('there_are_count_domains_in_this_zone', count: dc))
|
||||
false
|
||||
before_destroy do
|
||||
!used?
|
||||
end
|
||||
|
||||
def self.generate_zonefiles
|
||||
|
@ -37,6 +34,10 @@ module DNS
|
|||
pluck(:origin)
|
||||
end
|
||||
|
||||
def used?
|
||||
Domain.uses_zone?(self)
|
||||
end
|
||||
|
||||
def to_s
|
||||
origin
|
||||
end
|
||||
|
|
|
@ -724,5 +724,9 @@ class Domain < ActiveRecord::Base
|
|||
def self.delete_candidates
|
||||
where("#{attribute_alias(:delete_time)} < ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def self.uses_zone?(zone)
|
||||
exists?(["name ILIKE ?", "%.#{zone.origin}"])
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/ClassLength
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue