Revamp WHOIS for auctions

Fixes #1105
This commit is contained in:
Artur Beljajev 2019-03-17 19:24:44 +02:00
parent 5d61cbf4a8
commit daba47790c
9 changed files with 125 additions and 125 deletions

View file

@ -30,6 +30,12 @@ module Api
raise "Invalid status #{params[:status]}"
end
if auction.payment_not_received? || auction.domain_not_registered?
update_whois_from_auction(Auction.pending(auction.domain))
else
update_whois_from_auction(auction)
end
render json: serializable_hash_for_update_action(auction)
end
@ -44,6 +50,11 @@ module Api
hash[:registration_code] = auction.registration_code if auction.payment_received?
hash
end
def update_whois_from_auction(auction)
whois_record = Whois::Record.find_by!(name: auction.domain)
whois_record.update_from_auction(auction)
end
end
end
end

View file

@ -14,19 +14,17 @@ class Auction < ActiveRecord::Base
statuses[:payment_received]].freeze
private_constant :PENDING_STATUSES
def self.sell(domain_name)
create!(domain: domain_name.to_s, status: statuses[:started])
end
def self.pending(domain_name)
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
end
def start
self.status = self.class.statuses[:started]
save!
end
def mark_as_no_bids
transaction do
DNS::DomainName.new(domain).update_whois
no_bids!
end
no_bids!
end
def mark_as_payment_received
@ -57,17 +55,18 @@ class Auction < ActiveRecord::Base
payment_received? && registration_code_matches?(registration_code)
end
def restart
new_auction = self.class.new(domain: domain)
new_auction.start
end
private
def generate_registration_code
self.registration_code = SecureRandom.hex
end
def restart
self.class.create!(domain: domain, status: self.class.statuses[:started])
end
def registration_code_matches?(code)
registration_code == code
end
end
end

View file

@ -33,8 +33,10 @@ module DNS
end
def sell_at_auction
Auction.sell(self)
update_whois
auction = Auction.new
auction.domain = name
auction.start
update_whois_from_auction(auction)
end
def at_auction?
@ -49,10 +51,6 @@ module DNS
pending_auction&.payment_received?
end
def update_whois
Whois::Record.refresh(self)
end
def registered?
Domain.find_by_idn(name)
end
@ -92,5 +90,10 @@ module DNS
def pending_auction
Auction.pending(self)
end
def update_whois_from_auction(auction)
whois_record = Whois::Record.find_by!(name: name)
whois_record.update_from_auction(auction)
end
end
end

View file

@ -6,22 +6,18 @@ module Whois
Setting.registry_whois_disclaimer
end
def self.refresh(domain_name)
if domain_name.at_auction?
# Remove original record since `Domain#update_whois_record` callback is disabled when
# domain is at auction
find_by(name: domain_name.to_s).try(:destroy!)
create!(name: domain_name, json: { name: domain_name.to_s,
status: ['AtAuction'],
disclaimer: disclaimer })
elsif domain_name.awaiting_payment? || domain_name.pending_registration?
find_by(name: domain_name.to_s).update!(json: { name: domain_name.to_s,
status: ['PendingRegistration'],
disclaimer: disclaimer })
else
find_by(name: domain_name.to_s).destroy!
def update_from_auction(auction)
if auction.started?
update!(json: { name: auction.domain,
status: ['AtAuction'],
disclaimer: self.class.disclaimer })
elsif auction.no_bids?
destroy!
elsif auction.awaiting_payment? || auction.payment_received?
update!(json: { name: auction.domain,
status: ['PendingRegistration'],
disclaimer: self.class.disclaimer })
end
end
end
end
end