mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 20:27:30 +02:00
Remove redundant functionality
This commit is contained in:
parent
4efd94a90b
commit
0b2b1b0ef1
4 changed files with 26 additions and 32 deletions
|
@ -47,10 +47,7 @@ class UpdateWhoisRecordJob < Que::Job
|
|||
end
|
||||
|
||||
def delete_reserved(name)
|
||||
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
|
||||
remove_status_from_whois(domain_name: name, domain_status: 'Reserved')
|
||||
end
|
||||
|
||||
def delete_blocked(name)
|
||||
|
@ -60,8 +57,12 @@ class UpdateWhoisRecordJob < Que::Job
|
|||
def delete_disputed(name)
|
||||
return if Dispute.active.find_by(domain_name: name).present?
|
||||
|
||||
Whois::Record.where(name: name).each do |r|
|
||||
r.json['status'] = r.json['status'].delete_if { |status| status == 'disputed' }
|
||||
remove_status_from_whois(domain_name: name, domain_status: 'disputed')
|
||||
end
|
||||
|
||||
def remove_status_from_whois(domain_name:, domain_status:)
|
||||
Whois::Record.where(name: domain_name).each do |r|
|
||||
r.json['status'] = r.json['status'].delete_if { |status| status == domain_status }
|
||||
r.json['status'].blank? ? r.destroy : r.save
|
||||
end
|
||||
end
|
||||
|
|
15
app/models/concerns/whois_status_populate.rb
Normal file
15
app/models/concerns/whois_status_populate.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module WhoisStatusPopulate
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def generate_json(record, domain_status:)
|
||||
h = HashWithIndifferentAccess.new(name: record.name, status: [domain_status])
|
||||
return h if record.json.blank?
|
||||
|
||||
status_arr = (record.json['status'] ||= [])
|
||||
return record.json if status_arr.include? domain_status
|
||||
|
||||
status_arr.push(domain_status)
|
||||
record.json['status'] = status_arr
|
||||
record.json
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
class Dispute < ApplicationRecord
|
||||
include WhoisStatusPopulate
|
||||
validates :domain_name, :password, :starts_at, :expires_at, presence: true
|
||||
before_validation :fill_empty_passwords, :set_expiry_date
|
||||
validate :validate_domain_name_format
|
||||
|
@ -48,7 +49,7 @@ class Dispute < ApplicationRecord
|
|||
return if domain
|
||||
|
||||
wr = Whois::Record.find_or_initialize_by(name: domain_name)
|
||||
wr.json = @json = generate_json(wr)
|
||||
wr.json = @json = generate_json(wr, domain_status: 'disputed')
|
||||
wr.save
|
||||
end
|
||||
|
||||
|
@ -79,18 +80,6 @@ class Dispute < ApplicationRecord
|
|||
record.save
|
||||
end
|
||||
|
||||
def generate_json(record)
|
||||
h = HashWithIndifferentAccess.new(name: domain_name, status: ['disputed'])
|
||||
return h if record.json.blank?
|
||||
|
||||
status_arr = (record.json['status'] ||= [])
|
||||
return record.json if status_arr.include? 'disputed'
|
||||
|
||||
status_arr.push('disputed')
|
||||
record.json['status'] = status_arr
|
||||
record.json
|
||||
end
|
||||
|
||||
def remove_data
|
||||
UpdateWhoisRecordJob.enqueue domain_name, 'disputed'
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class ReservedDomain < ApplicationRecord
|
||||
include Versions # version/reserved_domain_version.rb
|
||||
include WhoisStatusPopulate
|
||||
before_save :fill_empty_passwords
|
||||
before_save :generate_data
|
||||
before_save :sync_dispute_password
|
||||
|
@ -51,24 +52,12 @@ class ReservedDomain < ApplicationRecord
|
|||
return if Domain.where(name: name).any?
|
||||
|
||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||
wr.json = @json = generate_json(wr) # we need @json to bind to class
|
||||
wr.json = @json = generate_json(wr, domain_status: 'Reserved') # we need @json to bind to class
|
||||
wr.save
|
||||
end
|
||||
|
||||
alias_method :update_whois_record, :generate_data
|
||||
|
||||
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
|
||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue