diff --git a/app/api/repp/nameservers_v1.rb b/app/api/repp/nameservers_v1.rb index 04d7d4f6a..56a893880 100644 --- a/app/api/repp/nameservers_v1.rb +++ b/app/api/repp/nameservers_v1.rb @@ -8,6 +8,7 @@ module Repp requires :data, type: Hash, allow_blank: false do requires :type, type: String, allow_blank: false requires :id, type: String, allow_blank: false + optional :domains, type: Array requires :attributes, type: Hash, allow_blank: false do requires :hostname, type: String, allow_blank: false requires :ipv4, type: Array @@ -28,8 +29,11 @@ module Repp ipv6: params[:data][:attributes][:ipv6], } + domains = params[:data][:domains] || [] + begin - affected_domains = current_user.registrar.replace_nameservers(hostname, new_attributes) + affected_domains = current_user.registrar.replace_nameservers(hostname, new_attributes, + domains: domains) rescue ActiveRecord::RecordInvalid => e error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400) end diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 95da7e329..c8c88c8ca 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -6,9 +6,12 @@ class Registrar ipv4 = params[:ipv4].split("\r\n") ipv6 = params[:ipv6].split("\r\n") + domains = domain_list_from_csv + uri = URI.parse("#{ENV['repp_url']}registrar/nameservers") request = Net::HTTP::Put.new(uri, 'Content-Type' => 'application/json') request.body = { data: { type: 'nameserver', id: params[:old_hostname], + domains: domains, attributes: { hostname: params[:new_hostname], ipv4: ipv4, ipv6: ipv6 } } }.to_json @@ -55,5 +58,13 @@ class Registrar render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver } end end + + def domain_list_from_csv + return [] if params[:puny_file].blank? + + domains = [] + CSV.read(params[:puny_file].path, headers: true).each { |b| domains << b['domain_name'] } + domains + end end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index e2ffcbfd4..040c7886b 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -141,11 +141,13 @@ class Registrar < ApplicationRecord end # Audit log is needed, therefore no raw SQL - def replace_nameservers(hostname, new_attributes) + def replace_nameservers(hostname, new_attributes, domains: []) transaction do domain_list = [] nameservers.where(hostname: hostname).find_each do |original_nameserver| + next unless domains.include?(original_nameserver.domain.name_puny) || domains.empty? + new_nameserver = Nameserver.new new_nameserver.domain = original_nameserver.domain new_nameserver.attributes = new_attributes diff --git a/app/views/registrar/bulk_change/_nameserver_form.html.erb b/app/views/registrar/bulk_change/_nameserver_form.html.erb index e3f4a0214..782076358 100644 --- a/app/views/registrar/bulk_change/_nameserver_form.html.erb +++ b/app/views/registrar/bulk_change/_nameserver_form.html.erb @@ -1,4 +1,4 @@ -<%= form_tag registrar_nameservers_path, method: :patch, class: 'form-horizontal' do %> +<%= form_tag registrar_nameservers_path, multipart: true, method: :patch, class: 'form-horizontal' do %> <%= render 'registrar/domain_transfers/form/api_errors' %>