mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Whois body updated later with delayed job
This commit is contained in:
parent
ff709e8d7b
commit
7ff09c75e3
2 changed files with 24 additions and 23 deletions
|
@ -51,13 +51,8 @@ class Domain < ActiveRecord::Base
|
||||||
def touch_always_version
|
def touch_always_version
|
||||||
self.updated_at = Time.now
|
self.updated_at = Time.now
|
||||||
end
|
end
|
||||||
before_save :update_whois_body
|
|
||||||
after_save :delay_whois_server_update
|
|
||||||
def delay_whois_server_update
|
|
||||||
return if whois_body.blank?
|
|
||||||
delay.whois_server_update(name, whois_body)
|
|
||||||
end
|
|
||||||
after_save :manage_automatic_statuses
|
after_save :manage_automatic_statuses
|
||||||
|
after_save :update_whois_body
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
validates :name_dirty, domain_name: true, uniqueness: true
|
||||||
validates :period, numericality: { only_integer: true }
|
validates :period, numericality: { only_integer: true }
|
||||||
|
@ -117,6 +112,14 @@ class Domain < ActiveRecord::Base
|
||||||
nameservers.select { |x| !x.hostname.end_with?(name) }
|
nameservers.select { |x| !x.hostname.end_with?(name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def convert_period_to_time(period, unit)
|
||||||
|
return period.to_i.days if unit == 'd'
|
||||||
|
return period.to_i.months if unit == 'm'
|
||||||
|
return period.to_i.years if unit == 'y'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def name=(value)
|
def name=(value)
|
||||||
value.strip!
|
value.strip!
|
||||||
value.downcase!
|
value.downcase!
|
||||||
|
@ -225,9 +228,15 @@ class Domain < ActiveRecord::Base
|
||||||
log
|
log
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_whois_server
|
||||||
|
wd = Whois::Domain.find_or_initialize_by(name: name)
|
||||||
|
wd.whois_body = whois_body
|
||||||
|
wd.save
|
||||||
|
end
|
||||||
|
|
||||||
# rubocop:disable Metrics/MethodLength
|
# rubocop:disable Metrics/MethodLength
|
||||||
def update_whois_body
|
def update_whois_body
|
||||||
self.whois_body = <<-EOS
|
new_whois_body = <<-EOS
|
||||||
This Whois Server contains information on
|
This Whois Server contains information on
|
||||||
Estonian Top Level Domain ee TLD
|
Estonian Top Level Domain ee TLD
|
||||||
|
|
||||||
|
@ -251,7 +260,13 @@ class Domain < ActiveRecord::Base
|
||||||
created: #{registrar.created_at.to_s(:db)}
|
created: #{registrar.created_at.to_s(:db)}
|
||||||
changed: #{registrar.updated_at.to_s(:db)}
|
changed: #{registrar.updated_at.to_s(:db)}
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
|
if whois_body != new_whois_body
|
||||||
|
update_column(whois_body: new_whois_body)
|
||||||
|
update_whois_server
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
handle_asynchronously :update_whois_body
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
def contacts_body
|
def contacts_body
|
||||||
|
@ -273,18 +288,4 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|
||||||
def whois_server_update(name, whois_body)
|
|
||||||
wd = Whois::Domain.find_or_initialize_by(name: name)
|
|
||||||
wd.whois_body = whois_body
|
|
||||||
wd.save
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
|
||||||
def convert_period_to_time(period, unit)
|
|
||||||
return period.to_i.days if unit == 'd'
|
|
||||||
return period.to_i.months if unit == 'm'
|
|
||||||
return period.to_i.years if unit == 'y'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,8 +74,8 @@ describe Domain do
|
||||||
domain.errors.full_messages.should match_array(["Admin domain contacts is invalid"])
|
domain.errors.full_messages.should match_array(["Admin domain contacts is invalid"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have whois_body' do
|
it 'should not have whois_body present by default' do
|
||||||
@domain.whois_body.present?.should == true
|
@domain.whois_body.present?.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with versioning' do
|
context 'with versioning' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue