From 1885ddf7494f4af7150dcbadccc08f8cf7ac0556 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 7 Jul 2021 09:34:06 +0300 Subject: [PATCH 01/43] fix bind_invoice method --- app/models/bank_transaction.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 734075ac3..5b4f30adf 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -60,7 +60,7 @@ class BankTransaction < ApplicationRecord invoice = Invoice.find_by(number: invoice_no) errors.add(:base, I18n.t('invoice_was_not_found')) unless invoice - validate_invoice_data(invoice) + validate_invoice_data(invoice) if invoice return if errors.any? create_internal_payment_record(channel: (manual ? 'admin_payment' : nil), invoice: invoice, From 9c6527d6d3ffbfd7a16fd141909afb5809568495 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 7 Jul 2021 15:38:08 +0500 Subject: [PATCH 02/43] Mask orphan notification as read --- app/controllers/epp/polls_controller.rb | 1 + test/integration/epp/poll_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index 86218336b..01cb719c4 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -27,6 +27,7 @@ module Epp Rails.logger.error 'orphan message, error ignored: ' + problem.to_s # now we should dequeue or delete the messages avoid duplicate log alarms + @notification.mark_as_read end end diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index 5cdb7e524..e3fbb0daf 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -26,6 +26,31 @@ class EppPollTest < EppTestCase assert_equal 'Your domain has been updated', xml_doc.at_css('msgQ msg').text end + def test_clears_orphan_messages_if_any + # To check if we are clearing orphan messages we need to create a message not linked to any + # existing Epp::Domain + + orphan_notification = @notification.dup + orphan_notification.attached_obj_type = Epp::Domain + orphan_notification.attached_obj_id = rand(Epp::Domain.first.id-1) + orphan_notification.save! + assert orphan_notification.unread? + + request_xml = <<-XML + + + + + + + XML + post epp_poll_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + orphan_notification.reload + refute orphan_notification.unread? + end + def test_does_not_drop_error_if_old_version version = Version::DomainVersion.last @notification.update(attached_obj_type: 'DomainVersion', attached_obj_id: version.id) From 86c7496addc3c4313903952a985726276b7ba728 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 7 Jul 2021 17:52:26 +0500 Subject: [PATCH 03/43] Fix empty statuses_before_force_delete error --- .../restore_statuses_before_force_delete.rb | 2 +- .../epp/domain/update/base_test.rb | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb b/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb index c55c06764..792b63a86 100644 --- a/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb +++ b/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb @@ -2,7 +2,7 @@ module Domains module CancelForceDelete class RestoreStatusesBeforeForceDelete < Base def execute - domain.statuses = domain.statuses_before_force_delete + domain.statuses = domain.statuses_before_force_delete || [] domain.statuses_before_force_delete = nil domain.save(validate: false) end diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index 644619644..bff325307 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -588,6 +588,50 @@ class EppDomainUpdateBaseTest < EppTestCase assert_no_emails end + def test_makes_update_if_was_forcedelete + contact = @domain.contacts.first + contact.update_attribute(:email, '`@outlook.test') + contact.email_verification.verify + assert contact.email_verification_failed? + @domain.reload + assert @domain.force_delete_scheduled? + + @domain.update_attribute(:statuses_before_force_delete, nil) + + Setting.request_confirmation_on_registrant_change_enabled = true + new_registrant = contacts(:william).becomes(Registrant) + assert_not_equal new_registrant, @domain.registrant + + request_xml = <<-XML + + + + + + #{@domain.name} + + #{new_registrant.code} + + + + + + #{'test' * 2000} + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + @domain.reload + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + assert_epp_response :completed_successfully + end + def test_clears_force_delete_when_registrar_changed Setting.request_confirmation_on_registrant_change_enabled = true new_registrant = contacts(:william).becomes(Registrant) From 405e6804ccd5da49e3be80bfca0f3603c5e372f5 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 7 Jul 2021 18:22:14 +0300 Subject: [PATCH 04/43] fixes by review result --- app/models/bank_transaction.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 5b4f30adf..ae4fbf51b 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -59,8 +59,7 @@ class BankTransaction < ApplicationRecord end invoice = Invoice.find_by(number: invoice_no) - errors.add(:base, I18n.t('invoice_was_not_found')) unless invoice - validate_invoice_data(invoice) if invoice + validate_invoice_data(invoice) return if errors.any? create_internal_payment_record(channel: (manual ? 'admin_payment' : nil), invoice: invoice, @@ -68,6 +67,11 @@ class BankTransaction < ApplicationRecord end def validate_invoice_data(invoice) + unless invoice + errors.add(:base, I18n.t('invoice_was_not_found')) + return + end + if invoice.paid? errors.add(:base, I18n.t('invoice_is_already_binded')) return From 6643081c1880a8dbeace19f50189c310106b7ea5 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 8 Jul 2021 00:06:46 +0300 Subject: [PATCH 05/43] added test --- test/models/bank_transaction_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/models/bank_transaction_test.rb b/test/models/bank_transaction_test.rb index 9a9b02a74..46ac54d3c 100644 --- a/test/models/bank_transaction_test.rb +++ b/test/models/bank_transaction_test.rb @@ -136,6 +136,12 @@ class BankTransactionTest < ActiveSupport::TestCase assert transaction.errors.full_messages.include?('Invoice and transaction sums do not match') end + def test_binds_without_invoice_no + transaction = BankTransaction.new(sum: 9) + transaction.bind_invoice('') + assert transaction.errors.full_messages.include?('Invoice was not found') + end + def test_overpayment_is_not_matched_with_invoice create_payable_invoice(number: '2222', total: 10) transaction = BankTransaction.new(sum: 11) From 77d2e402b418a4b370cded6aa7c713dd8bf85099 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 8 Jul 2021 15:49:31 +0300 Subject: [PATCH 06/43] added validation and tests --- app/models/epp/contact.rb | 20 ++++++ config/locales/epp/contacts.en.yml | 6 ++ .../epp/contact/create/base_test.rb | 61 +++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 6bd5507b9..e98e88368 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -16,6 +16,26 @@ class Epp::Contact < Contact throw(:abort) end + validate :validate_birthday_ident + + def validate_birthday_ident + return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type) + + if (Date.parse(ident) rescue ArgumentError) == ArgumentError + add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format')) + @error = true + return + end + + contact_ident_date = Date.parse(ident) + valid_time_range = (Date.today - 125.years)...(Date.tomorrow - 18.years) + return if valid_time_range.cover?(contact_ident_date) + + add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range')) + @error = true + nil + end + class << self # support legacy search def find_by_epp_code(code) diff --git a/config/locales/epp/contacts.en.yml b/config/locales/epp/contacts.en.yml index fe4ed7ccf..1da66f31d 100644 --- a/config/locales/epp/contacts.en.yml +++ b/config/locales/epp/contacts.en.yml @@ -8,6 +8,12 @@ en: valid_ident: >- Ident update is not allowed. Consider creating new contact object + valid_ident_date_format: >- + Ident update is not allowed. + Date format is invalid + valid_ident_date_range: >- + Ident update is not allowed. + Age must be over 18 and under 125 ident_update: >- Only ident type and country can be updated in case of invalid ident. Please create new contact object to update ident code diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index b2b65a7ef..956735257 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -81,6 +81,67 @@ class EppContactCreateBaseTest < EppTestCase assert_epp_response :parameter_value_syntax_error end + def test_responses_with_error_on_invalid_birthday_date + name = 'new' + email = 'new@registrar.test' + phone = '+1.2' + birthday_wrong_format = '1111-22-33' + birthday_above_valid_range = '1800-01-01' + birthday_below_valid_range = '2008-07-09' + + request_xml = <<-XML + + + + + + + #{name} + + #{phone} + #{email} + + + + + #{birthday_wrong_format} + + + + + XML + + + assert_no_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + assert_epp_response :data_management_policy_violation + + request_xml.sub! ">#{birthday_wrong_format}<", ">#{birthday_above_valid_range}<" + assert_no_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + assert_epp_response :data_management_policy_violation + + request_xml.sub! ">#{birthday_above_valid_range}<", ">#{birthday_below_valid_range}<" + assert_no_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + assert_epp_response :data_management_policy_violation + end + def test_responces_error_with_email_error name = 'new' email = 'new@registrar@test' From fb352fb718df4bfa168d320ae6861988fbc6ba9f Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 8 Jul 2021 16:20:13 +0300 Subject: [PATCH 07/43] added migration and new json field for store domain statuses history --- ...814_add_json_statuses_history_field_to_domain.rb | 6 ++++++ db/structure.sql | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb diff --git a/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb new file mode 100644 index 000000000..0f177683b --- /dev/null +++ b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb @@ -0,0 +1,6 @@ +class AddJsonStatusesHistoryFieldToDomain < ActiveRecord::Migration[6.1] + def change + add_column :domains, :json_statuses_history, :jsonb + add_index :domains, :json_statuses_history, using: :gin + end +end diff --git a/db/structure.sql b/db/structure.sql index 481732b8a..54d740fa5 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -933,7 +933,8 @@ CREATE TABLE public.domains ( uuid uuid DEFAULT public.gen_random_uuid() NOT NULL, locked_by_registrant_at timestamp without time zone, force_delete_start timestamp without time zone, - force_delete_data public.hstore + force_delete_data public.hstore, + json_statuses_history jsonb ); @@ -3985,6 +3986,13 @@ CREATE INDEX index_domain_transfers_on_domain_id ON public.domain_transfers USIN CREATE INDEX index_domains_on_delete_date ON public.domains USING btree (delete_date); +-- +-- Name: index_domains_on_json_statuses_history; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_domains_on_json_statuses_history ON public.domains USING gin (json_statuses_history); + + -- -- Name: index_domains_on_name; Type: INDEX; Schema: public; Owner: - -- @@ -5152,6 +5160,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200917104213'), ('20200921084356'), ('20210215101019'), -('20210616112332'); +('20210616112332'), +('20210708131814'); From d750ca2403c4a1f1fc883e6797e557beabe9d663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 8 Jul 2021 16:31:15 +0300 Subject: [PATCH 08/43] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ffb7787..9076a1434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +08.07.2021 +* improved contact name validation [#1795](https://github.com/internetee/registry/issues/1795) + 06.07.2021 * admin dropdown filter ui fix [#2065](https://github.com/internetee/registry/issues/2065) * Bump truemail to 2.4.4 [#2071](https://github.com/internetee/registry/pull/2071) From 7877534589caba29b735739519f3dc2a540dcb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 8 Jul 2021 17:01:08 +0300 Subject: [PATCH 09/43] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9076a1434..b20121a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ 08.07.2021 * improved contact name validation [#1795](https://github.com/internetee/registry/issues/1795) +* orphaned poll messages are automatically dequed [#2026](https://github.com/internetee/registry/issues/2026) 06.07.2021 * admin dropdown filter ui fix [#2065](https://github.com/internetee/registry/issues/2065) From 5bed817c354814e5426dc0c12e565166a6135db5 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 8 Jul 2021 17:07:43 +0300 Subject: [PATCH 10/43] fixes by review and codeclimat --- app/models/epp/contact.rb | 11 +++++++++-- config/locales/epp/contacts.en.yml | 2 +- test/integration/epp/contact/create/base_test.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index e98e88368..57c4d033a 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -8,6 +8,9 @@ class Epp::Contact < Contact # disable STI, there is type column present self.inheritance_column = :sti_disabled + VALID_BIRTH_DATE_FROM = Time.zone.today - 150.years + VALID_BIRTH_DATE_TO = Time.zone.tomorrow + before_validation :manage_permissions def manage_permissions @@ -21,14 +24,18 @@ class Epp::Contact < Contact def validate_birthday_ident return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type) - if (Date.parse(ident) rescue ArgumentError) == ArgumentError + if begin + Date.parse(ident) + rescue StandardError + ArgumentError + end == ArgumentError add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format')) @error = true return end contact_ident_date = Date.parse(ident) - valid_time_range = (Date.today - 125.years)...(Date.tomorrow - 18.years) + valid_time_range = VALID_BIRTH_DATE_FROM...VALID_BIRTH_DATE_TO return if valid_time_range.cover?(contact_ident_date) add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range')) diff --git a/config/locales/epp/contacts.en.yml b/config/locales/epp/contacts.en.yml index 1da66f31d..341630299 100644 --- a/config/locales/epp/contacts.en.yml +++ b/config/locales/epp/contacts.en.yml @@ -13,7 +13,7 @@ en: Date format is invalid valid_ident_date_range: >- Ident update is not allowed. - Age must be over 18 and under 125 + Age must be over 0 and under 150 ident_update: >- Only ident type and country can be updated in case of invalid ident. Please create new contact object to update ident code diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index 956735257..5d965596a 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -87,7 +87,7 @@ class EppContactCreateBaseTest < EppTestCase phone = '+1.2' birthday_wrong_format = '1111-22-33' birthday_above_valid_range = '1800-01-01' - birthday_below_valid_range = '2008-07-09' + birthday_below_valid_range = '2050-07-09' request_xml = <<-XML From 33a855fbe7b15eff11b4634c016c33baf13b8271 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 8 Jul 2021 17:56:42 +0300 Subject: [PATCH 11/43] codeclimate fixes --- app/models/epp/contact.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 57c4d033a..6f53eaed5 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -24,11 +24,9 @@ class Epp::Contact < Contact def validate_birthday_ident return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type) - if begin + begin Date.parse(ident) - rescue StandardError - ArgumentError - end == ArgumentError + rescue ArgumentError add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format')) @error = true return From b0df8f230eb28f31842a12aaf5d4c1528e461840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 8 Jul 2021 19:43:47 +0300 Subject: [PATCH 12/43] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b20121a0a..9711c3ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 08.07.2021 * improved contact name validation [#1795](https://github.com/internetee/registry/issues/1795) * orphaned poll messages are automatically dequed [#2026](https://github.com/internetee/registry/issues/2026) +* fixed registrant change with force delete set [#2077](https://github.com/internetee/registry/issues/2077) 06.07.2021 * admin dropdown filter ui fix [#2065](https://github.com/internetee/registry/issues/2065) From a02a6c99cb9e990a63ee181bceb9d6550ffd3251 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 9 Jul 2021 09:24:51 +0300 Subject: [PATCH 13/43] fixed undefined method settings error --- app/models/bank_transaction.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index ae4fbf51b..3377d06b8 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -106,7 +106,7 @@ class BankTransaction < ApplicationRecord private def reset_pending_registrar_balance_reload - return unless registrar.settings['balance_auto_reload'] + return unless registrar.present? && registrar.settings['balance_auto_reload'] registrar.settings['balance_auto_reload'].delete('pending') registrar.save! From d260eacc1a1fb6a8facb7bf66dda8d0163345eb0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 9 Jul 2021 12:09:20 +0300 Subject: [PATCH 14/43] added tasks for migrate data and tests --- ...igrate_before_force_delete_statuses_job.rb | 9 +++++++ .../migrate_statuses_to_domain_history_job.rb | 9 +++++++ app/models/domain.rb | 4 +++ lib/tasks/migrate_domain_statuses.rake | 10 +++++++ ...e_before_force_delete_statuses_job_test.rb | 27 +++++++++++++++++++ ...ate_statuses_to_domain_history_job_test.rb | 22 +++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 app/jobs/migrate_before_force_delete_statuses_job.rb create mode 100644 app/jobs/migrate_statuses_to_domain_history_job.rb create mode 100644 lib/tasks/migrate_domain_statuses.rake create mode 100644 test/jobs/migrate_before_force_delete_statuses_job_test.rb create mode 100644 test/jobs/migrate_statuses_to_domain_history_job_test.rb diff --git a/app/jobs/migrate_before_force_delete_statuses_job.rb b/app/jobs/migrate_before_force_delete_statuses_job.rb new file mode 100644 index 000000000..ba34eae3b --- /dev/null +++ b/app/jobs/migrate_before_force_delete_statuses_job.rb @@ -0,0 +1,9 @@ +class MigrateBeforeForceDeleteStatusesJob < ApplicationJob + def perform + domains = Domain.where.not(statuses_before_force_delete: nil) + domains.each do |domain| + domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete + domain.save + end + end +end diff --git a/app/jobs/migrate_statuses_to_domain_history_job.rb b/app/jobs/migrate_statuses_to_domain_history_job.rb new file mode 100644 index 000000000..b5cc0a858 --- /dev/null +++ b/app/jobs/migrate_statuses_to_domain_history_job.rb @@ -0,0 +1,9 @@ +class MigrateStatusesToDomainHistoryJob < ApplicationJob + def perform + domains = Domain.all.select { |d| !d.locked_by_registrant? } + domains.each do |domain| + domain.admin_store_statuses_history = domain.statuses + domain.save + end + end +end diff --git a/app/models/domain.rb b/app/models/domain.rb index 5601167a2..519f33575 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -22,6 +22,10 @@ class Domain < ApplicationRecord alias_attribute :auth_info, :transfer_code # Old attribute name; for PaperTrail alias_attribute :registered_at, :created_at + store_accessor :json_statuses_history, + :force_delete_domain_statuses_history, + :admin_store_statuses_history + # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? diff --git a/lib/tasks/migrate_domain_statuses.rake b/lib/tasks/migrate_domain_statuses.rake new file mode 100644 index 000000000..8c68f9e70 --- /dev/null +++ b/lib/tasks/migrate_domain_statuses.rake @@ -0,0 +1,10 @@ +namespace :migrate_domain_statuses do + desc 'Starts collect invalid validation contacts' + task fd_domains: :environment do + MigrateBeforeForceDeleteStatusesJob.perform_later + end + + task admin_status_history: :environment do + MigrateStatusesToDomainHistoryJob.perform_later + end +end diff --git a/test/jobs/migrate_before_force_delete_statuses_job_test.rb b/test/jobs/migrate_before_force_delete_statuses_job_test.rb new file mode 100644 index 000000000..0288a686c --- /dev/null +++ b/test/jobs/migrate_before_force_delete_statuses_job_test.rb @@ -0,0 +1,27 @@ +require 'test_helper' + +class MigrateBeforeForceDeleteStatusesJobTest < ActiveJob::TestCase + setup do + travel_to Time.zone.parse('2010-07-05') + @domain = domains(:shop) + end + + def test_migrate_data_before_force_delete + @domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + @domain.reload + assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + + @domain.schedule_force_delete(type: :soft) + @domain.reload + + assert @domain.force_delete_scheduled? + + perform_enqueued_jobs do + MigrateBeforeForceDeleteStatusesJob.perform_later + end + + @domain.reload + + assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED + end +end diff --git a/test/jobs/migrate_statuses_to_domain_history_job_test.rb b/test/jobs/migrate_statuses_to_domain_history_job_test.rb new file mode 100644 index 000000000..dcacc327a --- /dev/null +++ b/test/jobs/migrate_statuses_to_domain_history_job_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class MigrateBeforeForceDeleteStatusesJobTest < ActiveJob::TestCase + setup do + travel_to Time.zone.parse('2010-07-05') + @domain = domains(:shop) + end + + def test_migrate_statuses_to_domain_history_job + @domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) + @domain.reload + assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + + perform_enqueued_jobs do + MigrateStatusesToDomainHistoryJob.perform_later + end + + @domain.reload + + assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED + end +end From 8063d538a637188abcdefd7abd80ca11be5f2789 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 9 Jul 2021 16:28:48 +0300 Subject: [PATCH 15/43] refactoring --- app/jobs/migrate_before_force_delete_statuses_job.rb | 8 +++++--- app/jobs/migrate_statuses_to_domain_history_job.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/jobs/migrate_before_force_delete_statuses_job.rb b/app/jobs/migrate_before_force_delete_statuses_job.rb index ba34eae3b..d7f6c0606 100644 --- a/app/jobs/migrate_before_force_delete_statuses_job.rb +++ b/app/jobs/migrate_before_force_delete_statuses_job.rb @@ -1,9 +1,11 @@ class MigrateBeforeForceDeleteStatusesJob < ApplicationJob def perform domains = Domain.where.not(statuses_before_force_delete: nil) - domains.each do |domain| - domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete - domain.save + domains.find_in_batches do |domain_batches| + domain_batches.each do |domain| + domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete + domain.save + end end end end diff --git a/app/jobs/migrate_statuses_to_domain_history_job.rb b/app/jobs/migrate_statuses_to_domain_history_job.rb index b5cc0a858..870a9cf55 100644 --- a/app/jobs/migrate_statuses_to_domain_history_job.rb +++ b/app/jobs/migrate_statuses_to_domain_history_job.rb @@ -1,6 +1,6 @@ class MigrateStatusesToDomainHistoryJob < ApplicationJob def perform - domains = Domain.all.select { |d| !d.locked_by_registrant? } + domains = Domain.where(locked_by_registrant_at: nil) domains.each do |domain| domain.admin_store_statuses_history = domain.statuses domain.save From 725ed1519181032336136e9691c7e6bdbabac4a4 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Mon, 12 Jul 2021 16:21:21 +0300 Subject: [PATCH 16/43] added condition for delete button render --- app/controllers/registrar/domains_controller.rb | 6 ++++++ app/views/registrar/domains/_domain.html.erb | 2 ++ app/views/registrar/domains/info.html.erb | 2 ++ 3 files changed, 10 insertions(+) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index 2e268af0b..a5b13a09c 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -64,6 +64,7 @@ class Registrar def info authorize! :info, Depp::Domain @data = @domain.info(params[:domain_name]) if params[:domain_name] + @pending_delete = domain_delete_pending(@data) @client_holded = client_holded(@data) if response_ok? render 'info' @@ -182,6 +183,11 @@ class Registrar &.any? { |status| status == DomainStatus::CLIENT_HOLD } end + def domain_delete_pending(data) + data.css('status')&.map { |element| element.attribute('s').value } + &.any? { |status| status.include?(DomainStatus::PENDING_DELETE) } + end + def contacts current_registrar_user.registrar.contacts end diff --git a/app/views/registrar/domains/_domain.html.erb b/app/views/registrar/domains/_domain.html.erb index 74f29dc15..8cc6da6f7 100644 --- a/app/views/registrar/domains/_domain.html.erb +++ b/app/views/registrar/domains/_domain.html.erb @@ -7,7 +7,9 @@ class: 'btn btn-primary btn-xs' %> <%= link_to t('.renew_btn'), renew_registrar_domains_path(domain_name: domain.name), class: 'btn btn-default btn-xs' %> + <% unless (domain.statuses & %w[pendingDelete pendingDeleteConfirmation]).any? %> <%= link_to t('.delete_btn'), delete_registrar_domains_path(domain_name: domain.name), class: 'btn btn-default btn-xs' %> + <% end %> diff --git a/app/views/registrar/domains/info.html.erb b/app/views/registrar/domains/info.html.erb index e88882233..c2f219bf9 100644 --- a/app/views/registrar/domains/info.html.erb +++ b/app/views/registrar/domains/info.html.erb @@ -4,8 +4,10 @@ class: 'btn btn-default') %> <%= link_to(t(:renew), renew_registrar_domains_path(domain_name: params[:domain_name]), class: 'btn btn-default') %> + <% unless @pending_delete %> <%= link_to(t(:delete), delete_registrar_domains_path(domain_name: params[:domain_name]), class: 'btn btn-default') %> + <% end %> <% if @client_holded %> <%= link_to(t(:remove_client_hold), remove_hold_registrar_domains_path(domain_name: params[:domain_name]), class: 'btn btn-default') %> From 46479dc31be1a21f21dbd542f6e08d1692ed04cc Mon Sep 17 00:00:00 2001 From: Keijo Raamat Date: Mon, 12 Jul 2021 19:22:17 +0300 Subject: [PATCH 17/43] Revert "Merge pull request #2074 from internetee/1795-validation-contacts-name" This reverts commit e2116a505ed64511df074ddc4ed7c64ec3416745, reversing changes made to ded22685c9ff15a7f7c88b77cd32ddbda6891996. --- app/models/contact.rb | 5 ----- test/models/contact_test.rb | 10 ---------- 2 files changed, 15 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 01a4bab3d..b6b1e979b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -28,12 +28,7 @@ class Contact < ApplicationRecord .where('success = false and verified_at IS NOT NULL') } - NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]| - [\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x.freeze - validates :name, :email, presence: true - validates :name, format: { without: NAME_REGEXP, message: :invalid } - validates :street, :city, :zip, :country_code, presence: true, if: lambda { self.class.address_processing? } diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index 189a85dc7..4a598b0c7 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -32,16 +32,6 @@ class ContactTest < ActiveJob::TestCase assert contact.invalid? end - def test_allowed_and_disallowed_symbols_for_name - contact = valid_contact - contact.name = 'MARY ÄNN O’CONNEŽ-ŠUSLIK' - assert contact.valid? - contact.name = 'Boğaçhan Çağlayan' - assert contact.valid? - contact.name = '# "¤ #" ¤ "?' - assert contact.invalid? - end - def test_validates_code_format contact = valid_contact.dup max_length = 100 From 89b2c88f5e49a9df708bf6ac4682956af24840f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jul 2021 17:17:12 +0000 Subject: [PATCH 18/43] Bump addressable from 2.7.0 to 2.8.0 Bumps [addressable](https://github.com/sporkmonger/addressable) from 2.7.0 to 2.8.0. - [Release notes](https://github.com/sporkmonger/addressable/releases) - [Changelog](https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md) - [Commits](https://github.com/sporkmonger/addressable/compare/addressable-2.7.0...addressable-2.8.0) --- updated-dependencies: - dependency-name: addressable dependency-type: indirect ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 68ab07153..c2c4d7a6f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -139,7 +139,7 @@ GEM minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - addressable (2.7.0) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) aes_key_wrap (1.1.0) airbrake (11.0.3) From d8f7f9ca16618636022bef1e54731ae1b71a7f8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jul 2021 19:00:42 +0000 Subject: [PATCH 19/43] Bump data_migrate from 7.0.1 to 7.0.2 Bumps [data_migrate](https://github.com/ajvargo/data-migrate) from 7.0.1 to 7.0.2. - [Release notes](https://github.com/ajvargo/data-migrate/releases) - [Changelog](https://github.com/ilyakatz/data-migrate/blob/master/Changelog.md) - [Commits](https://github.com/ajvargo/data-migrate/commits) --- updated-dependencies: - dependency-name: data_migrate dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 68ab07153..7c7b267a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,7 +205,7 @@ GEM daemons-rails (1.2.1) daemons multi_json (~> 1.0) - data_migrate (7.0.1) + data_migrate (7.0.2) activerecord (>= 5.0) railties (>= 5.0) database_cleaner (2.0.1) @@ -387,7 +387,7 @@ GEM method_source rake (>= 0.13) thor (~> 1.0) - rake (13.0.3) + rake (13.0.6) ransack (2.4.2) activerecord (>= 5.2.4) activesupport (>= 5.2.4) From 19f43f65e00f9ef60bfaaa6091b4e0a26cd0e5f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jul 2021 19:00:58 +0000 Subject: [PATCH 20/43] Bump active_interaction from 4.0.4 to 4.0.5 Bumps [active_interaction](https://github.com/AaronLasseigne/active_interaction) from 4.0.4 to 4.0.5. - [Release notes](https://github.com/AaronLasseigne/active_interaction/releases) - [Changelog](https://github.com/AaronLasseigne/active_interaction/blob/master/CHANGELOG.md) - [Commits](https://github.com/AaronLasseigne/active_interaction/compare/v4.0.4...v4.0.5) --- updated-dependencies: - dependency-name: active_interaction dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 68ab07153..e293b4a30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -115,7 +115,7 @@ GEM erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - active_interaction (4.0.4) + active_interaction (4.0.5) activemodel (>= 5, < 7) activesupport (>= 5, < 7) activejob (6.1.4) From c92237bf0fa9f11eadd91ad7c0a7edfd5c3a78f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jul 2021 19:01:37 +0000 Subject: [PATCH 21/43] Bump truemail from 2.4.4 to 2.4.6 Bumps [truemail](https://github.com/truemail-rb/truemail) from 2.4.4 to 2.4.6. - [Release notes](https://github.com/truemail-rb/truemail/releases) - [Changelog](https://github.com/truemail-rb/truemail/blob/master/CHANGELOG.md) - [Commits](https://github.com/truemail-rb/truemail/compare/v2.4.4...v2.4.6) --- updated-dependencies: - dependency-name: truemail dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 68ab07153..7e93742e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -463,7 +463,7 @@ GEM temple (0.8.2) thor (1.1.0) tilt (2.0.10) - truemail (2.4.4) + truemail (2.4.6) simpleidn (~> 0.2.1) tzinfo (2.0.4) concurrent-ruby (~> 1.0) From 0950361e0a03b7c62ac367bc8f27d984406f0986 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 13 Jul 2021 12:04:54 +0300 Subject: [PATCH 22/43] added stdout to log file --- ...igrate_before_force_delete_statuses_job.rb | 30 ++++++++++++++-- .../migrate_statuses_to_domain_history_job.rb | 34 +++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/app/jobs/migrate_before_force_delete_statuses_job.rb b/app/jobs/migrate_before_force_delete_statuses_job.rb index d7f6c0606..7161ecdd2 100644 --- a/app/jobs/migrate_before_force_delete_statuses_job.rb +++ b/app/jobs/migrate_before_force_delete_statuses_job.rb @@ -1,11 +1,37 @@ class MigrateBeforeForceDeleteStatusesJob < ApplicationJob def perform + logger.info 'Ran MigrateBeforeForceDeleteStatusesJob!' + domains = Domain.where.not(statuses_before_force_delete: nil) + logger.info "Total domains are #{domains.count}" + + interate_domain_in_batches(domains) + end + + private + + def interate_domain_in_batches(domains) + count = 0 + domains.find_in_batches do |domain_batches| + count += domain_batches.count + logger.info "Proccesing #{count} domains of #{domains.count}" domain_batches.each do |domain| - domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete - domain.save + migrate_data_to_statuses_history(domain) end end end + + def migrate_data_to_statuses_history(domain) + domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete + domain.save + rescue StandardError => e + logger.warn "#{domain.name} crashed!" + logger.warn e.to_s + raise e + end + + def logger + @logger ||= Logger.new(Rails.root.join('log', 'migrate_before_force_delete_statuses.log')) + end end diff --git a/app/jobs/migrate_statuses_to_domain_history_job.rb b/app/jobs/migrate_statuses_to_domain_history_job.rb index 870a9cf55..205ea1816 100644 --- a/app/jobs/migrate_statuses_to_domain_history_job.rb +++ b/app/jobs/migrate_statuses_to_domain_history_job.rb @@ -1,9 +1,37 @@ class MigrateStatusesToDomainHistoryJob < ApplicationJob def perform + logger.info 'Ran MigrateStatusesToDomainHistoryJob!' + domains = Domain.where(locked_by_registrant_at: nil) - domains.each do |domain| - domain.admin_store_statuses_history = domain.statuses - domain.save + logger.info "Total domains are #{domains.count}" + + interate_domain_in_batches(domains) + end + + private + + def interate_domain_in_batches(domains) + count = 0 + + domains.find_in_batches do |domain_batches| + count += domain_batches.count + logger.info "Proccesing #{count} domains of #{domains.count}" + domain_batches.each do |domain| + migrate_data_to_admin_store_field(domain) + end end end + + def migrate_data_to_admin_store_field(domain) + domain.admin_store_statuses_history = domain.statuses + domain.save + rescue StandardError => e + logger.warn "#{domain.name} crashed!" + logger.warn e.to_s + raise e + end + + def logger + @logger ||= Logger.new(Rails.root.join('log', 'migrate_statuses_to_domain_history.log')) + end end From 465610b1dd526b3e191452c3b31eba69b56d8ed0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 13 Jul 2021 14:06:39 +0300 Subject: [PATCH 23/43] updated epp request object --- app/views/admin/epp_logs/index.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/epp_logs/index.haml b/app/views/admin/epp_logs/index.haml index 29493d3f7..33ba4f96f 100644 --- a/app/views/admin/epp_logs/index.haml +++ b/app/views/admin/epp_logs/index.haml @@ -14,7 +14,7 @@ - opts = [[t(:choose),''], 'contact', 'domain', 'poll'] - opts += [params[:q][:request_object_cont]] if params[:q].present? && params[:q][:request_object_cont].present? = f.label :request_object - = f.select :request_object_cont, opts, {}, class: 'form-control js-combobox', placeholder: t(:choose) + = f.select :request_object_cont, opts, {}, class: 'form-control selectize_create', placeholder: t(:choose) .col-md-3 .form-group = f.label :request_successful From ac9b6c23bf87a42de9ff62c233974a786a41aea7 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 13 Jul 2021 14:33:40 +0300 Subject: [PATCH 24/43] added if_not_exists method to migration --- .../20210708131814_add_json_statuses_history_field_to_domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb index 0f177683b..658cdb313 100644 --- a/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb +++ b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb @@ -1,6 +1,6 @@ class AddJsonStatusesHistoryFieldToDomain < ActiveRecord::Migration[6.1] def change - add_column :domains, :json_statuses_history, :jsonb + add_column :domains, :json_statuses_history, :jsonb, if_not_exists: true add_index :domains, :json_statuses_history, using: :gin end end From ec90722bf03e9f52943fa428be9e32d17d85fae5 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 13 Jul 2021 15:37:20 +0300 Subject: [PATCH 25/43] add update instead save --- app/jobs/migrate_before_force_delete_statuses_job.rb | 3 +-- app/jobs/migrate_statuses_to_domain_history_job.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/jobs/migrate_before_force_delete_statuses_job.rb b/app/jobs/migrate_before_force_delete_statuses_job.rb index 7161ecdd2..f65538d50 100644 --- a/app/jobs/migrate_before_force_delete_statuses_job.rb +++ b/app/jobs/migrate_before_force_delete_statuses_job.rb @@ -23,8 +23,7 @@ class MigrateBeforeForceDeleteStatusesJob < ApplicationJob end def migrate_data_to_statuses_history(domain) - domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete - domain.save + domain.update(force_delete_domain_statuses_history: domain.statuses_before_force_delete) rescue StandardError => e logger.warn "#{domain.name} crashed!" logger.warn e.to_s diff --git a/app/jobs/migrate_statuses_to_domain_history_job.rb b/app/jobs/migrate_statuses_to_domain_history_job.rb index 205ea1816..a1750c1e6 100644 --- a/app/jobs/migrate_statuses_to_domain_history_job.rb +++ b/app/jobs/migrate_statuses_to_domain_history_job.rb @@ -23,8 +23,7 @@ class MigrateStatusesToDomainHistoryJob < ApplicationJob end def migrate_data_to_admin_store_field(domain) - domain.admin_store_statuses_history = domain.statuses - domain.save + domain.update(admin_store_statuses_history: domain.statuses) rescue StandardError => e logger.warn "#{domain.name} crashed!" logger.warn e.to_s From 96bc237484b02608213339efa0a9849f59f62f0d Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 14 Jul 2021 11:16:56 +0300 Subject: [PATCH 26/43] implement mechanism of save statuses for force delete and lock --- .../remove_force_delete_statuses.rb | 10 ++-- .../restore_statuses_before_force_delete.rb | 3 +- .../domains/force_delete/prepare_domain.rb | 1 + app/models/concerns/domain/force_delete.rb | 6 +- .../concerns/domain/registry_lockable.rb | 3 +- app/models/domain.rb | 14 +++++ test/models/domain/force_delete_test.rb | 57 ++++++++++++++---- test/models/domain/registry_lockable_test.rb | 60 +++++++++++++++++-- test/models/domain_test.rb | 11 ++++ 9 files changed, 142 insertions(+), 23 deletions(-) diff --git a/app/interactions/domains/cancel_force_delete/remove_force_delete_statuses.rb b/app/interactions/domains/cancel_force_delete/remove_force_delete_statuses.rb index c77820ecf..adb310e51 100644 --- a/app/interactions/domains/cancel_force_delete/remove_force_delete_statuses.rb +++ b/app/interactions/domains/cancel_force_delete/remove_force_delete_statuses.rb @@ -2,10 +2,12 @@ module Domains module CancelForceDelete class RemoveForceDeleteStatuses < Base def execute - domain.statuses.delete(DomainStatus::FORCE_DELETE) - domain.statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED) - domain.statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) - domain.statuses.delete(DomainStatus::CLIENT_HOLD) + domain_statuses = [DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::CLIENT_HOLD] + rejected_statuses = domain.statuses.reject { |a| domain_statuses.include? a } + domain.statuses = rejected_statuses domain.save(validate: false) end end diff --git a/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb b/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb index c55c06764..d521bfcba 100644 --- a/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb +++ b/app/interactions/domains/cancel_force_delete/restore_statuses_before_force_delete.rb @@ -2,8 +2,9 @@ module Domains module CancelForceDelete class RestoreStatusesBeforeForceDelete < Base def execute - domain.statuses = domain.statuses_before_force_delete + domain.statuses = domain.force_delete_domain_statuses_history || [] domain.statuses_before_force_delete = nil + domain.force_delete_domain_statuses_history = nil domain.save(validate: false) end end diff --git a/app/interactions/domains/force_delete/prepare_domain.rb b/app/interactions/domains/force_delete/prepare_domain.rb index 74eea21ed..e45f7969c 100644 --- a/app/interactions/domains/force_delete/prepare_domain.rb +++ b/app/interactions/domains/force_delete/prepare_domain.rb @@ -6,6 +6,7 @@ module Domains DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze def execute + domain.force_delete_domain_statuses_history = domain.statuses domain.statuses_before_force_delete = domain.statuses domain.statuses |= STATUSES_TO_SET domain.save(validate: false) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index bc89022d0..b31b02eac 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -1,6 +1,10 @@ -module Domain::ForceDelete # rubocop:disable Metrics/ModuleLength +module Domain::ForceDelete extend ActiveSupport::Concern + FORCE_DELETE_STATUSES = [DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze + included do store_accessor :force_delete_data, :force_delete_type, diff --git a/app/models/concerns/domain/registry_lockable.rb b/app/models/concerns/domain/registry_lockable.rb index 2c0f5c0fe..4f9340aaf 100644 --- a/app/models/concerns/domain/registry_lockable.rb +++ b/app/models/concerns/domain/registry_lockable.rb @@ -36,9 +36,10 @@ module Domain::RegistryLockable transaction do LOCK_STATUSES.each do |domain_status| - statuses.delete(domain_status) + statuses.delete([domain_status]) end self.locked_by_registrant_at = nil + self.statuses = admin_store_statuses_history || [] alert_registrar_lock_changes!(lock: false) save! diff --git a/app/models/domain.rb b/app/models/domain.rb index 519f33575..b150b1f8b 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -553,8 +553,22 @@ class Domain < ApplicationRecord statuses.include?(DomainStatus::FORCE_DELETE) end + def update_unless_locked_by_registrant(update) + update(admin_store_statuses_history: update) unless locked_by_registrant? + end + + def update_not_by_locked_statuses(update) + return unless locked_by_registrant? + + result = update.reject { |status| RegistryLockable::LOCK_STATUSES.include? status } + update(admin_store_statuses_history: result) + end + # special handling for admin changing status def admin_status_update(update) + update_unless_locked_by_registrant(update) + + update_not_by_locked_statuses(update) # check for deleted status statuses.each do |s| unless update.include? s diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 000694673..c9de86b5e 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -12,6 +12,41 @@ class ForceDeleteTest < ActionMailer::TestCase Truemail.configure.default_validation_type = @old_validation_type end + def test_restore_domain_statuses_after_soft_force_delete + @domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED]) + @domain.schedule_force_delete(type: :soft) + + assert @domain.force_delete_scheduled? + + assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED + + @domain.cancel_force_delete + assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED + end + + # def test_restore_domain_statuses_if_status_set_after_fc + # @domain.schedule_force_delete(type: :soft) + + # assert @domain.force_delete_scheduled? + + # @domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED]) + # assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED + + # @domain.cancel_force_delete + # assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED + # end + + def test_clear_force_delete_domain_statuses_history + @domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED]) + @domain.schedule_force_delete(type: :soft) + + assert @domain.force_delete_scheduled? + assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED + @domain.cancel_force_delete + + assert_nil @domain.force_delete_domain_statuses_history + end + def test_schedules_force_delete_fast_track assert_not @domain.force_delete_scheduled? travel_to Time.zone.parse('2010-07-05') @@ -56,7 +91,7 @@ class ForceDeleteTest < ActionMailer::TestCase statuses_to_be_added = [ DomainStatus::FORCE_DELETE, DomainStatus::SERVER_RENEW_PROHIBITED, - DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED ] @domain.schedule_force_delete(type: :soft) @@ -68,7 +103,7 @@ class ForceDeleteTest < ActionMailer::TestCase statuses_to_be_added = [ DomainStatus::FORCE_DELETE, DomainStatus::SERVER_RENEW_PROHIBITED, - DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED ] @domain.schedule_force_delete(type: :fast_track) @@ -79,7 +114,7 @@ class ForceDeleteTest < ActionMailer::TestCase def test_scheduling_force_delete_allows_domain_deletion statuses_to_be_removed = [ DomainStatus::CLIENT_DELETE_PROHIBITED, - DomainStatus::SERVER_DELETE_PROHIBITED, + DomainStatus::SERVER_DELETE_PROHIBITED ] @domain.statuses = statuses_to_be_removed + %w[other-status] @@ -94,7 +129,7 @@ class ForceDeleteTest < ActionMailer::TestCase DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_TRANSFER, DomainStatus::PENDING_RENEW, - DomainStatus::PENDING_CREATE, + DomainStatus::PENDING_CREATE ] @domain.statuses = statuses_to_be_removed + %w[other-status] @@ -122,7 +157,7 @@ class ForceDeleteTest < ActionMailer::TestCase assert_not result.valid? assert_not @domain.force_delete_scheduled? - message = ["Force delete procedure cannot be scheduled while a domain is discarded"] + message = ['Force delete procedure cannot be scheduled while a domain is discarded'] assert_equal message, result.errors.messages[:domain] end @@ -149,9 +184,9 @@ class ForceDeleteTest < ActionMailer::TestCase def test_force_delete_does_not_double_statuses statuses = [ - DomainStatus::FORCE_DELETE, - DomainStatus::SERVER_RENEW_PROHIBITED, - DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::FORCE_DELETE, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED ] @domain.statuses = @domain.statuses + statuses @domain.save! @@ -177,8 +212,8 @@ class ForceDeleteTest < ActionMailer::TestCase def test_cancelling_force_delete_keeps_previous_statuses statuses = [ - DomainStatus::SERVER_RENEW_PROHIBITED, - DomainStatus::SERVER_TRANSFER_PROHIBITED, + DomainStatus::SERVER_RENEW_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED ] @domain.statuses = statuses @@ -479,7 +514,7 @@ class ForceDeleteTest < ActionMailer::TestCase @bounced_mail.bounce_subtype = 'General' @bounced_mail.action = 'failed' @bounced_mail.status = '5.1.1' - @bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown' + @bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown' @bounced_mail.save! end end diff --git a/test/models/domain/registry_lockable_test.rb b/test/models/domain/registry_lockable_test.rb index 6e4a1826c..c8ea69fd1 100644 --- a/test/models/domain/registry_lockable_test.rb +++ b/test/models/domain/registry_lockable_test.rb @@ -11,12 +11,62 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase refute(@domain.locked_by_registrant?) @domain.update(statuses: [DomainStatus::SERVER_TRANSFER_PROHIBITED]) - @domain.apply_registry_lock #Raise validation error + @domain.apply_registry_lock # Raise validation error check_statuses_lockable_domain assert(@domain.locked_by_registrant?) end + def test_remove_lockalable_statuses_after_admin_intervention + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort + + deleted_status = @domain.statuses - [DomainStatus::SERVER_DELETE_PROHIBITED] + @domain.update(statuses: deleted_status) + assert_not @domain.locked_by_registrant? + + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + @domain.remove_registry_lock + + assert_not @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED + end + + def test_restore_domain_statuses_after_unlock + @domain.statuses = [DomainStatus::SERVER_UPDATE_PROHIBITED] + @domain.admin_store_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED] + @domain.save + assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED + + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort + + @domain.remove_registry_lock + assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED + end + + def test_add_additinal_status_for_locked_domain + @domain.apply_registry_lock + assert @domain.locked_by_registrant? + assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort + + @domain.statuses += [DomainStatus::SERVER_RENEW_PROHIBITED] + @domain.admin_store_statuses_history = [DomainStatus::SERVER_RENEW_PROHIBITED] + @domain.save + + @domain.remove_registry_lock + assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED + assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED + end + def test_lockable_domain_if_remove_some_prohibited_status refute(@domain.locked_by_registrant?) @domain.apply_registry_lock @@ -29,7 +79,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase assert @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED assert @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED assert_not @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED - + assert_not(@domain.locked_by_registrant?) end @@ -74,7 +124,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase @domain.remove_registry_lock - assert_equal(["ok"], @domain.statuses) + assert_equal(['ok'], @domain.statuses) refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant_at) end @@ -100,8 +150,8 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase def check_statuses_lockable_domain lock_statuses = [DomainStatus::SERVER_UPDATE_PROHIBITED, - DomainStatus::SERVER_DELETE_PROHIBITED, - DomainStatus::SERVER_TRANSFER_PROHIBITED] + DomainStatus::SERVER_DELETE_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED] @domain.statuses.include? lock_statuses end diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index 15ab8b0c2..57c370089 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -27,6 +27,17 @@ class DomainTest < ActiveSupport::TestCase assert domains(:invalid).invalid? end + def test_valid_domain_statuses_history + @domain.force_delete_domain_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED, + DomainStatus::SERVER_TRANSFER_PROHIBITED] + @domain.admin_store_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED] + assert @domain.valid? + + assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverUpdateProhibited' + assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverTransferProhibited' + assert_equal @domain.json_statuses_history['admin_store_statuses_history'], ['serverUpdateProhibited'] + end + # https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine def test_validates_name_format assert_equal dns_zones(:one).origin, 'test' From addeebfeb3f16d4a365c4d7d20be073c812f3b9d Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 14 Jul 2021 12:40:49 +0300 Subject: [PATCH 27/43] created birth date validator --- app/models/contact/ident.rb | 2 ++ app/models/epp/contact.rb | 25 ------------------ .../contact/ident/birth_date_validator.rb | 26 +++++++++++++++++++ config/locales/epp/contacts.en.yml | 6 ----- config/locales/idents.yml | 1 + .../epp/contact/create/base_test.rb | 6 ++--- 6 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 app/validators/contact/ident/birth_date_validator.rb diff --git a/app/models/contact/ident.rb b/app/models/contact/ident.rb index d531b833c..8d1179afe 100644 --- a/app/models/contact/ident.rb +++ b/app/models/contact/ident.rb @@ -13,6 +13,7 @@ class Contact::Ident validates :type, presence: true, inclusion: { in: proc { types } } validates :country_code, presence: true, iso31661_alpha2: true validates_with MismatchValidator + validates_with BirthDateValidator, if: :birthday? def self.epp_code_map { @@ -26,6 +27,7 @@ class Contact::Ident [:code, :invalid_national_id], [:code, :invalid_reg_no], [:code, :invalid_iso8601_date], + [:code, :invalid_birth_date], [:country_code, :invalid_iso31661_alpha2] ] } diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 6f53eaed5..6bd5507b9 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -8,9 +8,6 @@ class Epp::Contact < Contact # disable STI, there is type column present self.inheritance_column = :sti_disabled - VALID_BIRTH_DATE_FROM = Time.zone.today - 150.years - VALID_BIRTH_DATE_TO = Time.zone.tomorrow - before_validation :manage_permissions def manage_permissions @@ -19,28 +16,6 @@ class Epp::Contact < Contact throw(:abort) end - validate :validate_birthday_ident - - def validate_birthday_ident - return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type) - - begin - Date.parse(ident) - rescue ArgumentError - add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format')) - @error = true - return - end - - contact_ident_date = Date.parse(ident) - valid_time_range = VALID_BIRTH_DATE_FROM...VALID_BIRTH_DATE_TO - return if valid_time_range.cover?(contact_ident_date) - - add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range')) - @error = true - nil - end - class << self # support legacy search def find_by_epp_code(code) diff --git a/app/validators/contact/ident/birth_date_validator.rb b/app/validators/contact/ident/birth_date_validator.rb new file mode 100644 index 000000000..38cfc98f9 --- /dev/null +++ b/app/validators/contact/ident/birth_date_validator.rb @@ -0,0 +1,26 @@ +class Contact::Ident::BirthDateValidator < ActiveModel::Validator + VALID_BIRTH_DATE_FROM = Time.zone.today - 150.years + VALID_BIRTH_DATE_TO = Time.zone.tomorrow + + def validate(record) + record.errors.add(:code, :invalid_birth_date) if birth_date_wrong?(record) + end + + private + + def birth_date_wrong?(record) + return unless record.birthday? + + begin + Date.parse(record.code) + rescue ArgumentError + return true + end + + contact_ident_date = Date.parse(record.code) + valid_time_range = VALID_BIRTH_DATE_FROM...VALID_BIRTH_DATE_TO + return if valid_time_range.cover?(contact_ident_date) + + true + end +end diff --git a/config/locales/epp/contacts.en.yml b/config/locales/epp/contacts.en.yml index 341630299..fe4ed7ccf 100644 --- a/config/locales/epp/contacts.en.yml +++ b/config/locales/epp/contacts.en.yml @@ -8,12 +8,6 @@ en: valid_ident: >- Ident update is not allowed. Consider creating new contact object - valid_ident_date_format: >- - Ident update is not allowed. - Date format is invalid - valid_ident_date_range: >- - Ident update is not allowed. - Age must be over 0 and under 150 ident_update: >- Only ident type and country can be updated in case of invalid ident. Please create new contact object to update ident code diff --git a/config/locales/idents.yml b/config/locales/idents.yml index 33b935833..8e6a677de 100644 --- a/config/locales/idents.yml +++ b/config/locales/idents.yml @@ -9,3 +9,4 @@ en: code: invalid_national_id: does not conform to national identification number format of %{country} invalid_reg_no: does not conform to registration number format of %{country} + invalid_birth_date: Birth date is invalid, age must be over 0 and under 150 diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index 5d965596a..72d8597c4 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -119,7 +119,7 @@ class EppContactCreateBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml - assert_epp_response :data_management_policy_violation + assert_epp_response :parameter_value_syntax_error request_xml.sub! ">#{birthday_wrong_format}<", ">#{birthday_above_valid_range}<" assert_no_difference 'Contact.count' do @@ -129,7 +129,7 @@ class EppContactCreateBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml - assert_epp_response :data_management_policy_violation + assert_epp_response :parameter_value_syntax_error request_xml.sub! ">#{birthday_above_valid_range}<", ">#{birthday_below_valid_range}<" assert_no_difference 'Contact.count' do @@ -139,7 +139,7 @@ class EppContactCreateBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml - assert_epp_response :data_management_policy_violation + assert_epp_response :parameter_value_syntax_error end def test_responces_error_with_email_error From 458609921f44b5264659b24ef441b5e7bf805a07 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 14 Jul 2021 12:49:47 +0300 Subject: [PATCH 28/43] remove comments --- test/models/domain/force_delete_test.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index c9de86b5e..73a6245de 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -24,18 +24,6 @@ class ForceDeleteTest < ActionMailer::TestCase assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED end - # def test_restore_domain_statuses_if_status_set_after_fc - # @domain.schedule_force_delete(type: :soft) - - # assert @domain.force_delete_scheduled? - - # @domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED]) - # assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED - - # @domain.cancel_force_delete - # assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED - # end - def test_clear_force_delete_domain_statuses_history @domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED]) @domain.schedule_force_delete(type: :soft) From 25d743c1ca95fa0958d60bf68a9cfaca99dab165 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 14 Jul 2021 13:22:09 +0300 Subject: [PATCH 29/43] hotfix: added if_exist method to migration --- .../20210708131814_add_json_statuses_history_field_to_domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb index 658cdb313..74d9cee54 100644 --- a/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb +++ b/db/migrate/20210708131814_add_json_statuses_history_field_to_domain.rb @@ -1,6 +1,6 @@ class AddJsonStatusesHistoryFieldToDomain < ActiveRecord::Migration[6.1] def change add_column :domains, :json_statuses_history, :jsonb, if_not_exists: true - add_index :domains, :json_statuses_history, using: :gin + add_index :domains, :json_statuses_history, using: :gin, if_not_exists: true end end From 939efdba0f8d058904e96fe9b9f17d8f7a53c33c Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 14 Jul 2021 13:26:01 +0300 Subject: [PATCH 30/43] fixed codeclimate errors --- app/models/contact/ident.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/contact/ident.rb b/app/models/contact/ident.rb index 8d1179afe..854fecb20 100644 --- a/app/models/contact/ident.rb +++ b/app/models/contact/ident.rb @@ -18,17 +18,17 @@ class Contact::Ident def self.epp_code_map { '2003' => [ - [:code, :blank], - [:type, :blank], - [:country_code, :blank] + %i[code blank], + %i[type blank], + %i[country_code blank] ], '2005' => [ - [:base, :mismatch], - [:code, :invalid_national_id], - [:code, :invalid_reg_no], - [:code, :invalid_iso8601_date], - [:code, :invalid_birth_date], - [:country_code, :invalid_iso31661_alpha2] + %i[base mismatch], + %i[code invalid_national_id], + %i[code invalid_reg_no], + %i[code invalid_iso8601_date], + %i[code invalid_birth_date], + %i[country_code invalid_iso31661_alpha2] ] } end From 2a33b02f8f8a67ff25a25d764354911bb7bfff52 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 14 Jul 2021 13:32:12 +0300 Subject: [PATCH 31/43] fixed codeclimate errors --- app/models/contact/ident.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/contact/ident.rb b/app/models/contact/ident.rb index 854fecb20..c2e1790f7 100644 --- a/app/models/contact/ident.rb +++ b/app/models/contact/ident.rb @@ -20,7 +20,7 @@ class Contact::Ident '2003' => [ %i[code blank], %i[type blank], - %i[country_code blank] + %i[country_code blank], ], '2005' => [ %i[base mismatch], @@ -28,7 +28,7 @@ class Contact::Ident %i[code invalid_reg_no], %i[code invalid_iso8601_date], %i[code invalid_birth_date], - %i[country_code invalid_iso31661_alpha2] + %i[country_code invalid_iso31661_alpha2], ] } end From cfb74cc7daf0a409007fb6824fc43b71cc63ae54 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 14 Jul 2021 16:43:16 +0500 Subject: [PATCH 32/43] Revert "Mark orphan notification as read" --- app/controllers/epp/polls_controller.rb | 1 - test/integration/epp/poll_test.rb | 25 ------------------------- 2 files changed, 26 deletions(-) diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index 01cb719c4..86218336b 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -27,7 +27,6 @@ module Epp Rails.logger.error 'orphan message, error ignored: ' + problem.to_s # now we should dequeue or delete the messages avoid duplicate log alarms - @notification.mark_as_read end end diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index e3fbb0daf..5cdb7e524 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -26,31 +26,6 @@ class EppPollTest < EppTestCase assert_equal 'Your domain has been updated', xml_doc.at_css('msgQ msg').text end - def test_clears_orphan_messages_if_any - # To check if we are clearing orphan messages we need to create a message not linked to any - # existing Epp::Domain - - orphan_notification = @notification.dup - orphan_notification.attached_obj_type = Epp::Domain - orphan_notification.attached_obj_id = rand(Epp::Domain.first.id-1) - orphan_notification.save! - assert orphan_notification.unread? - - request_xml = <<-XML - - - - - - - XML - post epp_poll_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - - orphan_notification.reload - refute orphan_notification.unread? - end - def test_does_not_drop_error_if_old_version version = Version::DomainVersion.last @notification.update(attached_obj_type: 'DomainVersion', attached_obj_id: version.id) From 51410cdb3fc944cf0f4be3be93ed543ecb089518 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 14 Jul 2021 17:13:08 +0500 Subject: [PATCH 33/43] Fix orphan message behaviour --- app/controllers/epp/polls_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index 86218336b..3886d2382 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -24,9 +24,8 @@ module Epp # SELECT messages.id, domains.name, messages.body FROM messages LEFT OUTER # JOIN domains ON attached_obj_id::INTEGER = domains.id # WHERE attached_obj_type = 'Epp::Domain' AND name IS NULL; - - Rails.logger.error 'orphan message, error ignored: ' + problem.to_s - # now we should dequeue or delete the messages avoid duplicate log alarms + message = 'orphan message, domain deleted, registrar should dequeue: ' + Rails.logger.error message + problem.to_s end end From 2224add1656fc7ef3a50098604af20ebfd35696e Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 14 Jul 2021 15:52:40 +0300 Subject: [PATCH 34/43] deleted checking of registrar present --- app/models/bank_transaction.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index 3377d06b8..ae4fbf51b 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -106,7 +106,7 @@ class BankTransaction < ApplicationRecord private def reset_pending_registrar_balance_reload - return unless registrar.present? && registrar.settings['balance_auto_reload'] + return unless registrar.settings['balance_auto_reload'] registrar.settings['balance_auto_reload'].delete('pending') registrar.save! From 89c2ef1cf17e44cf8685889eaeb01d09d762212a Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 15 Jul 2021 11:32:14 +0300 Subject: [PATCH 35/43] fixed test --- test/system/registrar_area/domains_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/system/registrar_area/domains_test.rb b/test/system/registrar_area/domains_test.rb index 7a2f5f7f1..74fac9b2f 100644 --- a/test/system/registrar_area/domains_test.rb +++ b/test/system/registrar_area/domains_test.rb @@ -18,4 +18,20 @@ class RegistrarDomainsTest < ApplicationSystemTestCase assert_equal "attachment; filename=\"Domains_2010-07-05_10.30.csv\"; filename*=UTF-8''Domains_2010-07-05_10.30.csv", response_headers['Content-Disposition'] assert_equal expected_csv, page.body end + + def test_delete_domain + sign_in users(:api_bestnames) + visit registrar_domains_path + click_link_or_button 'airport.test' + + assert_text 'Delete' + + click_link_or_button 'Delete' + click_link_or_button 'Delete' + visit registrar_domains_url + click_link_or_button 'airport.test' + + assert_no_button 'Delete' + assert_text 'pendingDelete' + end end From 962c343ab72fe80b6db7a5febd4b4725feaa0a69 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 15 Jul 2021 17:44:52 +0300 Subject: [PATCH 36/43] added flash notification --- app/controllers/registrar/domains_controller.rb | 1 + config/locales/registrar/domains.en.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index a5b13a09c..d477c2c27 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -132,6 +132,7 @@ class Registrar @data = @domain.delete(params[:domain]) @results = @data.css('result') if response_ok? + flash[:notice] = t('.deleting_request') redirect_to info_registrar_domains_url(domain_name: params[:domain][:name]) else params[:domain_name] = params[:domain][:name] diff --git a/config/locales/registrar/domains.en.yml b/config/locales/registrar/domains.en.yml index c98002b8f..b8605bd42 100644 --- a/config/locales/registrar/domains.en.yml +++ b/config/locales/registrar/domains.en.yml @@ -16,6 +16,9 @@ en: info: transfer_btn: Transfer + destroy: + deleting_request: Domain deletion request was sent + search_form: download_btn: Download CSV reset_btn: Reset From ec5d3f5197433923cc5e79f8e3ebcf022a7546dd Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 16 Jul 2021 10:49:38 +0300 Subject: [PATCH 37/43] removed test --- test/system/registrar_area/domains_test.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/system/registrar_area/domains_test.rb b/test/system/registrar_area/domains_test.rb index 74fac9b2f..7a2f5f7f1 100644 --- a/test/system/registrar_area/domains_test.rb +++ b/test/system/registrar_area/domains_test.rb @@ -18,20 +18,4 @@ class RegistrarDomainsTest < ApplicationSystemTestCase assert_equal "attachment; filename=\"Domains_2010-07-05_10.30.csv\"; filename*=UTF-8''Domains_2010-07-05_10.30.csv", response_headers['Content-Disposition'] assert_equal expected_csv, page.body end - - def test_delete_domain - sign_in users(:api_bestnames) - visit registrar_domains_path - click_link_or_button 'airport.test' - - assert_text 'Delete' - - click_link_or_button 'Delete' - click_link_or_button 'Delete' - visit registrar_domains_url - click_link_or_button 'airport.test' - - assert_no_button 'Delete' - assert_text 'pendingDelete' - end end From 63e911acb618360214ea5e5426b094aae05a98a9 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 19 Jul 2021 16:09:41 +0500 Subject: [PATCH 38/43] Fix 'true' validation in repp mark message as read endpoint --- app/controllers/repp/v1/registrar/notifications_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index 1185a1a73..815ee85b9 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -48,7 +48,7 @@ module Repp api :PUT, '/repp/v1/registrar/notifications' desc 'Mark poll message as read' param :notification, Hash, required: true do - param :read, [true], required: true, desc: 'Set as true to mark as read' + param :read, [true, 'true'], required: true, desc: 'Set as true to mark as read' end def update # rubocop:disable Style/AndOr From c24706be99838d99936292df0b70aee12e65cd53 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jul 2021 19:00:45 +0000 Subject: [PATCH 39/43] Bump countries from 4.0.0 to 4.0.1 Bumps [countries](https://github.com/countries/countries) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/countries/countries/releases) - [Changelog](https://github.com/countries/countries/blob/master/CHANGELOG.md) - [Commits](https://github.com/countries/countries/compare/v4.0.0...v4.0.1) --- updated-dependencies: - dependency-name: countries dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index e9b374616..563d012f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -195,7 +195,7 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.1.9) connection_pool (2.2.5) - countries (4.0.0) + countries (4.0.1) i18n_data (~> 0.13.0) sixarm_ruby_unaccent (~> 1.1) crack (0.4.5) From d6985dc78be01acb504af037c0735e1dcd349049 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 20 Jul 2021 01:03:18 +0300 Subject: [PATCH 40/43] fixed method update --- app/controllers/registrar/contacts_controller.rb | 2 +- app/models/depp/contact.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index 756495457..85a1adce5 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -83,7 +83,7 @@ class Registrar def update authorize! :edit, Depp::Contact - @contact = Depp::Contact.new(contact_params) + @contact = Depp::Contact.find_by_id(contact_params[:id]) if @contact.update_attributes(contact_params) redirect_to registrar_contact_url(@contact.id) diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index 33b7545b7..9050d8ca1 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -172,9 +172,9 @@ module Depp end def update_attributes(params) - self.ident_country_code = params[:ident_country_code] - self.ident_type = params[:ident_type] - self.ident = params[:ident] + self.ident_country_code ||= params[:ident_country_code] + self.ident_type ||= params[:ident_type] + self.ident ||= params[:ident] self.name = params[:name] self.email = params[:email] From 01840ef511be7fec5f055630c09ceb7e85650137 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 20 Jul 2021 07:02:58 +0300 Subject: [PATCH 41/43] fixed codeclimate error --- app/models/depp/contact.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index 9050d8ca1..710fff9f7 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -173,8 +173,8 @@ module Depp def update_attributes(params) self.ident_country_code ||= params[:ident_country_code] - self.ident_type ||= params[:ident_type] - self.ident ||= params[:ident] + self.ident_type ||= params[:ident_type] + self.ident ||= params[:ident] self.name = params[:name] self.email = params[:email] From cbfe2704b6b6cbd2aabc98b680255e7fffc64e31 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 20 Jul 2021 15:55:53 +0300 Subject: [PATCH 42/43] fixed form and contacts controller --- app/controllers/registrar/contacts_controller.rb | 2 +- app/views/registrar/contacts/form/_general.haml | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/controllers/registrar/contacts_controller.rb b/app/controllers/registrar/contacts_controller.rb index 85a1adce5..756495457 100644 --- a/app/controllers/registrar/contacts_controller.rb +++ b/app/controllers/registrar/contacts_controller.rb @@ -83,7 +83,7 @@ class Registrar def update authorize! :edit, Depp::Contact - @contact = Depp::Contact.find_by_id(contact_params[:id]) + @contact = Depp::Contact.new(contact_params) if @contact.update_attributes(contact_params) redirect_to registrar_contact_url(@contact.id) diff --git a/app/views/registrar/contacts/form/_general.haml b/app/views/registrar/contacts/form/_general.haml index d7fcea38a..77443903d 100644 --- a/app/views/registrar/contacts/form/_general.haml +++ b/app/views/registrar/contacts/form/_general.haml @@ -15,9 +15,7 @@ = f.label :ident_country_code, t(:country) + '*' .col-md-7 - if ident_complete && @contact.persisted? && f.object.ident_country_code.present? - .disabled-value - = Country.new(f.object.ident_country_code).try(:to_s) - = " [#{f.object.ident_country_code}]" + = f.text_field :ident_country_code, value: f.object.ident_country_code, :readonly => true - else = f.select(:ident_country_code, ApplicationController.helpers.all_country_options(country_selected), {}, class: 'js-ident-country-code', required: true) @@ -27,9 +25,7 @@ = f.label :ident_type, t(:type) + '*' .col-md-7 - if ident_complete && @contact.persisted? && f.object.ident_type.present? - .disabled-value - = Depp::Contact.type_string(f.object.ident_type) - = " [#{f.object.ident_type}]" + = f.text_field :ident_type, value: f.object.ident_type, :readonly => true - else = f.select(:ident_type, Depp::Contact::SELECTION_TYPES, { selected: type_selected }, class: 'js-ident-type', required: true) @@ -39,8 +35,7 @@ = f.label :ident, t(:ident) + '*' .col-md-7 - if ident_complete && @contact.persisted? && f.object.ident.present? - .disabled-value - = f.object.ident + = f.text_field :ident, value: f.object.ident, :readonly => true - else = f.text_field :ident, class: 'form-control', required: true - tip_visibility = f.object.ident_type == 'birthday' ? '' : 'display: none' From 8fb8830dd013429e0ae38a03c626858af482ac98 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 21 Jul 2021 09:49:37 +0300 Subject: [PATCH 43/43] rolled back model changes --- app/models/depp/contact.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/depp/contact.rb b/app/models/depp/contact.rb index 710fff9f7..33b7545b7 100644 --- a/app/models/depp/contact.rb +++ b/app/models/depp/contact.rb @@ -172,9 +172,9 @@ module Depp end def update_attributes(params) - self.ident_country_code ||= params[:ident_country_code] - self.ident_type ||= params[:ident_type] - self.ident ||= params[:ident] + self.ident_country_code = params[:ident_country_code] + self.ident_type = params[:ident_type] + self.ident = params[:ident] self.name = params[:name] self.email = params[:email]