mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +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
|
end
|
||||||
|
|
||||||
def delete_reserved(name)
|
def delete_reserved(name)
|
||||||
Whois::Record.where(name: name).each do |r|
|
remove_status_from_whois(domain_name: name, domain_status: 'Reserved')
|
||||||
r.json['status'] = r.json['Reserved'].delete_if { |status| status == 'Reserved' }
|
|
||||||
r.json['status'].blank? ? r.destroy : r.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_blocked(name)
|
def delete_blocked(name)
|
||||||
|
@ -60,8 +57,12 @@ class UpdateWhoisRecordJob < Que::Job
|
||||||
def delete_disputed(name)
|
def delete_disputed(name)
|
||||||
return if Dispute.active.find_by(domain_name: name).present?
|
return if Dispute.active.find_by(domain_name: name).present?
|
||||||
|
|
||||||
Whois::Record.where(name: name).each do |r|
|
remove_status_from_whois(domain_name: name, domain_status: 'disputed')
|
||||||
r.json['status'] = r.json['status'].delete_if { |status| 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
|
r.json['status'].blank? ? r.destroy : r.save
|
||||||
end
|
end
|
||||||
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
|
class Dispute < ApplicationRecord
|
||||||
|
include WhoisStatusPopulate
|
||||||
validates :domain_name, :password, :starts_at, :expires_at, presence: true
|
validates :domain_name, :password, :starts_at, :expires_at, presence: true
|
||||||
before_validation :fill_empty_passwords, :set_expiry_date
|
before_validation :fill_empty_passwords, :set_expiry_date
|
||||||
validate :validate_domain_name_format
|
validate :validate_domain_name_format
|
||||||
|
@ -48,7 +49,7 @@ class Dispute < ApplicationRecord
|
||||||
return if domain
|
return if domain
|
||||||
|
|
||||||
wr = Whois::Record.find_or_initialize_by(name: domain_name)
|
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
|
wr.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -79,18 +80,6 @@ class Dispute < ApplicationRecord
|
||||||
record.save
|
record.save
|
||||||
end
|
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
|
def remove_data
|
||||||
UpdateWhoisRecordJob.enqueue domain_name, 'disputed'
|
UpdateWhoisRecordJob.enqueue domain_name, 'disputed'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class ReservedDomain < ApplicationRecord
|
class ReservedDomain < ApplicationRecord
|
||||||
include Versions # version/reserved_domain_version.rb
|
include Versions # version/reserved_domain_version.rb
|
||||||
|
include WhoisStatusPopulate
|
||||||
before_save :fill_empty_passwords
|
before_save :fill_empty_passwords
|
||||||
before_save :generate_data
|
before_save :generate_data
|
||||||
before_save :sync_dispute_password
|
before_save :sync_dispute_password
|
||||||
|
@ -51,24 +52,12 @@ class ReservedDomain < ApplicationRecord
|
||||||
return if Domain.where(name: name).any?
|
return if Domain.where(name: name).any?
|
||||||
|
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
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
|
wr.save
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :update_whois_record, :generate_data
|
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
|
def remove_data
|
||||||
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue