From d36ef24170d40db35b0926adba656189df215d12 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 15 Sep 2021 21:55:11 +0300 Subject: [PATCH 01/12] created method for adding nameservers --- .../v1/registrar/nameservers_controller.rb | 21 ++++++++---- app/models/registrar.rb | 32 +++++++++++++++++++ .../repp/v1/registrar/nameservers_test.rb | 23 +++++++++++++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/app/controllers/repp/v1/registrar/nameservers_controller.rb b/app/controllers/repp/v1/registrar/nameservers_controller.rb index 0d03bf2a9..5c53b62f2 100644 --- a/app/controllers/repp/v1/registrar/nameservers_controller.rb +++ b/app/controllers/repp/v1/registrar/nameservers_controller.rb @@ -8,7 +8,7 @@ module Repp desc 'bulk nameserver change' param :data, Hash, required: true, desc: 'Object holding nameserver changes' do param :type, String, required: true, desc: 'Always set as "nameserver"' - param :id, String, required: true, desc: 'Hostname of replacable nameserver' + param :id, String, required: false, desc: 'Hostname of replacable nameserver' param :domains, Array, required: false, desc: 'Array of domain names qualified for ' \ 'nameserver replacement' param :attributes, Hash, required: true, desc: 'Object holding new nameserver values' do @@ -17,11 +17,16 @@ module Repp param :ipv6, Array, of: String, required: false, desc: 'Array of fixed IPv6 addresses' end end + def update - affected, errored = current_user.registrar - .replace_nameservers(hostname, - hostname_params[:data][:attributes], - domains: domains_from_params) + affected, errored = if hostname.present? + current_user.registrar.replace_nameservers(hostname, + hostname_params[:data][:attributes], + domains: domains_from_params) + else + current_user.registrar.add_nameservers(hostname_params[:data][:attributes], + domains: domains_from_params) + end render_success(data: data_format_for_success(affected, errored)) rescue ActiveRecord::RecordInvalid => e @@ -47,7 +52,7 @@ module Repp end def hostname_params - params.require(:data).require(%i[type id]) + params.require(:data).require(%i[type]) params.require(:data).require(:attributes).require([:hostname]) params.permit(data: [ @@ -58,10 +63,12 @@ module Repp end def hostname - hostname_params[:data][:id] + hostname_params[:data][:id] || nil end def verify_nameserver_existance + return true if hostname.nil? + current_user.registrar.nameservers.find_by!(hostname: hostname) end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 18c549e41..efb073e04 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -43,6 +43,7 @@ class Registrar < ApplicationRecord after_commit :update_whois_records def update_whois_records return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present? + RegenerateRegistrarWhoisesJob.perform_later id end @@ -175,6 +176,36 @@ class Registrar < ApplicationRecord end end + def add_nameservers(new_attributes, domains: []) + transaction do + domain_scope = domains.dup + domain_list = [] + failed_list = [] + + return if domains.empty? + + domain_scope.each do |domain_name| + domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) + + if !domain.present? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) + failed_list << domain_name + next + end + + new_nameserver = Nameserver.new + new_nameserver.domain = domain + new_nameserver.attributes = new_attributes + new_nameserver.save! + + domain_scope.delete_if { |i| i == domain.name || i == domain.name_puny } + domain_list << domain_name + end + + 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 + def vat_country=(country) self.address_country_code = country.alpha2 end @@ -198,6 +229,7 @@ class Registrar < ApplicationRecord def billing_email return contact_email if self[:billing_email].blank? + self[:billing_email] end diff --git a/test/integration/repp/v1/registrar/nameservers_test.rb b/test/integration/repp/v1/registrar/nameservers_test.rb index 01f30c813..11216375d 100644 --- a/test/integration/repp/v1/registrar/nameservers_test.rb +++ b/test/integration/repp/v1/registrar/nameservers_test.rb @@ -34,6 +34,29 @@ class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest assert json[:data][:affected_domains].include? 'shop.test' end + def test_add_nameserver_values + nameserver = nameservers(:shop_ns1) + payload = { + "data": { + "type": 'nameserver', + "domains": ['shop.test'], + "attributes": { + "hostname": "#{nameserver.hostname}.testtest", + "ipv4": ['2.2.2.2'] + } + } + } + + put '/repp/v1/registrar/nameservers', headers: @auth_headers, params: payload + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + assert_equal({ hostname: "#{nameserver.hostname}.testtest", ipv4: ['2.2.2.2'] }, json[:data][:attributes]) + assert json[:data][:affected_domains].include? 'shop.test' + end + def test_fails_to_update_if_prohibited domain = domains(:shop) domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED]) From 170652679de124390e50b53d61136776e081e818 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 16 Sep 2021 14:46:27 +0300 Subject: [PATCH 02/12] fixed rubocop errors --- app/controllers/repp/v1/registrar/nameservers_controller.rb | 2 +- app/models/registrar.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repp/v1/registrar/nameservers_controller.rb b/app/controllers/repp/v1/registrar/nameservers_controller.rb index 5c53b62f2..6e8143907 100644 --- a/app/controllers/repp/v1/registrar/nameservers_controller.rb +++ b/app/controllers/repp/v1/registrar/nameservers_controller.rb @@ -18,7 +18,7 @@ module Repp end end - def update + def update # rubocop:disable Metrics/MethodLength affected, errored = if hostname.present? current_user.registrar.replace_nameservers(hostname, hostname_params[:data][:attributes], diff --git a/app/models/registrar.rb b/app/models/registrar.rb index efb073e04..e0ec3aac9 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -187,7 +187,7 @@ class Registrar < ApplicationRecord domain_scope.each do |domain_name| domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) - if !domain.present? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) + if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) failed_list << domain_name next end From e1e8979736f48745677ba904f6f8c4e5a6111f0d Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 17 Sep 2021 11:05:25 +0300 Subject: [PATCH 03/12] refactored after review --- app/models/registrar.rb | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index e0ec3aac9..598605409 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -160,10 +160,7 @@ class Registrar < ApplicationRecord next end - new_nameserver = Nameserver.new - new_nameserver.domain = origin.domain - new_nameserver.attributes = new_attributes - new_nameserver.save! + create_nameserver(origin.domain, new_attributes) domain_scope.delete_if { |i| i == idn || i == puny } domain_list << idn @@ -184,28 +181,36 @@ class Registrar < ApplicationRecord return if domains.empty? - domain_scope.each do |domain_name| - domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) - - if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) - failed_list << domain_name - next - end - - new_nameserver = Nameserver.new - new_nameserver.domain = domain - new_nameserver.attributes = new_attributes - new_nameserver.save! - - domain_scope.delete_if { |i| i == domain.name || i == domain.name_puny } - domain_list << domain_name - end + domain_list_processing(domain_scope, new_attributes, domain_list, failed_list) 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 + def domain_list_processing(domains, new_attributes, domain_list, failed_list) + domains.each do |domain_name| + domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) + + if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) + failed_list << domain_name + next + end + + create_nameserver(domain, new_attributes) + + domains.delete_if { |i| i == domain.name || i == domain.name_puny } + domain_list << domain_name + end + end + + def create_nameserver(domain, attributes) + new_nameserver = Nameserver.new + new_nameserver.domain = domain + new_nameserver.attributes = attributes + new_nameserver.save! + end + def vat_country=(country) self.address_country_code = country.alpha2 end From 9b67dff2e4efd46ce6d013c3fda0ce8344a8f9d1 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 22 Sep 2021 18:15:54 +0300 Subject: [PATCH 04/12] fixed bulk change nameserver form --- app/controllers/repp/v1/registrar/nameservers_controller.rb | 2 +- app/views/registrar/bulk_change/_nameserver_form.html.erb | 4 ++-- config/locales/registrar/bulk_change.en.yml | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/repp/v1/registrar/nameservers_controller.rb b/app/controllers/repp/v1/registrar/nameservers_controller.rb index 6e8143907..174193350 100644 --- a/app/controllers/repp/v1/registrar/nameservers_controller.rb +++ b/app/controllers/repp/v1/registrar/nameservers_controller.rb @@ -67,7 +67,7 @@ module Repp end def verify_nameserver_existance - return true if hostname.nil? + return true if hostname.blank? current_user.registrar.nameservers.find_by!(hostname: hostname) end diff --git a/app/views/registrar/bulk_change/_nameserver_form.html.erb b/app/views/registrar/bulk_change/_nameserver_form.html.erb index 6feb83648..a6df5c398 100644 --- a/app/views/registrar/bulk_change/_nameserver_form.html.erb +++ b/app/views/registrar/bulk_change/_nameserver_form.html.erb @@ -3,11 +3,11 @@
- <%= label_tag :old_hostname %> + <%= label_tag t '.old_hostname' %>
- <%= text_field_tag :old_hostname, params[:old_hostname], required: true, + <%= text_field_tag :old_hostname, params[:old_hostname], required: false, class: 'form-control' %>
diff --git a/config/locales/registrar/bulk_change.en.yml b/config/locales/registrar/bulk_change.en.yml index d9f6ebbd2..f669f468f 100644 --- a/config/locales/registrar/bulk_change.en.yml +++ b/config/locales/registrar/bulk_change.en.yml @@ -32,6 +32,7 @@ en: ident data ie for updating contact information. nameserver_form: + old_hostname: Old hostname (optional) ip_hint: One IP per line replace_btn: Replace nameserver help_btn: Toggle help From 1f42c1f92157957b95dedad7a7021854eda0781d Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 22 Sep 2021 18:29:58 +0300 Subject: [PATCH 05/12] fixed errors --- app/views/registrar/bulk_change/_nameserver_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/registrar/bulk_change/_nameserver_form.html.erb b/app/views/registrar/bulk_change/_nameserver_form.html.erb index a6df5c398..45ae6a7dd 100644 --- a/app/views/registrar/bulk_change/_nameserver_form.html.erb +++ b/app/views/registrar/bulk_change/_nameserver_form.html.erb @@ -3,7 +3,7 @@
- <%= label_tag t '.old_hostname' %> + <%= label_tag :old_hostname, t('.old_hostname') %>
From f0ee59bf46099dcb2c235e06d55585a708b9dc35 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 23 Sep 2021 12:51:21 +0300 Subject: [PATCH 06/12] fixed CSV headers, added tests --- .../registrar/nameservers_controller.rb | 9 ++- config/locales/registrar/bulk_change.en.yml | 2 +- config/locales/registrar/nameservers.en.yml | 1 + .../valid_domains_for_ns_replacement.csv | 2 +- .../bulk_change/nameserver_test.rb | 80 +++++++++++++++++-- 5 files changed, 81 insertions(+), 13 deletions(-) diff --git a/app/controllers/registrar/nameservers_controller.rb b/app/controllers/registrar/nameservers_controller.rb index 37d95dbe2..9bf31d1d7 100644 --- a/app/controllers/registrar/nameservers_controller.rb +++ b/app/controllers/registrar/nameservers_controller.rb @@ -32,7 +32,8 @@ class Registrar end def compose_notice_message(res) - notices = ["#{t('.replaced')}. #{t('.affected_domains')}: " \ + action_text = params[:old_hostname].blank? ? t('.added') : t('.replaced') + notices = ["#{action_text}. #{t('.affected_domains')}: " \ "#{res[:data][:affected_domains].join(', ')}"] notices << "#{t('.skipped_domains')}: #{res[:data][:skipped_domains].join(', ')}" if res[:data][:skipped_domains] @@ -42,7 +43,7 @@ class Registrar def csv_list_empty_guard notice = 'CSV scoped domain list seems empty. Make sure that domains are added and ' \ - '"domain_name" header is present.' + '"Domain" header is present.' redirect_to(registrar_domains_url, flash: { notice: notice }) end @@ -52,9 +53,9 @@ class Registrar domains = [] csv = CSV.read(params[:puny_file].path, headers: true) - return [] if csv['domain_name'].blank? + return [] if csv['Domain'].blank? - csv.map { |b| domains << b['domain_name'] } + csv.map { |b| domains << b['Domain'] } domains.compact rescue CSV::MalformedCSVError diff --git a/config/locales/registrar/bulk_change.en.yml b/config/locales/registrar/bulk_change.en.yml index f669f468f..8d5a6d9eb 100644 --- a/config/locales/registrar/bulk_change.en.yml +++ b/config/locales/registrar/bulk_change.en.yml @@ -34,7 +34,7 @@ en: nameserver_form: old_hostname: Old hostname (optional) ip_hint: One IP per line - replace_btn: Replace nameserver + replace_btn: Replace/Add nameserver help_btn: Toggle help help: >- Replace nameserver specified in the "old hostname" with the one in "new hostname" with diff --git a/config/locales/registrar/nameservers.en.yml b/config/locales/registrar/nameservers.en.yml index 9c1c2a70e..15a2623e9 100644 --- a/config/locales/registrar/nameservers.en.yml +++ b/config/locales/registrar/nameservers.en.yml @@ -3,5 +3,6 @@ en: nameservers: update: replaced: Nameserver have been successfully replaced + added: Nameserver have been successfully added affected_domains: Affected domains skipped_domains: Untouched domains diff --git a/test/fixtures/files/valid_domains_for_ns_replacement.csv b/test/fixtures/files/valid_domains_for_ns_replacement.csv index 122301ca8..3ff8ebfa2 100644 --- a/test/fixtures/files/valid_domains_for_ns_replacement.csv +++ b/test/fixtures/files/valid_domains_for_ns_replacement.csv @@ -1,2 +1,2 @@ -domain_name +Domain shop.test diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index 287265cdf..306c75424 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -31,7 +31,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'New hostname', with: 'new-ns.bestnames.test' fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_requested request_stub assert_current_path registrar_domains_path @@ -52,7 +52,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'New hostname', with: 'new hostname' fill_in 'ipv4', with: 'ipv4' fill_in 'ipv6', with: 'ipv6' - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_text 'epic fail' assert_field 'Old hostname', with: 'old hostname' @@ -63,7 +63,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase def test_replaces_nameservers_only_for_scoped_domains request_body = { data: { type: 'nameserver', - id: 'ns1.bestnames.test', + id: 'ns1.bestnames.test', domains: ['shop.test'], attributes: { hostname: 'new-ns.bestnames.test', ipv4: %w[192.0.2.55 192.0.2.56], @@ -87,7 +87,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_ns_replacement.csv').to_s - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' assert_requested request_stub assert_current_path registrar_domains_path @@ -109,10 +109,76 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'invalid_domains_for_ns_replacement.csv').to_s assert_no_changes -> { nameserver.hostname } do - click_on 'Replace nameserver' + click_on 'Replace/Add nameserver' end - assert_current_path registrar_domains_path - assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and "domain_name" header is present.' + assert_current_path registrar_domains_path + assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and "Domain" header is present.' + end + + def test_replaces_current_registrar_nameservers + request_body = { data: { type: 'nameserver', + id: '', + domains: [], + attributes: { hostname: 'new-ns2.bestnames.test', + ipv4: %w[192.0.2.55 192.0.2.56], + ipv6: %w[2001:db8::55 2001:db8::56] } } } + request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, + headers: { 'Content-type' => Mime[:json] }, + basic_auth: ['test_goodnames', 'testtest']) + .to_return(body: { data: { + type: 'nameserver', + id: 'new-ns2.bestnames.test', + affected_domains: ["airport.test", "shop.test"], + skipped_domains: [] + } + }.to_json, status: 200) + + visit registrar_domains_url + click_link 'Bulk change' + click_link 'Nameserver' + + fill_in 'New hostname', with: 'new-ns2.bestnames.test' + fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" + fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" + click_on 'Replace/Add nameserver' + + assert_requested request_stub + assert_current_path registrar_domains_path + assert_text 'Nameserver have been successfully added' + assert_text 'Affected domains: airport.test, shop.test' + end + + def test_adding_nameservers_only_for_scoped_domains + request_body = { data: { type: 'nameserver', + id: '', + domains: ['shop.test'], + attributes: { hostname: 'new-ns1.bestnames.test', + ipv4: %w[192.0.2.55 192.0.2.56], + ipv6: %w[2001:db8::55 2001:db8::56] } } } + request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, + headers: { 'Content-type' => Mime[:json] }, + basic_auth: ['test_goodnames', 'testtest']) + .to_return(body: { data: { + type: 'nameserver', + id: 'new-ns1.bestnames.test', + affected_domains: ["shop.test"], + skipped_domains: []}}.to_json, status: 200) + + visit registrar_domains_url + click_link 'Bulk change' + click_link 'Nameserver' + + fill_in 'New hostname', with: 'new-ns1.bestnames.test' + fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56" + fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56" + attach_file :puny_file, Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_ns_replacement.csv').to_s + + click_on 'Replace/Add nameserver' + + assert_requested request_stub + assert_current_path registrar_domains_path + assert_text 'Nameserver have been successfully added' + assert_text 'Affected domains: shop.test' end end From fb2a175bce8637e4aa2754d306c795fd59025b3f Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 23 Sep 2021 15:13:49 +0300 Subject: [PATCH 07/12] fixed test method name --- test/system/registrar_area/bulk_change/nameserver_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/registrar_area/bulk_change/nameserver_test.rb b/test/system/registrar_area/bulk_change/nameserver_test.rb index 306c75424..8a053333f 100644 --- a/test/system/registrar_area/bulk_change/nameserver_test.rb +++ b/test/system/registrar_area/bulk_change/nameserver_test.rb @@ -116,7 +116,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase assert_text 'CSV scoped domain list seems empty. Make sure that domains are added and "Domain" header is present.' end - def test_replaces_current_registrar_nameservers + def test_adding_current_registrar_nameservers request_body = { data: { type: 'nameserver', id: '', domains: [], From 70d46f4d3f604b6e6c24196bb2487bb9f8c21283 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 23 Sep 2021 17:12:19 +0300 Subject: [PATCH 08/12] changed update prohibited conditions --- app/models/concerns/domain/bulk_updatable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/domain/bulk_updatable.rb b/app/models/concerns/domain/bulk_updatable.rb index 6a462e1af..05d9a0d64 100644 --- a/app/models/concerns/domain/bulk_updatable.rb +++ b/app/models/concerns/domain/bulk_updatable.rb @@ -2,7 +2,7 @@ module Domain::BulkUpdatable extend ActiveSupport::Concern def bulk_update_prohibited? - discarded? || statuses_blocks_update? + statuses_blocks_update? end def statuses_blocks_update? From 777678779097cce56d29819c9e16c6f900cb7a93 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 23 Sep 2021 18:01:15 +0300 Subject: [PATCH 09/12] fixed tests --- test/integration/api/domain_admin_contacts_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/api/domain_admin_contacts_test.rb b/test/integration/api/domain_admin_contacts_test.rb index cd5b92865..46e68c90e 100644 --- a/test/integration/api/domain_admin_contacts_test.rb +++ b/test/integration/api/domain_admin_contacts_test.rb @@ -61,8 +61,8 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest end def test_return_skipped_domains_in_alphabetical_order - domains(:shop).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) - domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + domains(:airport).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code, new_contact_id: @admin_new.code }, From e2a085761fced86ab46d697fb967dcca46b88bf1 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 23 Sep 2021 18:10:09 +0300 Subject: [PATCH 10/12] fixed tests --- test/integration/api/domain_admin_contacts_test.rb | 2 +- test/integration/api/domain_contacts_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/api/domain_admin_contacts_test.rb b/test/integration/api/domain_admin_contacts_test.rb index 46e68c90e..ce61cffd1 100644 --- a/test/integration/api/domain_admin_contacts_test.rb +++ b/test/integration/api/domain_admin_contacts_test.rb @@ -38,7 +38,7 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest end def test_skip_discarded_domains - domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) + domains(:airport).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code, new_contact_id: @admin_new.code }, diff --git a/test/integration/api/domain_contacts_test.rb b/test/integration/api/domain_contacts_test.rb index efd7032b4..3301326d0 100644 --- a/test/integration/api/domain_contacts_test.rb +++ b/test/integration/api/domain_contacts_test.rb @@ -12,7 +12,7 @@ class APIDomainContactsTest < ApplicationIntegrationTest end def test_skip_discarded_domains - domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) + domains(:airport).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001', new_contact_id: 'john-001' }, @@ -33,8 +33,8 @@ class APIDomainContactsTest < ApplicationIntegrationTest end def test_return_skipped_domains_in_alphabetical_order - domains(:shop).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) - domains(:airport).update!(statuses: [DomainStatus::DELETE_CANDIDATE]) + domains(:shop).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + domains(:airport).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) patch '/repp/v1/domains/contacts', params: { current_contact_id: 'william-001', new_contact_id: 'john-001' }, From 0f18c1f93ff3841ba00cf884e1264cefd766aa53 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 28 Sep 2021 00:06:20 +0300 Subject: [PATCH 11/12] fixed multiple domains updating --- app/models/registrar.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 598605409..cdab3e1d8 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -175,33 +175,26 @@ class Registrar < ApplicationRecord def add_nameservers(new_attributes, domains: []) transaction do - domain_scope = domains.dup - domain_list = [] - failed_list = [] - return if domains.empty? - domain_list_processing(domain_scope, new_attributes, domain_list, failed_list) + approved_list = domain_list_processing(domains: domains, new_attributes: new_attributes) - 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] + self.domains.where(name: approved_list).find_each(&:update_whois_record) if approved_list.any? + [approved_list.uniq.sort, (domains - approved_list).uniq.sort] end end - def domain_list_processing(domains, new_attributes, domain_list, failed_list) + def domain_list_processing(domains:, new_attributes:) + approved_list = [] domains.each do |domain_name| domain = self.domains.find_by('name = ? OR name_puny = ?', domain_name, domain_name) - if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) - failed_list << domain_name - next - end + next if domain.blank? || domain_not_updatable?(hostname: new_attributes[:hostname], domain: domain) create_nameserver(domain, new_attributes) - - domains.delete_if { |i| i == domain.name || i == domain.name_puny } - domain_list << domain_name + approved_list << domain_name end + approved_list end def create_nameserver(domain, attributes) From d51b41c3e4ad804600b8efd20eaf040069d50f28 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 28 Sep 2021 23:25:04 +0300 Subject: [PATCH 12/12] added tests --- .../repp/v1/registrar/nameservers_test.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/integration/repp/v1/registrar/nameservers_test.rb b/test/integration/repp/v1/registrar/nameservers_test.rb index 11216375d..15e60c710 100644 --- a/test/integration/repp/v1/registrar/nameservers_test.rb +++ b/test/integration/repp/v1/registrar/nameservers_test.rb @@ -57,6 +57,34 @@ class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest assert json[:data][:affected_domains].include? 'shop.test' end + def test_add_nameserver_values_to_array_of_domains + nameserver = nameservers(:shop_ns1) + airport_domain = domains(:airport) + airport_domain.update(statuses: [DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED]) + payload = { + "data": { + "type": 'nameserver', + "domains": ['shop.test', 'airport.test'], + "attributes": { + "hostname": "#{nameserver.hostname}.arraytest", + "ipv4": ['2.2.2.2'] + } + } + } + + put '/repp/v1/registrar/nameservers', headers: @auth_headers, params: payload + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + assert_equal({ hostname: "#{nameserver.hostname}.arraytest", ipv4: ['2.2.2.2'] }, json[:data][:attributes]) + assert json[:data][:affected_domains].include? 'shop.test' + assert json[:data][:affected_domains].include? 'airport.test' + end + def test_fails_to_update_if_prohibited domain = domains(:shop) domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED])