Process failed domains for bulk ns change

This commit is contained in:
Karl Erik Õunapuu 2020-12-30 11:00:52 +02:00
parent 7d61eb07b0
commit 0e120d4992
No known key found for this signature in database
GPG key ID: C9DD647298A34764
5 changed files with 25 additions and 11 deletions

View file

@ -51,6 +51,10 @@ class Registrar
notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: " \
"#{parsed_response[:data][:affected_domains].join(', ')}"
if parsed_response[:data][:skipped_domains]
notices << "#{t('.skipped_domains')}: " \
"#{parsed_response[:data][:skipped_domains].join(', ')}"
end
flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url

View file

@ -5,12 +5,12 @@ module Repp
before_action :verify_nameserver_existance, only: %i[update]
def update
affected = current_user.registrar
affected, errored = current_user.registrar
.replace_nameservers(hostname,
hostname_params[:data][:attributes],
domains: domains_from_params)
render_success(data: data_format_for_success(affected))
render_success(data: data_format_for_success(affected, errored))
rescue ActiveRecord::RecordInvalid => e
handle_errors(e.record)
end
@ -23,12 +23,13 @@ module Repp
params[:data][:domains].map(&:downcase)
end
def data_format_for_success(affected_domains)
def data_format_for_success(affected_domains, errored_domains)
{
type: 'nameserver',
id: params[:data][:attributes][:hostname],
attributes: params[:data][:attributes],
affected_domains: affected_domains,
skipped_domains: errored_domains,
}
end

View file

@ -145,22 +145,28 @@ class Registrar < ApplicationRecord
def replace_nameservers(hostname, new_attributes, domains: [])
transaction do
domain_list = []
failed_list = []
nameservers.where(hostname: hostname).find_each do |original_nameserver|
next unless domains.include?(original_nameserver.domain.name) || domains.empty?
nameservers.where(hostname: hostname).find_each do |origin|
next unless domains.include?(origin.domain.name) || domains.empty?
if origin.domain.nameservers.where(hostname: new_attributes[:hostname]).any?
failed_list << origin.domain.name
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_list << origin.domain.name
original_nameserver.destroy!
origin.destroy!
end
self.domains.where(name: domain_list).find_each(&:update_whois_record) if domain_list.any?
domain_list.uniq.sort
[domain_list.uniq.sort, failed_list.uniq.sort]
end
end

View file

@ -4,3 +4,4 @@ en:
update:
replaced: Nameserver have been successfully replaced
affected_domains: Affected domains
skipped_domains: Skipped domains

View file

@ -18,7 +18,8 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
.to_return(body: { data: {
type: 'nameserver',
id: 'new-ns.bestnames.test',
affected_domains: ["airport.test", "shop.test"]
affected_domains: ["airport.test", "shop.test"],
skipped_domains: []
}
}.to_json, status: 200)
@ -73,7 +74,8 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
.to_return(body: { data: {
type: 'nameserver',
id: 'new-ns.bestnames.test',
affected_domains: ["shop.test"]}}.to_json, status: 200)
affected_domains: ["shop.test"],
skipped_domains: []}}.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'