mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
39 lines
986 B
Ruby
39 lines
986 B
Ruby
module Whois
|
|
class Update < ActiveInteraction::Base
|
|
array :names
|
|
string :type
|
|
|
|
validates :type, inclusion: { in: %w[reserved blocked domain disputed zone] }
|
|
|
|
def execute
|
|
::PaperTrail.request.whodunnit = "job - #{self.class.name} - #{type}"
|
|
|
|
klass = determine_class
|
|
|
|
Array(names).each do |name|
|
|
record = find_record(klass, name)
|
|
if record
|
|
Whois::UpdateRecord.run(record: { klass: klass.to_s, id: record.id, type: type })
|
|
else
|
|
Whois::DeleteRecord.run(name: name, type: type)
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def determine_class
|
|
case type
|
|
when 'reserved' then ReservedDomain
|
|
when 'blocked' then BlockedDomain
|
|
when 'domain' then Domain
|
|
when 'disputed' then Dispute.active
|
|
else DNS::Zone
|
|
end
|
|
end
|
|
|
|
def find_record(klass, name)
|
|
klass == DNS::Zone ? klass.find_by(origin: name) : klass.find_by(name: name)
|
|
end
|
|
end
|
|
end
|