Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor force delete notifications and improve status handling #2755

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/interactions/domains/force_delete/notify_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ def execute
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,
Expand All @@ -28,6 +38,8 @@ def notify_without_email
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,
Expand Down
20 changes: 10 additions & 10 deletions app/jobs/company_register_status_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,12 @@ def schedule_force_delete(contact, company_status)
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
Expand Down Expand Up @@ -142,15 +136,13 @@ def extract_kandeliik_tekstina(company_details_response)
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}"
Expand All @@ -168,4 +160,12 @@ def whitelisted_companies
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
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/et.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
2 changes: 2 additions & 0 deletions test/jobs/company_register_status_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def object.simple_data(registration_number:)
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

Expand Down
Loading