diff --git a/app/api/repp/nameservers_v1.rb b/app/api/repp/nameservers_v1.rb index d653adf7f..71fde5aba 100644 --- a/app/api/repp/nameservers_v1.rb +++ b/app/api/repp/nameservers_v1.rb @@ -29,7 +29,7 @@ module Repp } begin - current_user.registrar.replace_nameservers(hostname, new_attributes) + affected_domains = current_user.registrar.replace_nameservers(hostname, new_attributes) rescue ActiveRecord::RecordInvalid => e error!({ errors: e.record.errors.full_messages.map { |error| { title: error } } }, 400) end @@ -37,7 +37,8 @@ module Repp status 200 @response = { data: { type: 'nameserver', id: params[:data][:attributes][:hostname], - attributes: params[:data][:attributes] } } + attributes: params[:data][:attributes], + affected_domains: affected_domains } } end end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 54e007133..de02d42a7 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -145,7 +145,7 @@ class Registrar < ActiveRecord::Base original_nameserver.destroy! end - domain_list + domain_list.uniq.sort end end diff --git a/doc/repp/v1/nameservers.md b/doc/repp/v1/nameservers.md index 702a0c186..c1269f92a 100644 --- a/doc/repp/v1/nameservers.md +++ b/doc/repp/v1/nameservers.md @@ -35,6 +35,7 @@ Content-Type: application/json "ipv4": ["192.0.2.1", "192.0.2.2"], "ipv6": ["2001:db8::1", "2001:db8::2"] }, + "affected_domains": ["example.com", "example.org"] } } ``` diff --git a/test/integration/api/nameservers/put_test.rb b/test/integration/api/nameservers/put_test.rb index 416510541..e840cfcfc 100644 --- a/test/integration/api/nameservers/put_test.rb +++ b/test/integration/api/nameservers/put_test.rb @@ -41,11 +41,12 @@ class APINameserversPutTest < ActionDispatch::IntegrationTest assert_equal nameserver_hash, nameservers(:metro_ns1).reload.attributes end - def test_returns_new_nameserver_record + def test_returns_new_nameserver_record_and_affected_domain request_params = { format: :json, data: { type: 'nameserver', id: 'ns1.bestnames.test', attributes: { hostname: 'ns55.bestnames.test', ipv4: ['192.0.2.55'], ipv6: ['2001:db8::55'] } } } + put '/repp/v1/registrar/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } assert_response 200 @@ -53,7 +54,8 @@ class APINameserversPutTest < ActionDispatch::IntegrationTest id: 'ns55.bestnames.test', attributes: { hostname: 'ns55.bestnames.test', ipv4: ['192.0.2.55'], - ipv6: ['2001:db8::55'] } } }), + ipv6: ['2001:db8::55'] }, + affected_domains: ["airport.test", "shop.test"] } }), JSON.parse(response.body, symbolize_names: true) end diff --git a/test/integration/registrar/bulk_change/nameserver_test.rb b/test/integration/registrar/bulk_change/nameserver_test.rb index 20fd6617d..d1dbfc012 100644 --- a/test/integration/registrar/bulk_change/nameserver_test.rb +++ b/test/integration/registrar/bulk_change/nameserver_test.rb @@ -16,7 +16,8 @@ class RegistrarAreaNameserverBulkChangeTest < ActionDispatch::IntegrationTest basic_auth: ['test_goodnames', 'testtest']) .to_return(body: { data: [{ type: 'nameserver', - id: 'new-ns.bestnames.test' + id: 'new-ns.bestnames.test', + affected_domains: ["airport.test", "shop.test"] }] }.to_json, status: 200) visit registrar_domains_url diff --git a/test/models/registrar/replace_nameservers_test.rb b/test/models/registrar/replace_nameservers_test.rb index c247b2860..5bcbb83d1 100644 --- a/test/models/registrar/replace_nameservers_test.rb +++ b/test/models/registrar/replace_nameservers_test.rb @@ -5,7 +5,7 @@ class ReplaceNameserversTest < ActiveSupport::TestCase @registrar = registrars(:bestnames) end - def test_replace_nameservers_in_bulk_returns_domain_names + def test_replace_nameservers_in_bulk_returns_sorted_domain_names new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1', ipv6: '2001:db8::2' } result = @registrar.replace_nameservers('ns1.bestnames.test', new_attributes)