Merge pull request #1784 from internetee/1139-fix-whois-for-domain-release

Fix Whois record updating for domain release
This commit is contained in:
Timo Võhmar 2021-01-28 09:24:17 +02:00 committed by GitHub
commit 8826c8052f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 10 deletions

6
app/lib/to_stdout.rb Normal file
View file

@ -0,0 +1,6 @@
class ToStdout
def self.msg(message)
time = Time.zone.now.utc
STDOUT << "#{time} - #{message}\n" unless Rails.env.test?
end
end

View file

@ -39,13 +39,15 @@ module Concerns
def release
if release_to_auction
transaction do
domain_name.sell_at_auction if domain_name.auctionable?
destroy!
registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}",
attached_obj_id: id,
attached_obj_type: self.class)
end
ToStdout.msg 'Destroying domain'
destroy!
ToStdout.msg "Checking if domain_name is auctionable: #{domain_name.auctionable?}"
domain_name.sell_at_auction if domain_name.auctionable?
ToStdout.msg 'Sending registrar notification'
registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}",
attached_obj_id: id,
attached_obj_type: self.class)
else
discard
end

View file

@ -36,6 +36,7 @@ module DNS
auction = Auction.new
auction.domain = name
auction.start
ToStdout.msg "Created the auction: #{auction.inspect}"
update_whois_from_auction(auction)
end
@ -100,7 +101,8 @@ module DNS
whois_record = Whois::Record.find_or_create_by!(name: name) do |record|
record.json = {}
end
ToStdout.msg "Starting to update WHOIS record #{whois_record.inspect}\n\n"\
"from auction #{auction.inspect}"
whois_record.update_from_auction(auction)
end
end

View file

@ -78,7 +78,7 @@ class Domain < ApplicationRecord
true
end
after_commit :update_whois_record, unless: -> { domain_name.at_auction? }
after_commit :update_whois_record
after_create :update_reserved_domains
def update_reserved_domains

View file

@ -2,23 +2,34 @@ module Whois
class Record < Whois::Server
self.table_name = 'whois_records'
def self.without_auctions
ids = Whois::Record.all.select { |record| Auction.where(domain: record.name).blank? }
.pluck(:id)
Whois::Record.where(id: ids)
end
def self.disclaimer
Setting.registry_whois_disclaimer
end
# rubocop:disable Metrics/AbcSize
def update_from_auction(auction)
if auction.started?
update!(json: { name: auction.domain,
status: ['AtAuction'],
disclaimer: self.class.disclaimer })
ToStdout.msg "Updated from auction WHOIS record #{inspect}"
elsif auction.no_bids?
ToStdout.msg "Destroying WHOIS record #{inspect}"
destroy!
elsif auction.awaiting_payment? || auction.payment_received?
update!(json: { name: auction.domain,
status: ['PendingRegistration'],
disclaimer: self.class.disclaimer,
registration_deadline: auction.whois_deadline })
ToStdout.msg "Updated from auction WHOIS record #{inspect}"
end
end
# rubocop:enable Metrics/AbcSize
end
end

View file

@ -97,7 +97,7 @@ class WhoisRecord < ApplicationRecord
end
def destroy_whois_record
Whois::Record.where(name: name).delete_all
Whois::Record.without_auctions.where(name: name).delete_all
end
private