mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 05:05:45 +02:00
Merge pull request #1784 from internetee/1139-fix-whois-for-domain-release
Fix Whois record updating for domain release
This commit is contained in:
commit
8826c8052f
8 changed files with 53 additions and 10 deletions
6
app/lib/to_stdout.rb
Normal file
6
app/lib/to_stdout.rb
Normal 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
|
|
@ -39,13 +39,15 @@ module Concerns
|
||||||
|
|
||||||
def release
|
def release
|
||||||
if release_to_auction
|
if release_to_auction
|
||||||
transaction do
|
ToStdout.msg 'Destroying domain'
|
||||||
domain_name.sell_at_auction if domain_name.auctionable?
|
destroy!
|
||||||
destroy!
|
ToStdout.msg "Checking if domain_name is auctionable: #{domain_name.auctionable?}"
|
||||||
registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}",
|
domain_name.sell_at_auction if domain_name.auctionable?
|
||||||
attached_obj_id: id,
|
|
||||||
attached_obj_type: self.class)
|
ToStdout.msg 'Sending registrar notification'
|
||||||
end
|
registrar.notifications.create!(text: "#{I18n.t(:domain_deleted)}: #{name}",
|
||||||
|
attached_obj_id: id,
|
||||||
|
attached_obj_type: self.class)
|
||||||
else
|
else
|
||||||
discard
|
discard
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ module DNS
|
||||||
auction = Auction.new
|
auction = Auction.new
|
||||||
auction.domain = name
|
auction.domain = name
|
||||||
auction.start
|
auction.start
|
||||||
|
ToStdout.msg "Created the auction: #{auction.inspect}"
|
||||||
update_whois_from_auction(auction)
|
update_whois_from_auction(auction)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,7 +101,8 @@ module DNS
|
||||||
whois_record = Whois::Record.find_or_create_by!(name: name) do |record|
|
whois_record = Whois::Record.find_or_create_by!(name: name) do |record|
|
||||||
record.json = {}
|
record.json = {}
|
||||||
end
|
end
|
||||||
|
ToStdout.msg "Starting to update WHOIS record #{whois_record.inspect}\n\n"\
|
||||||
|
"from auction #{auction.inspect}"
|
||||||
whois_record.update_from_auction(auction)
|
whois_record.update_from_auction(auction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Domain < ApplicationRecord
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
after_commit :update_whois_record, unless: -> { domain_name.at_auction? }
|
after_commit :update_whois_record
|
||||||
|
|
||||||
after_create :update_reserved_domains
|
after_create :update_reserved_domains
|
||||||
def update_reserved_domains
|
def update_reserved_domains
|
||||||
|
|
|
@ -2,23 +2,34 @@ module Whois
|
||||||
class Record < Whois::Server
|
class Record < Whois::Server
|
||||||
self.table_name = 'whois_records'
|
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
|
def self.disclaimer
|
||||||
Setting.registry_whois_disclaimer
|
Setting.registry_whois_disclaimer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def update_from_auction(auction)
|
def update_from_auction(auction)
|
||||||
if auction.started?
|
if auction.started?
|
||||||
update!(json: { name: auction.domain,
|
update!(json: { name: auction.domain,
|
||||||
status: ['AtAuction'],
|
status: ['AtAuction'],
|
||||||
disclaimer: self.class.disclaimer })
|
disclaimer: self.class.disclaimer })
|
||||||
|
ToStdout.msg "Updated from auction WHOIS record #{inspect}"
|
||||||
elsif auction.no_bids?
|
elsif auction.no_bids?
|
||||||
|
ToStdout.msg "Destroying WHOIS record #{inspect}"
|
||||||
destroy!
|
destroy!
|
||||||
elsif auction.awaiting_payment? || auction.payment_received?
|
elsif auction.awaiting_payment? || auction.payment_received?
|
||||||
update!(json: { name: auction.domain,
|
update!(json: { name: auction.domain,
|
||||||
status: ['PendingRegistration'],
|
status: ['PendingRegistration'],
|
||||||
disclaimer: self.class.disclaimer,
|
disclaimer: self.class.disclaimer,
|
||||||
registration_deadline: auction.whois_deadline })
|
registration_deadline: auction.whois_deadline })
|
||||||
|
ToStdout.msg "Updated from auction WHOIS record #{inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,7 +97,7 @@ class WhoisRecord < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_whois_record
|
def destroy_whois_record
|
||||||
Whois::Record.where(name: name).delete_all
|
Whois::Record.without_auctions.where(name: name).delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -36,8 +36,10 @@ module DomainNameRegistry
|
||||||
|
|
||||||
# Autoload all model subdirs
|
# Autoload all model subdirs
|
||||||
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
|
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
|
||||||
|
config.autoload_paths += Dir[Rails.root.join('app', 'lib', '**/')]
|
||||||
config.autoload_paths += Dir[Rails.root.join('app', 'interactions', '**/')]
|
config.autoload_paths += Dir[Rails.root.join('app', 'interactions', '**/')]
|
||||||
config.eager_load_paths << config.root.join('lib', 'validators')
|
config.eager_load_paths << config.root.join('lib', 'validators')
|
||||||
|
config.eager_load_paths << config.root.join('app', 'lib')
|
||||||
config.watchable_dirs['lib'] = %i[rb]
|
config.watchable_dirs['lib'] = %i[rb]
|
||||||
|
|
||||||
config.active_record.schema_format = :sql
|
config.active_record.schema_format = :sql
|
||||||
|
|
|
@ -25,6 +25,7 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
||||||
def test_skips_auction_when_domains_is_blocked
|
def test_skips_auction_when_domains_is_blocked
|
||||||
assert_equal 'shop.test', @domain.name
|
assert_equal 'shop.test', @domain.name
|
||||||
blocked_domains(:one).update!(name: 'shop.test')
|
blocked_domains(:one).update!(name: 'shop.test')
|
||||||
|
@domain.save!(validate: false)
|
||||||
|
|
||||||
@domain.release
|
@domain.release
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
||||||
def test_skips_auction_when_domains_is_reserved
|
def test_skips_auction_when_domains_is_reserved
|
||||||
assert_equal 'shop.test', @domain.name
|
assert_equal 'shop.test', @domain.name
|
||||||
reserved_domains(:one).update!(name: 'shop.test')
|
reserved_domains(:one).update!(name: 'shop.test')
|
||||||
|
@domain.save!(validate: false)
|
||||||
|
|
||||||
@domain.release
|
@domain.release
|
||||||
|
|
||||||
|
@ -58,6 +60,24 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_updates_whois_server
|
||||||
|
@domain.update!(delete_date: '2010-07-04')
|
||||||
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
|
old_whois = @domain.whois_record
|
||||||
|
|
||||||
|
Domain.release_domains
|
||||||
|
|
||||||
|
assert_raises ActiveRecord::RecordNotFound do
|
||||||
|
old_whois.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
whois_record = Whois::Record.find_by(name: @domain.name)
|
||||||
|
json = { "name"=>@domain.name,
|
||||||
|
"status"=>["AtAuction"],
|
||||||
|
"disclaimer"=> Setting.registry_whois_disclaimer }
|
||||||
|
assert_equal whois_record.json, json
|
||||||
|
end
|
||||||
|
|
||||||
def test_notifies_registrar
|
def test_notifies_registrar
|
||||||
@domain.update!(delete_date: '2010-07-04')
|
@domain.update!(delete_date: '2010-07-04')
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue