From be5bba09fb1d406710d5593add523a2ffe18c3f7 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 17 Feb 2025 12:31:51 +0200 Subject: [PATCH 1/2] Refactor force delete notifications and improve status handling - Add force delete type and start date to notifications - Extract company status notes logic into separate method - Standardize status message formatting for both soft and fast track deletes - Update translation templates to include force delete type and start date info - Add Estonian translation for new notification fields --- .../domains/force_delete/notify_registrar.rb | 12 +++++++++++ app/jobs/company_register_status_job.rb | 20 +++++++++---------- config/locales/en.yml | 2 +- config/locales/et.yml | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index 2e209a4c3..388456713 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -5,9 +5,19 @@ module Domains email.present? ? notify_with_email : notify_without_email end + def force_delete_type + type == :soft ? 'Soft' : 'Fast Track' + end + + def force_delete_start_date + domain.force_delete_start.strftime('%d.%m.%Y') + end + def notify_without_email template = if reason == 'invalid_company' I18n.t('invalid_ident', + force_delete_type: force_delete_type, + force_delete_start_date: force_delete_start_date, ident: domain.registrant.ident, domain_name: domain.name, outzone_date: domain.outzone_date, @@ -28,6 +38,8 @@ module Domains def notify_with_email template = if reason == 'invalid_company' I18n.t('invalid_ident', + force_delete_type: force_delete_type, + force_delete_start_date: force_delete_start_date, ident: domain.registrant.ident, domain_name: domain.name, outzone_date: domain.outzone_date, diff --git a/app/jobs/company_register_status_job.rb b/app/jobs/company_register_status_job.rb index 7f0e525a6..36672d34f 100644 --- a/app/jobs/company_register_status_job.rb +++ b/app/jobs/company_register_status_job.rb @@ -75,18 +75,12 @@ class CompanyRegisterStatusJob < ApplicationJob contact.registrant_domains.each do |domain| next if domain.force_delete_scheduled? - company_status = if company_status.nil? - 'Contact not found in EE business registry' - else - "Contact has status #{REGISTRY_STATUSES[company_status]}" - end - domain.schedule_force_delete( type: :fast_track, notify_by_email: true, reason: 'invalid_company', email: contact.email, - notes: company_status + notes: company_status_notes(company_status) ) end end @@ -142,15 +136,13 @@ class CompanyRegisterStatusJob < ApplicationJob def soft_delete_company(contact, company_status) contact.registrant_domains.reject { |domain| domain.force_delete_scheduled? }.each do |domain| next if domain.force_delete_scheduled? - - company_status = company_status.nil? ? 'No information' : REGISTRY_STATUSES[company_status] domain.schedule_force_delete( type: :soft, notify_by_email: true, reason: 'invalid_company', email: contact.email, - notes: "Contact has status #{company_status}") + notes: company_status_notes(company_status)) end puts "Soft delete process initiated for company: #{contact.name} with ID: #{contact.id}" @@ -168,4 +160,12 @@ class CompanyRegisterStatusJob < ApplicationJob def whitelisted_company?(contact) whitelisted_companies.include?(contact.ident) end + + def company_status_notes(company_status) + if company_status.nil? + 'Contact not found in EE business registry' + else + "Contact has status #{REGISTRY_STATUSES.fetch(company_status, company_status)}" + end + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index ba9120f18..7cb720451 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -676,7 +676,7 @@ en: actions: Actions contact_has_been_archived: 'Contact with code %{contact_code} has been archieved because it has been orphaned for longer than %{orphan_months} months.' dns_policy_violation: "Data management policy violation: DNSKEY does not match or not found in the authoritative nameservers" - invalid_ident: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. Invalid ident %{ident}. %{notes}' + invalid_ident: 'Force delete set on domain %{domain_name}. Force Delete Type: %{force_delete_type}. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. Invalid ident %{ident}. %{notes}' number: currency: diff --git a/config/locales/et.yml b/config/locales/et.yml index f0a9eba83..51192c708 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -41,4 +41,4 @@ et: ipv6: taken: 'on juba lisatud' - invalid_ident: 'Jõustatud kustutamine määratud domainile %{domain_name}. Väljaandmise kuupäev: %{outzone_date}. Kustutamise kuupäev: %{purge_date}. Vigane ident %{ident}' + invalid_ident: 'Jõustatud kustutamine määratud domainile %{domain_name}. Jõustatud kustutamine tüüp: %{force_delete_type}. Jõustatud kustutamise algus kuupäev: %{force_delete_start_date}. Väljaandmise kuupäev: %{outzone_date}. Kustutamise kuupäev: %{purge_date}. Vigane ident %{ident}' From cdf301bc0e2dcca4d0f60398e17360f324e0803a Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Mon, 17 Feb 2025 13:16:14 +0200 Subject: [PATCH 2/2] updated test --- test/jobs/company_register_status_job_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/jobs/company_register_status_job_test.rb b/test/jobs/company_register_status_job_test.rb index dad0f5da5..fc6b101d2 100644 --- a/test/jobs/company_register_status_job_test.rb +++ b/test/jobs/company_register_status_job_test.rb @@ -185,6 +185,8 @@ class CompanyRegisterStatusJobTest < ActiveSupport::TestCase domain_name: @registrant_acme.registrant_domains.first.name, outzone_date: @registrant_acme.registrant_domains.first.outzone_date, purge_date: @registrant_acme.registrant_domains.first.purge_date, + force_delete_type: 'Fast Track', + force_delete_start_date: @registrant_acme.registrant_domains.first.force_delete_start.strftime('%d.%m.%Y'), notes: "Contact has status deleted") assert_equal @registrant_acme.registrant_domains.first.registrar.notifications.last.text, template