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..6df72eb6ea --- /dev/null +++ b/app/jobs/replace_upd_to_obj_upd_prohibited_job.rb @@ -0,0 +1,40 @@ +class ReplaceUpdToObjUpdProhibitedJob < ApplicationJob + def perform(rollback: false) + logger.info 'Ran ReplaceUpdToObjUpdProhibitedJob!' + + start_replace_status_for_locked_domains(rollback: rollback) + end + + + 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| + if domain.locked_by_registrant? + process_domain_status_replacment(domain: domain, rollback: rollback) + end + end + + logger.info "Successfully proccesed #{count} domains of #{Domain.count}" + end + end + + private + + 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 + + def logger + @logger ||= Logger.new(Rails.root.join('log/replace_upd_to_obj_upd_prohibited.log')) + 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/app/models/registrant_user.rb b/app/models/registrant_user.rb index f7e85c5af5..57a2f58ab9 100644 --- a/app/models/registrant_user.rb +++ b/app/models/registrant_user.rb @@ -23,7 +23,7 @@ def companies(company_register = CompanyRegister::Client.new) 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/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 new file mode 100644 index 0000000000..54c53f11d0 --- /dev/null +++ b/lib/tasks/replace_upd_to_obj_upd_prohibited.rake @@ -0,0 +1,22 @@ +require 'benchmark' + +# 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. + +# 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` + +namespace :locked_domains do + desc 'Replace serverUpdateProhibited to serverObjUpdateProhibited for locked domains' + task replace_new_status: :environment do + ReplaceUpdToObjUpdProhibitedJob.perform_later + end + + 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 new file mode 100644 index 0000000000..16d6ed367b --- /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(extensions_prohibited: false) + assert @domain.locked_by_registrant? + + perform_enqueued_jobs do + ReplaceUpdToObjUpdProhibitedJob.perform_later + end + + @domain.reload + assert @domain.statuses.include? "serverObjUpdateProhibited" + end + + def test_start_adding_new_status_for_locked_domains + @domain.apply_registry_lock(extensions_prohibited: false) + 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 + 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 + 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 + end + + assert @domain.statuses.include? "serverUpdateProhibited" + end +end diff --git a/test/models/feature_test.rb b/test/models/feature_test.rb index 23fd861713..d910ac1404 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(extensions_prohibited: false) + 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