From af0a0611ce799149ff82cf17a8c6cb774b65da65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 30 Dec 2020 12:46:51 +0200 Subject: [PATCH] Bulk NS change: track untouched domains --- .../registrar/nameservers_controller.rb | 23 +++++++++++-------- .../v1/registrar/nameservers_controller.rb | 6 ++--- app/models/registrar.rb | 4 +++- config/locales/registrar/nameservers.en.yml | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 1ab0e335f..52c43bb1d 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -48,22 +48,25 @@ class Registrar parsed_response = JSON.parse(response.body, symbolize_names: true) if response.code == '200' - 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 + redirect_to(registrar_domains_url, + flash: { notice: compose_notice_message(parsed_response) }) else @api_errors = parsed_response[:message] render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver } end end + def compose_notice_message(res) + notices = ["#{t('.replaced')}. #{t('.affected_domains')}: " \ + "#{res[:data][:affected_domains].join(', ')}"] + + if res[:data][:skipped_domains] + notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}" + end + + notices.join(', ') + end + def domain_list_from_csv return [] if params[:puny_file].blank? diff --git a/app/controllers/repp/v1/registrar/nameservers_controller.rb b/app/controllers/repp/v1/registrar/nameservers_controller.rb index a71f11759..39f076e9b 100644 --- a/app/controllers/repp/v1/registrar/nameservers_controller.rb +++ b/app/controllers/repp/v1/registrar/nameservers_controller.rb @@ -6,9 +6,9 @@ module Repp def update affected, errored = current_user.registrar - .replace_nameservers(hostname, - hostname_params[:data][:attributes], - domains: domains_from_params) + .replace_nameservers(hostname, + hostname_params[:data][:attributes], + domains: domains_from_params) render_success(data: data_format_for_success(affected, errored)) rescue ActiveRecord::RecordInvalid => e diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 50ace5d4e..168dfdca7 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -144,6 +144,7 @@ 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 = [] @@ -162,13 +163,14 @@ class Registrar < ApplicationRecord new_nameserver.attributes = new_attributes new_nameserver.save! + domain_scope.delete_if { |i| i == idn || i == puny } domain_list << idn origin.destroy! end self.domains.where(name: domain_list).find_each(&:update_whois_record) if domain_list.any? - [domain_list.uniq.sort, failed_list.uniq.sort] + [domain_list.uniq.sort, (domain_scope + failed_list).uniq.sort] end end diff --git a/config/locales/registrar/nameservers.en.yml b/config/locales/registrar/nameservers.en.yml index 2e645734d..9c1c2a70e 100644 --- a/config/locales/registrar/nameservers.en.yml +++ b/config/locales/registrar/nameservers.en.yml @@ -4,4 +4,4 @@ en: update: replaced: Nameserver have been successfully replaced affected_domains: Affected domains - skipped_domains: Skipped domains + skipped_domains: Untouched domains