Reserved: Respect other domain statuses

This commit is contained in:
Karl Erik Õunapuu 2020-05-19 15:23:00 +03:00
parent 0998ada2fc
commit 4efd94a90b
2 changed files with 15 additions and 8 deletions

View file

@ -47,8 +47,10 @@ class UpdateWhoisRecordJob < Que::Job
end
def delete_reserved(name)
Domain.where(name: name).any?
Whois::Record.where(name: name).delete_all
Whois::Record.where(name: name).each do |r|
r.json['status'] = r.json['Reserved'].delete_if { |status| status == 'Reserved' }
r.json['status'].blank? ? r.destroy : r.save
end
end
def delete_blocked(name)

View file

@ -51,17 +51,22 @@ class ReservedDomain < ApplicationRecord
return if Domain.where(name: name).any?
wr = Whois::Record.find_or_initialize_by(name: name)
wr.json = @json = generate_json # we need @json to bind to class
wr.json = @json = generate_json(wr) # we need @json to bind to class
wr.save
end
alias_method :update_whois_record, :generate_data
def generate_json
h = HashWithIndifferentAccess.new
h[:name] = self.name
h[:status] = ['Reserved']
h
def generate_json(record)
h = HashWithIndifferentAccess.new(name: name, status: ['Reserved'])
return h if record.json.blank?
status_arr = (record.json['status'] ||= [])
return record.json if status_arr.include? 'Reserved'
status_arr.push('Reserved')
record.json['status'] = status_arr
record.json
end
def remove_data