mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
nameserver change tracking
This commit is contained in:
parent
ed34483bc2
commit
6b783fd45e
8 changed files with 44 additions and 26 deletions
|
@ -66,6 +66,7 @@ class Contact < ActiveRecord::Base
|
|||
def domains_snapshot
|
||||
(domains + domains_owned).uniq.each do |domain|
|
||||
next unless domain.is_a?(Domain)
|
||||
next if domain.versions.last == domain.create_snapshot
|
||||
domain.touch_with_version # Method from paper_trail
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,8 @@ class Domain < ActiveRecord::Base
|
|||
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
||||
through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :nameservers, dependent: :delete_all
|
||||
has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add
|
||||
|
||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||
reject_if: proc { |attrs| attrs[:hostname].blank? }
|
||||
|
||||
|
@ -62,6 +63,11 @@ class Domain < ActiveRecord::Base
|
|||
# archiving
|
||||
has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }
|
||||
|
||||
def track_nameserver_add(nameserver)
|
||||
# if we are not adding nameservers on create ( we don't care about ms so to_i )
|
||||
touch_with_version if nameserver.created_at.to_i != created_at.to_i && valid?
|
||||
end
|
||||
|
||||
def create_snapshot
|
||||
oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
|
||||
{
|
||||
|
|
|
@ -41,6 +41,9 @@ class DomainContact < ActiveRecord::Base
|
|||
def domain_snapshot
|
||||
# We don't create a version unless domain is valid, is that a good idea?
|
||||
return true unless PaperTrail.enabled?
|
||||
return true if domain.nil?
|
||||
return true if contact.nil?
|
||||
return true if domain.versions.last.try(:snapshot) == domain.try(:create_snapshot)
|
||||
domain.touch_with_version if domain.valid?
|
||||
true
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ class Nameserver < ActiveRecord::Base
|
|||
|
||||
# archiving
|
||||
has_paper_trail class_name: 'NameserverVersion'
|
||||
after_destroy :domain_version
|
||||
|
||||
before_validation :normalize_attributes
|
||||
|
||||
|
@ -45,6 +46,10 @@ class Nameserver < ActiveRecord::Base
|
|||
self.ipv6 = ipv6.try(:strip).try(:upcase)
|
||||
end
|
||||
|
||||
def domain_version
|
||||
domain.touch_with_version if domain.valid?
|
||||
end
|
||||
|
||||
def to_s
|
||||
hostname
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue