Merge remote-tracking branch 'origin/master' into repp-domains

This commit is contained in:
Karl Erik Õunapuu 2021-01-11 16:01:55 +02:00
commit 70759cb51b
No known key found for this signature in database
GPG key ID: C9DD647298A34764
24 changed files with 331 additions and 28 deletions

View file

@ -109,6 +109,7 @@ class Ability
can :destroy, :pending
can :create, :zonefile
can :access, :settings_menu
can :manage, :mass_actions
can :manage, BouncedMailAddress
end

View file

@ -19,7 +19,10 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
end
def notification_template
def notification_template(explicit: nil)
reason = explicit&.downcase
return reason if %w[invalid_email invalid_phone].include?(reason)
if contact_emails_verification_failed.present?
'invalid_email'
elsif registrant.org?
@ -33,9 +36,8 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
statuses.include?(DomainStatus::FORCE_DELETE)
end
def schedule_force_delete(type: :fast_track, notify_by_email: false)
Domains::ForceDelete::SetForceDelete.run(domain: self,
type: type,
def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil)
Domains::ForceDelete::SetForceDelete.run(domain: self, type: type, reason: reason,
notify_by_email: notify_by_email)
end

42
app/models/mass_action.rb Normal file
View file

@ -0,0 +1,42 @@
class MassAction
def self.process(action_type, entries)
entries = CSV.read(entries, headers: true)
case action_type
when 'force_delete'
process_force_delete(entries)
else
false
end
rescue StandardError
false
end
def self.process_force_delete(entries)
return false unless force_delete_entries_valid?(entries)
apply_force_deletes(entries)
end
def self.apply_force_deletes(entries)
log = { ok: [], fail: [] }
entries.each do |e|
dn = Domain.find_by(name_puny: e['domain_name'])
log[:fail] << e['domain_name'] and next unless dn
dn.schedule_force_delete(type: :soft, notify_by_email: true, reason: e['delete_reason'])
log[:ok] << dn.name
end
log
end
def self.force_delete_entries_valid?(entries)
entries.each do |e|
reasons = %w[ENTITY_BURIED INVALID_EMAIL INVALID_PHONE]
return false unless e['domain_name'].present? && reasons.include?(e['delete_reason'])
end
true
end
end

View file

@ -144,22 +144,33 @@ class Registrar < ApplicationRecord
# Audit log is needed, therefore no raw SQL
def replace_nameservers(hostname, new_attributes, domains: [])
transaction do
domain_scope = domains.dup
domain_list = []
failed_list = []
nameservers.where(hostname: hostname).find_each do |original_nameserver|
next unless domains.include?(original_nameserver.domain.name_puny) || domains.empty?
nameservers.where(hostname: hostname).find_each do |origin|
idn = origin.domain.name
puny = origin.domain.name_puny
next unless domains.include?(idn) || domains.include?(puny) || domains.empty?
if origin.domain.nameservers.where(hostname: new_attributes[:hostname]).any?
failed_list << idn
next
end
new_nameserver = Nameserver.new
new_nameserver.domain = original_nameserver.domain
new_nameserver.domain = origin.domain
new_nameserver.attributes = new_attributes
new_nameserver.save!
domain_list << original_nameserver.domain.name
domain_scope.delete_if { |i| i == idn || i == puny }
domain_list << idn
original_nameserver.destroy!
origin.destroy!
end
domain_list.uniq.sort
self.domains.where(name: domain_list).find_each(&:update_whois_record) if domain_list.any?
[domain_list.uniq.sort, (domain_scope + failed_list).uniq.sort]
end
end