mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
Merge branch 'master' of github.com:internetee/registry
This commit is contained in:
commit
38dc1c548b
45 changed files with 590 additions and 401 deletions
|
@ -17,18 +17,18 @@ class Address < ActiveRecord::Base
|
|||
# errors, used = [], []
|
||||
# parsed_frame.css('postalInfo').each do |pi|
|
||||
# attr = pi.attributes['type'].try(:value)
|
||||
# errors << {
|
||||
# code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')
|
||||
# errors << {
|
||||
# code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')
|
||||
# } and next unless attr
|
||||
# unless TYPES.include?(attr)
|
||||
# errors << {
|
||||
# code: 2005,
|
||||
# msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }
|
||||
# errors << {
|
||||
# code: 2005,
|
||||
# msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }
|
||||
# }
|
||||
# next
|
||||
# end
|
||||
# errors << {
|
||||
# code: 2005,
|
||||
# errors << {
|
||||
# code: 2005,
|
||||
# msg: I18n.t('errors.messages.repeating_postal_info')
|
||||
# } and next if used.include?(attr)
|
||||
# used << attr
|
||||
|
@ -54,11 +54,16 @@ class Address < ActiveRecord::Base
|
|||
return {} unless addr[:addr].is_a?(Hash)
|
||||
{ country_id: Country.find_by(iso: addr[:addr][:cc]).try(:id),
|
||||
city: addr[:addr][:city],
|
||||
street: addr[:addr][:street][0],
|
||||
street2: addr[:addr][:street][1],
|
||||
street3: addr[:addr][:street][2],
|
||||
street: pretty_street(addr[:addr][:street]), # [0],
|
||||
# street2: addr[:addr][:street][1],
|
||||
# street3: addr[:addr][:street][2],
|
||||
zip: addr[:addr][:pc]
|
||||
}.delete_if { |_k, v| v.nil? }
|
||||
end
|
||||
|
||||
def pretty_street(param_street)
|
||||
return param_street.join(',') if param_street.is_a?(Array)
|
||||
param_street
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
30
app/models/concerns/domain_version_observer.rb
Normal file
30
app/models/concerns/domain_version_observer.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module DomainVersionObserver
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_save :delayed_whois_update
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delayed_whois_update
|
||||
name = domain_name
|
||||
return unless name
|
||||
body = snapshot
|
||||
delay.update_whois(name, body)
|
||||
end
|
||||
|
||||
# not sure we need to pass in the params since i don't know if delayed job has access to
|
||||
# all the regular attributes and stuff
|
||||
def update_whois(domain_name, body)
|
||||
wd = WhoisDomain.find_or_initialize_by(name: domain_name)
|
||||
wd.body = body
|
||||
wd.save!
|
||||
end
|
||||
|
||||
def domain_name
|
||||
name = reify.try(:name)
|
||||
name = load_snapshot[:domain][:name] if event == 'create'
|
||||
return name if name
|
||||
end
|
||||
end
|
|
@ -18,10 +18,9 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :address, :disclosure
|
||||
|
||||
validates :code, :phone, :email, :ident, :address, :registrar, presence: true
|
||||
validates :phone, :email, :ident, :address, :registrar, presence: true
|
||||
|
||||
validate :ident_must_be_valid
|
||||
# validate :presence_of_one_address
|
||||
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/
|
||||
validates :email, format: /@/
|
||||
|
@ -37,6 +36,8 @@ class Contact < ActiveRecord::Base
|
|||
# after_commit :domains_snapshot
|
||||
after_update :domains_snapshot
|
||||
after_destroy :domains_snapshot
|
||||
before_create :generate_code
|
||||
before_create :generate_auth_info
|
||||
|
||||
# scopes
|
||||
scope :current_registrars, ->(id) { where(registrar_id: id) }
|
||||
|
@ -96,6 +97,10 @@ class Contact < ActiveRecord::Base
|
|||
self.code = SecureRandom.hex(4)
|
||||
end
|
||||
|
||||
def generate_auth_info
|
||||
self.auth_info = SecureRandom.hex(16)
|
||||
end
|
||||
|
||||
# Find a way to use self.domains with contact
|
||||
def domains_owned
|
||||
Domain.where(owner_contact_id: id)
|
||||
|
@ -149,16 +154,17 @@ class Contact < ActiveRecord::Base
|
|||
# non-EPP
|
||||
|
||||
# EPP
|
||||
def extract_attributes(ph, type = :create)
|
||||
def extract_attributes(ph, _type = :create)
|
||||
ph[:postalInfo] = ph[:postalInfo].first if ph[:postalInfo].is_a?(Array)
|
||||
contact_hash = {
|
||||
phone: ph[:voice],
|
||||
ident: ph[:ident],
|
||||
email: ph[:email],
|
||||
fax: ph[:fax],
|
||||
name: ph[:postalInfo].try(:[], :name),
|
||||
org_name: ph[:postalInfo].try(:[], :org)
|
||||
}
|
||||
contact_hash[:auth_info] = ph[:authInfo][:pw] if type == :create
|
||||
# contact_hash[:auth_info] = ph[:authInfo][:pw] if type == :create
|
||||
contact_hash.delete_if { |_k, v| v.nil? }
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class DomainVersion < PaperTrail::Version
|
||||
include UserEvents
|
||||
include DomainVersionObserver if Setting.whois_enabled # unless Setting.whois_enabled
|
||||
|
||||
scope :deleted, -> { where(event: 'destroy') }
|
||||
|
||||
|
@ -7,6 +8,29 @@ class DomainVersion < PaperTrail::Version
|
|||
self.sequence_name = :domain_version_id_seq
|
||||
|
||||
def load_snapshot
|
||||
YAML.load(snapshot)
|
||||
snapshot ? YAML.load(snapshot) : {}
|
||||
end
|
||||
|
||||
def previous?
|
||||
return true if previous
|
||||
false
|
||||
end
|
||||
|
||||
def name
|
||||
name = reify.try(:name)
|
||||
name = load_snapshot[:domain].try(:[], :name) unless name
|
||||
name
|
||||
end
|
||||
|
||||
def changed_elements
|
||||
return [] unless previous?
|
||||
@changes = []
|
||||
@previous_snap = previous.load_snapshot
|
||||
@snap = load_snapshot
|
||||
[:owner_contact, :tech_contacts, :admin_contacts, :nameservers, :domain].each do |key|
|
||||
@changes << key unless @snap[key] == @previous_snap[key]
|
||||
end
|
||||
|
||||
@changes
|
||||
end
|
||||
end
|
||||
|
|
3
app/models/whois_domain.rb
Normal file
3
app/models/whois_domain.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class WhoisDomain < WhoisServer
|
||||
self.table_name = 'domains'
|
||||
end
|
4
app/models/whois_server.rb
Normal file
4
app/models/whois_server.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class WhoisServer < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
establish_connection :"#{Rails.env}_whois"
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue