mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Added pure PaperTrail stack
This commit is contained in:
parent
ea6bdc19f9
commit
09a816d5a8
27 changed files with 846 additions and 492 deletions
|
@ -1,4 +1,5 @@
|
|||
class Domain < ActiveRecord::Base
|
||||
include Versions # version/domain_version.rb
|
||||
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
|
||||
# TODO: most inputs should be trimmed before validatation, probably some global logic?
|
||||
paginates_per 10 # just for showoff
|
||||
|
@ -17,7 +18,9 @@ class Domain < ActiveRecord::Base
|
|||
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
||||
through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add
|
||||
# TODO: remove old
|
||||
# has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add
|
||||
has_many :nameservers, dependent: :delete_all
|
||||
|
||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||
reject_if: proc { |attrs| attrs[:hostname].blank? }
|
||||
|
@ -102,9 +105,10 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
attr_accessor :owner_contact_typeahead, :update_me
|
||||
|
||||
# TODO: remove old
|
||||
# archiving
|
||||
# if proc works only on changes on domain sadly
|
||||
has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version)
|
||||
# has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version)
|
||||
|
||||
def tech_domain_contacts
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }
|
||||
|
@ -114,46 +118,51 @@ class Domain < ActiveRecord::Base
|
|||
domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN }
|
||||
end
|
||||
|
||||
def new_version
|
||||
return false if versions.try(:last).try(:snapshot) == create_snapshot
|
||||
true
|
||||
end
|
||||
# TODO: remove old
|
||||
# def new_version
|
||||
# return false if versions.try(:last).try(:snapshot) == create_snapshot
|
||||
# true
|
||||
# end
|
||||
|
||||
def create_version
|
||||
return true unless PaperTrail.enabled?
|
||||
return true unless valid?
|
||||
touch_with_version if new_version
|
||||
end
|
||||
# TODO: remove old
|
||||
# def create_version
|
||||
# return true unless PaperTrail.enabled?
|
||||
# return true unless valid?
|
||||
# touch_with_version if new_version
|
||||
# end
|
||||
|
||||
def track_nameserver_add(_nameserver)
|
||||
return true if versions.count == 0
|
||||
return true unless valid? && new_version
|
||||
# TODO: remove old
|
||||
# def track_nameserver_add(_nameserver)
|
||||
# return true if versions.count == 0
|
||||
# return true unless valid? && new_version
|
||||
|
||||
touch_with_version
|
||||
end
|
||||
# touch_with_version
|
||||
# end
|
||||
|
||||
def create_snapshot
|
||||
oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
|
||||
{
|
||||
owner_contact: oc,
|
||||
tech_contacts: tech_contacts.map(&:snapshot),
|
||||
admin_contacts: admin_contacts.map(&:snapshot),
|
||||
nameservers: nameservers.map(&:snapshot),
|
||||
domain: make_snapshot
|
||||
}.to_yaml
|
||||
end
|
||||
# TODO: remove old
|
||||
# def create_snapshot
|
||||
# oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
|
||||
# {
|
||||
# owner_contact: oc,
|
||||
# tech_contacts: tech_contacts.map(&:snapshot),
|
||||
# admin_contacts: admin_contacts.map(&:snapshot),
|
||||
# nameservers: nameservers.map(&:snapshot),
|
||||
# domain: make_snapshot
|
||||
# }.to_yaml
|
||||
# end
|
||||
|
||||
def make_snapshot
|
||||
{
|
||||
name: name,
|
||||
status: status,
|
||||
period: period,
|
||||
period_unit: period_unit,
|
||||
registrar_id: registrar.try(:id),
|
||||
valid_to: valid_to,
|
||||
valid_from: valid_from
|
||||
}
|
||||
end
|
||||
# TODO: remove old
|
||||
# def make_snapshot
|
||||
# {
|
||||
# name: name,
|
||||
# status: status,
|
||||
# period: period,
|
||||
# period_unit: period_unit,
|
||||
# registrar_id: registrar.try(:id),
|
||||
# valid_to: valid_to,
|
||||
# valid_from: valid_from
|
||||
# }
|
||||
# end
|
||||
|
||||
def name=(value)
|
||||
value.strip!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue