Merge pull request #2755 from internetee/upgrade-registrar-invalid-company-notification

Refactor force delete notifications and improve status handling
This commit is contained in:
Timo Võhmar 2025-02-20 10:11:17 +02:00 committed by GitHub
commit 5b1a5a6d06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 12 deletions

View file

@ -5,9 +5,19 @@ module Domains
email.present? ? notify_with_email : notify_without_email email.present? ? notify_with_email : notify_without_email
end 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 def notify_without_email
template = if reason == 'invalid_company' template = if reason == 'invalid_company'
I18n.t('invalid_ident', I18n.t('invalid_ident',
force_delete_type: force_delete_type,
force_delete_start_date: force_delete_start_date,
ident: domain.registrant.ident, ident: domain.registrant.ident,
domain_name: domain.name, domain_name: domain.name,
outzone_date: domain.outzone_date, outzone_date: domain.outzone_date,
@ -28,6 +38,8 @@ module Domains
def notify_with_email def notify_with_email
template = if reason == 'invalid_company' template = if reason == 'invalid_company'
I18n.t('invalid_ident', I18n.t('invalid_ident',
force_delete_type: force_delete_type,
force_delete_start_date: force_delete_start_date,
ident: domain.registrant.ident, ident: domain.registrant.ident,
domain_name: domain.name, domain_name: domain.name,
outzone_date: domain.outzone_date, outzone_date: domain.outzone_date,

View file

@ -75,18 +75,12 @@ class CompanyRegisterStatusJob < ApplicationJob
contact.registrant_domains.each do |domain| contact.registrant_domains.each do |domain|
next if domain.force_delete_scheduled? 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( domain.schedule_force_delete(
type: :fast_track, type: :fast_track,
notify_by_email: true, notify_by_email: true,
reason: 'invalid_company', reason: 'invalid_company',
email: contact.email, email: contact.email,
notes: company_status notes: company_status_notes(company_status)
) )
end end
end end
@ -142,15 +136,13 @@ class CompanyRegisterStatusJob < ApplicationJob
def soft_delete_company(contact, company_status) def soft_delete_company(contact, company_status)
contact.registrant_domains.reject { |domain| domain.force_delete_scheduled? }.each do |domain| contact.registrant_domains.reject { |domain| domain.force_delete_scheduled? }.each do |domain|
next if domain.force_delete_scheduled? next if domain.force_delete_scheduled?
company_status = company_status.nil? ? 'No information' : REGISTRY_STATUSES[company_status]
domain.schedule_force_delete( domain.schedule_force_delete(
type: :soft, type: :soft,
notify_by_email: true, notify_by_email: true,
reason: 'invalid_company', reason: 'invalid_company',
email: contact.email, email: contact.email,
notes: "Contact has status #{company_status}") notes: company_status_notes(company_status))
end end
puts "Soft delete process initiated for company: #{contact.name} with ID: #{contact.id}" puts "Soft delete process initiated for company: #{contact.name} with ID: #{contact.id}"
@ -168,4 +160,12 @@ class CompanyRegisterStatusJob < ApplicationJob
def whitelisted_company?(contact) def whitelisted_company?(contact)
whitelisted_companies.include?(contact.ident) whitelisted_companies.include?(contact.ident)
end 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 end

View file

@ -676,7 +676,7 @@ en:
actions: Actions 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.' 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" 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: number:
currency: currency:

View file

@ -41,4 +41,4 @@ et:
ipv6: ipv6:
taken: 'on juba lisatud' 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}'

View file

@ -185,6 +185,8 @@ class CompanyRegisterStatusJobTest < ActiveSupport::TestCase
domain_name: @registrant_acme.registrant_domains.first.name, domain_name: @registrant_acme.registrant_domains.first.name,
outzone_date: @registrant_acme.registrant_domains.first.outzone_date, outzone_date: @registrant_acme.registrant_domains.first.outzone_date,
purge_date: @registrant_acme.registrant_domains.first.purge_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") notes: "Contact has status deleted")
assert_equal @registrant_acme.registrant_domains.first.registrar.notifications.last.text, template assert_equal @registrant_acme.registrant_domains.first.registrar.notifications.last.text, template