From 45014634347afaa9ee3709a182055ec4518884a1 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 20 Sep 2021 15:17:44 +0300 Subject: [PATCH 1/6] added new task and test for replace new status for locked domains --- .../replace_upd_to_obj_upd_prohibited_job.rb | 35 +++++++++ app/models/registrant_user.rb | 6 +- .../replace_upd_to_obj_upd_prohibited.rake | 42 +++++++++++ ...lace_upd_to_obj_upd_prohibited_job_test.rb | 72 +++++++++++++++++++ 4 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 app/jobs/replace_upd_to_obj_upd_prohibited_job.rb create mode 100644 lib/tasks/replace_upd_to_obj_upd_prohibited.rake create mode 100644 test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb diff --git a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb new file mode 100644 index 0000000000..c0ea92dd66 --- /dev/null +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -0,0 +1,35 @@ +class ReplaceUpdToObjUpdProhibitedJob < ApplicationJob + def perform(mode, rollback = false) + logger.info 'Ran ReplaceUpdToObjUpdProhibitedJob!' + + start_adding_new_status_for_locked_domains(mode, rollback) + end + + private + + def start_adding_new_status_for_locked_domains(mode, rollback) + count = 0 + Domain.all.find_in_batches do |domain_batches| + count += domain_batches.count + logger.info "Proccesing #{count} domains of #{Domain.count}" + + domain_batches.each do |domain| + if domain.locked_by_registrant? + if rollback + domain.statuses = domain.statuses + ["serverUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverUpdateProhibited" + domain.statuses = domain.statuses - ["serverObjUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverObjUpdateProhibited" + else + domain.statuses = domain.statuses + ["serverObjUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverObjUpdateProhibited" + domain.statuses = domain.statuses - ["serverUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverUpdateProhibited" + end + domain.save! + end + end + logger.info "Successfully proccesed #{count} domains of #{Domain.count}" + end + end + + def logger + @logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log')) + end +end diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index f7e85c5af5..c6d80901e8 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -17,11 +17,11 @@ def country Country.new(alpha2_code) end - def companies(company_register = CompanyRegister::Client.new) + def companies(company_register = nil) return [] if ident.include?('-') - company_register.representation_rights(citizen_personal_code: ident, - citizen_country_code: country.alpha3) + [OpenStruct.new(registration_number: '43344412', company_name: 'TestFirma'), + OpenStruct.new(registration_number: '12345678', company_name: 'SuperFirma OU')] end def contacts(representable: true) diff --git a/lib/tasks/replace_upd_to_obj_upd_prohibited.rake b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake new file mode 100644 index 0000000000..2141685de4 --- /dev/null +++ b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake @@ -0,0 +1,42 @@ +require 'benchmark' + +namespace :locked_domains do + + # Add new status instruction! + # First run `rake locked_domains:add_new_status` + # and then after finish first task run `rake locked_domains:remove_old_status` + desc 'Add serverObjUpdateProhibited for locked domains' + task add_new_status: :environment do + time = Benchmark.realtime do + ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + end + puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" + end + + desc 'Remove serverUpdateProhibited from locked domains' + task remove_old_status: :environment do + time = Benchmark.realtime do + ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + end + puts "Time is #{time.round(2)} for remove serverUpdateProhibited for locked domains" + end + + # Rollback instruction! + # First run `rake locked_domains:rollback_remove_old_status` + # and then after finish first task run `rake locked_domains:rollback_add_new_status` + desc 'Rollback remove old serverUpdateProhibited for locked domains' + task rollback_remove_old_status: :environment do + time = Benchmark.realtime do + ReplaceUpdToObjUpdProhibitedJob.perform_later('add', true) + end + puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" + end + + desc 'Rollback add new serverObjUpdateProhibited for locked domains' + task rollback_add_new_status: :environment do + time = Benchmark.realtime do + ReplaceUpdToObjUpdProhibitedJob.perform_later('remove', true) + end + puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" + end +end diff --git a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb new file mode 100644 index 0000000000..6ad2624392 --- /dev/null +++ b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb @@ -0,0 +1,72 @@ +require 'test_helper' + +class ReplaceUpdToObjUpdProhibitedJobTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + + setup do + travel_to Time.zone.parse('2010-07-05') + @domain = domains(:shop) + end + + def test_start_adding_new_status_for_locked_domains + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + + perform_enqueued_jobs do + ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + end + + @domain.reload + assert @domain.statuses.include? "serverObjUpdateProhibited" + end + + def test_start_adding_new_status_for_locked_domains + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + assert @domain.statuses.include? "serverUpdateProhibited" + + @domain.statuses += ["serverObjUpdateProhibited"] + @domain.save + @domain.reload + + assert @domain.statuses.include? "serverObjUpdateProhibited" + + perform_enqueued_jobs do + ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + end + + @domain.reload + + assert_not @domain.statuses.include? "serverUpdateProhibited" + end + + def test_should_not_added_to_non_locked_domain_with_update_prohibited + @domain.statuses += ["serverUpdateProhibited"] + @domain.save + @domain.reload + assert @domain.statuses.include? "serverUpdateProhibited" + + assert_not @domain.locked_by_registrant? + + perform_enqueued_jobs do + ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + end + + assert_not @domain.statuses.include? "serverObjUpdateProhibited" + end + + def test_should_not_removed_from_non_locked_domain_with_update_prohibited + @domain.statuses += ["serverUpdateProhibited"] + @domain.save + @domain.reload + assert @domain.statuses.include? "serverUpdateProhibited" + + assert_not @domain.locked_by_registrant? + + perform_enqueued_jobs do + ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + end + + assert @domain.statuses.include? "serverUpdateProhibited" + end +end \ No newline at end of file From 419e5a587de995c522082e849977b4d8b3bae5cd Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 20 Sep 2021 15:30:30 +0300 Subject: [PATCH 2/6] refactoring --- .../replace_upd_to_obj_upd_prohibited_job.rb | 28 ++++++++++++++++--- app/models/registrant_user.rb | 8 +++--- ...lace_upd_to_obj_upd_prohibited_job_test.rb | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb index c0ea92dd66..8b2b26aefb 100644 --- a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -16,19 +16,39 @@ def start_adding_new_status_for_locked_domains(mode, rollback) domain_batches.each do |domain| if domain.locked_by_registrant? if rollback - domain.statuses = domain.statuses + ["serverUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverUpdateProhibited" - domain.statuses = domain.statuses - ["serverObjUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverObjUpdateProhibited" + domain = rollback_actions(mode, domain) else - domain.statuses = domain.statuses + ["serverObjUpdateProhibited"] if mode == 'add' and !domain.statuses.include? "serverObjUpdateProhibited" - domain.statuses = domain.statuses - ["serverUpdateProhibited"] if mode == 'remove' and domain.statuses.include? "serverUpdateProhibited" + domain = add_actions(mode, domain) end + domain.save! end end + logger.info "Successfully proccesed #{count} domains of #{Domain.count}" end end + def rollback_actions(mode, domain) + if mode == 'add' and !domain.statuses.include? 'serverUpdateProhibited' + domain.statuses = domain.statuses + ['serverUpdateProhibited'] + elsif mode == 'remove' and domain.statuses.include? 'serverObjUpdateProhibited' + domain.statuses = domain.statuses - ['serverObjUpdateProhibited'] + end + + domain + end + + def add_actions(mode, domain) + if mode == 'add' and !domain.statuses.include? 'serverObjUpdateProhibited' + domain.statuses = domain.statuses + ['serverObjUpdateProhibited'] + elsif mode == 'remove' and domain.statuses.include? 'serverUpdateProhibited' + domain.statuses = domain.statuses - ['serverUpdateProhibited'] + end + + domain + end + def logger @logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log')) end diff --git a/app/models/registrant_user.rb b/app/models/registrant_user.rb index c6d80901e8..57a2f58ab9 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -17,13 +17,13 @@ def country Country.new(alpha2_code) end - def companies(company_register = nil) + def companies(company_register = CompanyRegister::Client.new) return [] if ident.include?('-') - [OpenStruct.new(registration_number: '43344412', company_name: 'TestFirma'), - OpenStruct.new(registration_number: '12345678', company_name: 'SuperFirma OU')] + company_register.representation_rights(citizen_personal_code: ident, + citizen_country_code: country.alpha3) end - + def contacts(representable: true) Contact.registrant_user_contacts(self, representable: representable) end diff --git a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb index 6ad2624392..7960fd38fe 100644 --- a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb +++ b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb @@ -69,4 +69,4 @@ def test_should_not_removed_from_non_locked_domain_with_update_prohibited assert @domain.statuses.include? "serverUpdateProhibited" end -end \ No newline at end of file +end From b7b0cf133523440c5f5332906222f6d44f419353 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Mon, 20 Sep 2021 16:07:06 +0300 Subject: [PATCH 3/6] refactoring --- .../replace_upd_to_obj_upd_prohibited_job.rb | 46 ++++++++++--------- .../replace_upd_to_obj_upd_prohibited.rake | 8 ++-- ...lace_upd_to_obj_upd_prohibited_job_test.rb | 8 ++-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb index 8b2b26aefb..a7f0ae9d1e 100644 --- a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -1,52 +1,54 @@ class ReplaceUpdToObjUpdProhibitedJob < ApplicationJob - def perform(mode, rollback = false) + def perform(action:, rollback: false) logger.info 'Ran ReplaceUpdToObjUpdProhibitedJob!' - start_adding_new_status_for_locked_domains(mode, rollback) + start_adding_new_status_for_locked_domains(action: action, rollback: rollback) end private - def start_adding_new_status_for_locked_domains(mode, rollback) + def start_adding_new_status_for_locked_domains(action:, rollback:) count = 0 Domain.all.find_in_batches do |domain_batches| count += domain_batches.count logger.info "Proccesing #{count} domains of #{Domain.count}" domain_batches.each do |domain| - if domain.locked_by_registrant? - if rollback - domain = rollback_actions(mode, domain) - else - domain = add_actions(mode, domain) - end - - domain.save! - end + make_actions_with_statuses(domain: domain, action: action, rollback: rollback) end logger.info "Successfully proccesed #{count} domains of #{Domain.count}" end end - def rollback_actions(mode, domain) - if mode == 'add' and !domain.statuses.include? 'serverUpdateProhibited' + private + + def make_actions_with_statuses(domain:, action:, rollback:) + if domain.locked_by_registrant? && rollback + rollback_actions(action: action, domain: domain) + elsif domain.locked_by_registrant? && !rollback + add_actions(action: action, domain: domain) + end + end + + def rollback_actions(action:, domain:) + if action == :add && !domain.statuses.include?('serverUpdateProhibited') domain.statuses = domain.statuses + ['serverUpdateProhibited'] - elsif mode == 'remove' and domain.statuses.include? 'serverObjUpdateProhibited' + domain.save! + elsif action == :remove && domain.statuses.include?('serverObjUpdateProhibited') domain.statuses = domain.statuses - ['serverObjUpdateProhibited'] + domain.save! end - - domain end - def add_actions(mode, domain) - if mode == 'add' and !domain.statuses.include? 'serverObjUpdateProhibited' + def add_actions(action:, domain:) + if action == :add && !domain.statuses.include?('serverObjUpdateProhibited') domain.statuses = domain.statuses + ['serverObjUpdateProhibited'] - elsif mode == 'remove' and domain.statuses.include? 'serverUpdateProhibited' + domain.save! + elsif action == :remove && domain.statuses.include?('serverUpdateProhibited') domain.statuses = domain.statuses - ['serverUpdateProhibited'] + domain.save! end - - domain end def logger diff --git a/lib/tasks/replace_upd_to_obj_upd_prohibited.rake b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake index 2141685de4..3065eaa363 100644 --- a/lib/tasks/replace_upd_to_obj_upd_prohibited.rake +++ b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake @@ -8,7 +8,7 @@ namespace :locked_domains do desc 'Add serverObjUpdateProhibited for locked domains' task add_new_status: :environment do time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) end puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" end @@ -16,7 +16,7 @@ namespace :locked_domains do desc 'Remove serverUpdateProhibited from locked domains' task remove_old_status: :environment do time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) end puts "Time is #{time.round(2)} for remove serverUpdateProhibited for locked domains" end @@ -27,7 +27,7 @@ namespace :locked_domains do desc 'Rollback remove old serverUpdateProhibited for locked domains' task rollback_remove_old_status: :environment do time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later('add', true) + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add, rollback: true) end puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" end @@ -35,7 +35,7 @@ namespace :locked_domains do desc 'Rollback add new serverObjUpdateProhibited for locked domains' task rollback_add_new_status: :environment do time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later('remove', true) + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove, rollback: true) end puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" end diff --git a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb index 7960fd38fe..faeee127b4 100644 --- a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb +++ b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb @@ -13,7 +13,7 @@ def test_start_adding_new_status_for_locked_domains assert @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) end @domain.reload @@ -32,7 +32,7 @@ def test_start_adding_new_status_for_locked_domains assert @domain.statuses.include? "serverObjUpdateProhibited" perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) end @domain.reload @@ -49,7 +49,7 @@ def test_should_not_added_to_non_locked_domain_with_update_prohibited assert_not @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later('add') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) end assert_not @domain.statuses.include? "serverObjUpdateProhibited" @@ -64,7 +64,7 @@ def test_should_not_removed_from_non_locked_domain_with_update_prohibited assert_not @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later('remove') + ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) end assert @domain.statuses.include? "serverUpdateProhibited" From 651f542fcb3ca2665db13076997c04d6aaa2b063 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 21 Sep 2021 12:19:55 +0300 Subject: [PATCH 4/6] updated log output file --- app/jobs/replace_upd_to_obj_upd_prohibited_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb index a7f0ae9d1e..a3eb5a2db3 100644 --- a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -52,6 +52,6 @@ def add_actions(action:, domain:) end def logger - @logger ||= Logger.new(Rails.root.join('log/migrate_before_force_delete_statuses.log')) + @logger ||= Logger.new(Rails.root.join('log/replace_upd_to_obj_upd_prohibited.log')) end end From 41ee61d57ae96a7372cc9cdae83acb85cf14843b Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 22 Sep 2021 12:56:14 +0300 Subject: [PATCH 5/6] refactored task --- .../replace_upd_to_obj_upd_prohibited_job.rb | 43 +++++------------ .../concerns/domain/registry_lockable.rb | 2 +- app/models/feature.rb | 6 +++ config/application.yml.sample | 1 + .../replace_upd_to_obj_upd_prohibited.rake | 48 ++++++------------- ...lace_upd_to_obj_upd_prohibited_job_test.rb | 16 +++---- test/models/feature_test.rb | 23 +++++++++ 7 files changed, 66 insertions(+), 73 deletions(-) diff --git a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb index a3eb5a2db3..6df72eb6ea 100644 --- a/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -1,20 +1,21 @@ class ReplaceUpdToObjUpdProhibitedJob < ApplicationJob - def perform(action:, rollback: false) + def perform(rollback: false) logger.info 'Ran ReplaceUpdToObjUpdProhibitedJob!' - start_adding_new_status_for_locked_domains(action: action, rollback: rollback) + start_replace_status_for_locked_domains(rollback: rollback) end - private - def start_adding_new_status_for_locked_domains(action:, rollback:) + def start_replace_status_for_locked_domains(rollback:) count = 0 Domain.all.find_in_batches do |domain_batches| count += domain_batches.count logger.info "Proccesing #{count} domains of #{Domain.count}" domain_batches.each do |domain| - make_actions_with_statuses(domain: domain, action: action, rollback: rollback) + if domain.locked_by_registrant? + process_domain_status_replacment(domain: domain, rollback: rollback) + end end logger.info "Successfully proccesed #{count} domains of #{Domain.count}" @@ -23,31 +24,13 @@ def start_adding_new_status_for_locked_domains(action:, rollback:) private - def make_actions_with_statuses(domain:, action:, rollback:) - if domain.locked_by_registrant? && rollback - rollback_actions(action: action, domain: domain) - elsif domain.locked_by_registrant? && !rollback - add_actions(action: action, domain: domain) - end - end - - def rollback_actions(action:, domain:) - if action == :add && !domain.statuses.include?('serverUpdateProhibited') - domain.statuses = domain.statuses + ['serverUpdateProhibited'] - domain.save! - elsif action == :remove && domain.statuses.include?('serverObjUpdateProhibited') - domain.statuses = domain.statuses - ['serverObjUpdateProhibited'] - domain.save! - end - end - - def add_actions(action:, domain:) - if action == :add && !domain.statuses.include?('serverObjUpdateProhibited') - domain.statuses = domain.statuses + ['serverObjUpdateProhibited'] - domain.save! - elsif action == :remove && domain.statuses.include?('serverUpdateProhibited') - domain.statuses = domain.statuses - ['serverUpdateProhibited'] - domain.save! + def process_domain_status_replacment(domain:, rollback:) + domain.statuses = domain.statuses - ["serverUpdateProhibited"] + ["serverObjUpdateProhibited"] unless rollback + domain.statuses = domain.statuses - ["serverObjUpdateProhibited"] + ["serverUpdateProhibited"] if rollback + if domain.save + logger.info "#{domain.name} has next statuses #{domain.statuses}" + else + logger.warn "#{domain.name} - something goes wrong!" end end diff --git a/app/models/concerns/domain/registry_lockable.rb b/app/models/concerns/domain/registry_lockable.rb index 24c53b7be9..db41e763a0 100644 --- a/app/models/concerns/domain/registry_lockable.rb +++ b/app/models/concerns/domain/registry_lockable.rb @@ -1,7 +1,7 @@ module Domain::RegistryLockable extend ActiveSupport::Concern - LOCK_STATUSES = if Feature.obj_and_extensions_statuses_enabled? + LOCK_STATUSES = if Feature.enable_lock_domain_with_new_statuses? [DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED, DomainStatus::SERVER_DELETE_PROHIBITED, DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze diff --git a/app/models/feature.rb b/app/models/feature.rb index 0989490459..f14eefa4d6 100644 --- a/app/models/feature.rb +++ b/app/models/feature.rb @@ -4,4 +4,10 @@ def self.obj_and_extensions_statuses_enabled? ENV['obj_and_extensions_prohibited'] || false end + + def self.enable_lock_domain_with_new_statuses? + return false if ENV['enable_lock_domain_with_new_statuses'] == 'false' + + ENV['enable_lock_domain_with_new_statuses'] || false + end end diff --git a/config/application.yml.sample b/config/application.yml.sample index 7d0cbc8644..1da894b5f2 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -60,6 +60,7 @@ contact_org_enabled: 'false' # legal_document_types: "pdf,asice,sce,asics,scs,adoc,edoc,bdoc,ddoc,zip,rar,gz,tar,7z,odt,doc,docx" # obj_and_extensions_prohibited: 'true' +# enable_lock_domain_with_new_statuses: 'true' # # REGISTRAR configuration (DEPP) diff --git a/lib/tasks/replace_upd_to_obj_upd_prohibited.rake b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake index 3065eaa363..54c53f11d0 100644 --- a/lib/tasks/replace_upd_to_obj_upd_prohibited.rake +++ b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake @@ -1,42 +1,22 @@ require 'benchmark' -namespace :locked_domains do +# INSTRUCTIONS: +# The task works as follows, it finds a domain that has a domain lock mark and replaces the status serverUpdateProhibited with serverObjUpdateProhibited +# For run this task it need to type `rake locked_domains:replace_new_status` +# Whole results will saved into log/replace_upd_to_obj_upd_prohibited.log +# It need to make sure before launching that these statuses mean that the domain has a domain lock, otherwise this scanner will not find the required domains. +# Therefore, it is better that the value `enable_lock_domain_with_new_statuses` in the `application.yml` file is commented out or has the status false before starting. After the task has been completed, set the value `enable_lock_domain_with_new_statuses` to true, and then the domain with the following statuses `serverDeleteProhibited, serverTransferProhibited, serverObjUpdateProhibite` will be considered blocked now. - # Add new status instruction! - # First run `rake locked_domains:add_new_status` - # and then after finish first task run `rake locked_domains:remove_old_status` - desc 'Add serverObjUpdateProhibited for locked domains' - task add_new_status: :environment do - time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) - end - puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" - end +# If for some reason it need to roll back the result, then this value `enable_lock_domain_with_new_statuses` must be true, and run the command `rake locked_domains:rollback_replacement_new_status` - desc 'Remove serverUpdateProhibited from locked domains' - task remove_old_status: :environment do - time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) - end - puts "Time is #{time.round(2)} for remove serverUpdateProhibited for locked domains" - end - - # Rollback instruction! - # First run `rake locked_domains:rollback_remove_old_status` - # and then after finish first task run `rake locked_domains:rollback_add_new_status` - desc 'Rollback remove old serverUpdateProhibited for locked domains' - task rollback_remove_old_status: :environment do - time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add, rollback: true) - end - puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" +namespace :locked_domains do + desc 'Replace serverUpdateProhibited to serverObjUpdateProhibited for locked domains' + task replace_new_status: :environment do + ReplaceUpdToObjUpdProhibitedJob.perform_later end - desc 'Rollback add new serverObjUpdateProhibited for locked domains' - task rollback_add_new_status: :environment do - time = Benchmark.realtime do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove, rollback: true) - end - puts "Time is #{time.round(2)} for add serverObjUpdateProhibited status for locked domains" + desc 'Replace serverObjUpdateProhibited to serverUpdateProhibited for locked domains' + task rollback_replacement_new_status: :environment do + ReplaceUpdToObjUpdProhibitedJob.perform_later(rollback: true) end end diff --git a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb index faeee127b4..3cc4c38828 100644 --- a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb +++ b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb @@ -13,7 +13,7 @@ def test_start_adding_new_status_for_locked_domains assert @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) + ReplaceUpdToObjUpdProhibitedJob.perform_later end @domain.reload @@ -25,14 +25,14 @@ def test_start_adding_new_status_for_locked_domains assert @domain.locked_by_registrant? assert @domain.statuses.include? "serverUpdateProhibited" - @domain.statuses += ["serverObjUpdateProhibited"] - @domain.save - @domain.reload + # @domain.statuses += ["serverObjUpdateProhibited"] + # @domain.save + # @domain.reload - assert @domain.statuses.include? "serverObjUpdateProhibited" + # assert @domain.statuses.include? "serverObjUpdateProhibited" perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) + ReplaceUpdToObjUpdProhibitedJob.perform_later end @domain.reload @@ -49,7 +49,7 @@ def test_should_not_added_to_non_locked_domain_with_update_prohibited assert_not @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :add) + ReplaceUpdToObjUpdProhibitedJob.perform_later end assert_not @domain.statuses.include? "serverObjUpdateProhibited" @@ -64,7 +64,7 @@ def test_should_not_removed_from_non_locked_domain_with_update_prohibited assert_not @domain.locked_by_registrant? perform_enqueued_jobs do - ReplaceUpdToObjUpdProhibitedJob.perform_later(action: :remove) + ReplaceUpdToObjUpdProhibitedJob.perform_later end assert @domain.statuses.include? "serverUpdateProhibited" diff --git a/test/models/feature_test.rb b/test/models/feature_test.rb index 23fd861713..9e493e2a6f 100644 --- a/test/models/feature_test.rb +++ b/test/models/feature_test.rb @@ -1,6 +1,11 @@ require 'test_helper' class FeatureTest < ActiveSupport::TestCase + setup do + @domain = domains(:shop) + @domain.apply_registry_lock + end + def test_if_obj_and_extensions_prohibited_enabled ENV['obj_and_extensions_prohibited'] = 'true' @@ -27,4 +32,22 @@ def test_if_obj_and_extensions_prohibited_is_false statuses = DomainStatus.admin_statuses assert_not statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED end + + def test_if_enable_lock_domain_with_new_statuses_is_nil + ENV['enable_lock_domain_with_new_statuses'] = nil + + assert_not Feature.enable_lock_domain_with_new_statuses? + + assert_equal @domain.statuses, ["serverUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"] + assert @domain.locked_by_registrant? + end + + def test_if_enable_lock_domain_with_new_statuses_is_false + ENV['enable_lock_domain_with_new_statuses'] = 'false' + + assert_not Feature.enable_lock_domain_with_new_statuses? + + assert_equal @domain.statuses, ["serverUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"] + assert @domain.locked_by_registrant? + end end From c34e775acd70eb3f1759410ab0df479e92f97565 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 23 Sep 2021 17:00:24 +0300 Subject: [PATCH 6/6] updated tests --- test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb | 4 ++-- test/models/feature_test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb index 3cc4c38828..16d6ed367b 100644 --- a/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb +++ b/test/jobs/replace_upd_to_obj_upd_prohibited_job_test.rb @@ -9,7 +9,7 @@ class ReplaceUpdToObjUpdProhibitedJobTest < ActiveSupport::TestCase end def test_start_adding_new_status_for_locked_domains - @domain.apply_registry_lock + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? perform_enqueued_jobs do @@ -21,7 +21,7 @@ def test_start_adding_new_status_for_locked_domains end def test_start_adding_new_status_for_locked_domains - @domain.apply_registry_lock + @domain.apply_registry_lock(extensions_prohibited: false) assert @domain.locked_by_registrant? assert @domain.statuses.include? "serverUpdateProhibited" diff --git a/test/models/feature_test.rb b/test/models/feature_test.rb index 9e493e2a6f..d910ac1404 100644 --- a/test/models/feature_test.rb +++ b/test/models/feature_test.rb @@ -3,7 +3,7 @@ class FeatureTest < ActiveSupport::TestCase setup do @domain = domains(:shop) - @domain.apply_registry_lock + @domain.apply_registry_lock(extensions_prohibited: false) end def test_if_obj_and_extensions_prohibited_enabled