From be00eb4e9bbf942943776e0197214a3e4e6fe59e Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Fri, 16 Oct 2026 11:57:18 +0300 Subject: [PATCH 01/11] Add local death registry file and lookup Weekly job downloads the Population Register death open data (andmed.eesti.ee "surmaandmed") and builds a sorted, fixed-width file of Estonian personal identity codes and death dates. DeathRegistry::Lookup binary searches it on disk and raises FileUnavailable when the file is missing, stale or malformed, so a missing file never reads as "alive". The old file is kept when a download fails, the CSV format changes or the record count drops below death_registry_min_records. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/jobs/death_registry_file_build_job.rb | 11 ++ app/services/death_registry.rb | 41 +++++++ app/services/death_registry/file_builder.rb | 103 ++++++++++++++++ app/services/death_registry/lookup.rb | 56 +++++++++ config/application.yml.sample | 6 + config/schedule.rb | 7 ++ .../death_registry_file_build_job_test.rb | 30 +++++ .../death_registry/file_builder_test.rb | 114 ++++++++++++++++++ test/services/death_registry/lookup_test.rb | 72 +++++++++++ 9 files changed, 440 insertions(+) create mode 100644 app/jobs/death_registry_file_build_job.rb create mode 100644 app/services/death_registry.rb create mode 100644 app/services/death_registry/file_builder.rb create mode 100644 app/services/death_registry/lookup.rb create mode 100644 test/jobs/death_registry_file_build_job_test.rb create mode 100644 test/services/death_registry/file_builder_test.rb create mode 100644 test/services/death_registry/lookup_test.rb diff --git a/app/jobs/death_registry_file_build_job.rb b/app/jobs/death_registry_file_build_job.rb new file mode 100644 index 0000000000..f96d29dfb1 --- /dev/null +++ b/app/jobs/death_registry_file_build_job.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +# Weekly rebuild of the local death registry file used by DeathRegistry::Lookup. +class DeathRegistryFileBuildJob < ApplicationJob + queue_as :default + + def perform + count = DeathRegistry::FileBuilder.new.call + Rails.logger.info("DeathRegistryFileBuildJob: wrote #{count} records to #{DeathRegistry.file_path}") + end +end diff --git a/app/services/death_registry.rb b/app/services/death_registry.rb new file mode 100644 index 0000000000..e17e9c9d8b --- /dev/null +++ b/app/services/death_registry.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Local copy of the Population Register death open data +# (https://andmed.eesti.ee/datasets/surmaandmed), reduced to a sorted file of +# Estonian personal identity codes and death dates. +module DeathRegistry + class Error < StandardError; end + class FileUnavailable < Error; end + + DEFAULT_SOURCE_URLS = %w[ + https://opendata.smit.ee/etl/rahvastik/surmaandmed_1926_kuni_eelmise_aasta_lopuni.csv + https://opendata.smit.ee/etl/rahvastik/surmaandmed_jooksev_aasta.csv + ].freeze + DEFAULT_MAX_FILE_AGE_DAYS = 8 + DEFAULT_MIN_RECORDS = 100_000 + + # Every line is "<11-digit ident>;\n", so a record can be read by + # seeking to index * RECORD_SIZE. + IDENT_LENGTH = 11 + RECORD_SIZE = IDENT_LENGTH + 1 + 10 + 1 + IDENT_FORMAT = /\A\d{#{IDENT_LENGTH}}\z/.freeze + + module_function + + def file_path + ENV['death_registry_file_path'].presence || + Rails.root.join('tmp', 'death_registry', 'deaths.txt').to_s + end + + def source_urls + ENV['death_registry_source_urls'].presence&.split(',')&.map(&:strip) || DEFAULT_SOURCE_URLS + end + + def max_file_age + (ENV['death_registry_max_file_age_days'].presence || DEFAULT_MAX_FILE_AGE_DAYS).to_i.days + end + + def min_records + (ENV['death_registry_min_records'].presence || DEFAULT_MIN_RECORDS).to_i + end +end diff --git a/app/services/death_registry/file_builder.rb b/app/services/death_registry/file_builder.rb new file mode 100644 index 0000000000..dd18c10759 --- /dev/null +++ b/app/services/death_registry/file_builder.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require 'csv' + +module DeathRegistry + # Downloads the death open data CSVs and replaces the local lookup file. + # + # The new file is written next to the old one and renamed over it, so readers + # see either the old or the new file, never a partial one. If a download fails + # or yields suspiciously few records, the old file is kept. + class FileBuilder + OPEN_TIMEOUT = 30 + READ_TIMEOUT = 300 + DATE_FORMAT = /\A\d{4}-\d{2}-\d{2}\z/.freeze + + attr_reader :path, :source_urls, :min_records + + def initialize(path: DeathRegistry.file_path, + source_urls: DeathRegistry.source_urls, + min_records: DeathRegistry.min_records) + @path = path + @source_urls = source_urls + @min_records = min_records + end + + # Returns the number of records written. + def call + records = source_urls.flat_map { |url| with_download(url) { |file| parse(file) } } + records = unique_by_ident(records.sort!) + + if records.size < min_records + raise Error, "Death registry has only #{records.size} records, expected at least #{min_records}" + end + + write_atomically(records) + records.size + end + + private + + def with_download(url) + uri = URI.parse(url) + + Tempfile.create(['death_registry', '.csv'], binmode: true) do |file| + Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', + open_timeout: OPEN_TIMEOUT, + read_timeout: READ_TIMEOUT) do |http| + http.request_get(uri.request_uri) do |response| + raise Error, "Downloading #{url} failed: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess) + + response.read_body { |chunk| file.write(chunk) } + end + end + + file.flush + file.rewind + yield file + end + end + + # Rows without a valid ident or death date (the source uses "-" for + # missing values) are skipped. + def parse(file) + records = [] + csv = CSV.new(file, col_sep: ';', headers: true, encoding: 'bom|utf-8') + + csv.each do |row| + ident = row['isikukood'].to_s.strip + death_date = row['surma_kp'].to_s.strip + next unless ident.match?(IDENT_FORMAT) && death_date.match?(DATE_FORMAT) + + records << "#{ident};#{death_date}\n" + end + + missing = %w[isikukood surma_kp] - Array(csv.headers) + raise Error, "Death registry CSV is missing columns: #{missing.join(', ')}" if missing.any? + + records + end + + # Records are sorted, so the earliest death date of a duplicated ident + # comes first and is the one kept. + def unique_by_ident(records) + records.each_with_object([]) do |record, unique| + unique << record unless unique.last&.start_with?(record[0, IDENT_LENGTH]) + end + end + + def write_atomically(records) + FileUtils.mkdir_p(File.dirname(path)) + tmp_path = "#{path}.#{Process.pid}.tmp" + + File.open(tmp_path, 'wb') do |file| + records.each { |record| file.write(record) } + file.fsync + end + + File.rename(tmp_path, path) + ensure + FileUtils.rm_f(tmp_path) if tmp_path + end + end +end diff --git a/app/services/death_registry/lookup.rb b/app/services/death_registry/lookup.rb new file mode 100644 index 0000000000..90be25813a --- /dev/null +++ b/app/services/death_registry/lookup.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module DeathRegistry + # Finds a death date by binary search in the file built by + # DeathRegistry::FileBuilder, without loading the file into memory. + # + # Raises FileUnavailable when the file is missing, malformed or older than + # max_age, so callers never mistake a missing file for "not deceased". + class Lookup + attr_reader :path, :max_age + + def initialize(path: DeathRegistry.file_path, max_age: DeathRegistry.max_file_age) + @path = path + @max_age = max_age + end + + def available? + File.file?(path) && File.mtime(path) >= max_age.ago && (File.size(path) % RECORD_SIZE).zero? + end + + # Returns the death date as a Date, or nil if the ident is not in the file. + def death_date(ident) + raise FileUnavailable, "Death registry file #{path} is missing, stale or malformed" unless available? + + ident = ident.to_s + return unless ident.match?(IDENT_FORMAT) + + File.open(path, 'rb') { |file| search(file, ident) } + end + + def deceased?(ident) + death_date(ident).present? + end + + private + + def search(file, ident) + low = 0 + high = (file.size / RECORD_SIZE) - 1 + + while low <= high + mid = (low + high) / 2 + file.seek(mid * RECORD_SIZE) + record = file.read(RECORD_SIZE) + + case record[0, IDENT_LENGTH] <=> ident + when 0 then return Date.iso8601(record[IDENT_LENGTH + 1, 10]) + when -1 then low = mid + 1 + else high = mid - 1 + end + end + + nil + end + end +end diff --git a/config/application.yml.sample b/config/application.yml.sample index 12da2f8e60..770350eb74 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -264,6 +264,12 @@ business_registry_allowed_origins: "http://registry.test,https://registry.test" business_registry_allowed_ips: "127.0.0.1,0.0.0.0,192.168.65.1" business_registry_api_tokens: "token1,token2" +# Local copy of the Population Register death open data (DeathRegistry) +death_registry_file_path: '' # defaults to tmp/death_registry/deaths.txt +death_registry_source_urls: '' # comma-separated; defaults to the opendata.smit.ee CSVs +death_registry_max_file_age_days: '8' +death_registry_min_records: '100000' + staging: action_mailer_default_host: 'registry.staging.test' action_mailer_default_from: 'no-reply@registry.staging.test' diff --git a/config/schedule.rb b/config/schedule.rb index 123fb0b60a..fd4bf89d49 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -82,6 +82,13 @@ every :day, at: '12:01am' do rake 'invoices:process_payments' end + + # Population Register death open data omits the newest 7 days, so a weekly + # rebuild is enough; DeathRegistry::Lookup treats the file as stale after + # death_registry_max_file_age_days. + every :monday, at: '4:00am' do + runner 'DeathRegistryFileBuildJob.perform_now' + end end every 10.minutes do diff --git a/test/jobs/death_registry_file_build_job_test.rb b/test/jobs/death_registry_file_build_job_test.rb new file mode 100644 index 0000000000..e417c6dcde --- /dev/null +++ b/test/jobs/death_registry_file_build_job_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +class DeathRegistryFileBuildJobTest < ActiveJob::TestCase + setup do + @dir = Dir.mktmpdir + @path = File.join(@dir, 'deaths.txt') + @url = 'https://opendata.test/surmaandmed.csv' + ENV['death_registry_file_path'] = @path + ENV['death_registry_source_urls'] = @url + ENV['death_registry_min_records'] = '1' + end + + teardown do + ENV.delete('death_registry_file_path') + ENV.delete('death_registry_source_urls') + ENV.delete('death_registry_min_records') + FileUtils.rm_rf(@dir) + end + + def test_builds_file_from_configured_sources + stub_request(:get, @url).to_return(status: 200, body: <<~CSV) + eesnimi;perenimi;isikukood;synni_kp;surma_kp + "JAAN";"TAMM";"37001010002";"1970-01-01";"2019-03-04" + CSV + + DeathRegistryFileBuildJob.perform_now + + assert_equal "37001010002;2019-03-04\n", File.read(@path) + end +end diff --git a/test/services/death_registry/file_builder_test.rb b/test/services/death_registry/file_builder_test.rb new file mode 100644 index 0000000000..1187805861 --- /dev/null +++ b/test/services/death_registry/file_builder_test.rb @@ -0,0 +1,114 @@ +require 'test_helper' + +class DeathRegistry::FileBuilderTest < ActiveSupport::TestCase + HISTORY_URL = 'https://opendata.test/surmaandmed_ajalugu.csv'.freeze + CURRENT_URL = 'https://opendata.test/surmaandmed_jooksev_aasta.csv'.freeze + HEADER = "eesnimi;perenimi;isikukood;synni_kp;surma_kp\n".freeze + + setup do + @dir = Dir.mktmpdir + @path = File.join(@dir, 'deaths.txt') + end + + teardown do + FileUtils.rm_rf(@dir) + end + + def test_writes_sorted_fixed_width_records_from_all_sources + stub_csv(HISTORY_URL, <<~CSV) + "MARI";"MAASIKAS";"48001010001";"1980-01-01";"2020-05-06" + "JAAN";"TAMM";"37001010002";"1970-01-01";"2019-03-04" + CSV + stub_csv(CURRENT_URL, <<~CSV) + "PEETER";"KASK";"39001010003";"1990-01-01";"2026-02-03" + CSV + + assert_equal 3, build + + assert_equal "37001010002;2019-03-04\n" \ + "39001010003;2026-02-03\n" \ + "48001010001;2020-05-06\n", File.read(@path) + end + + def test_skips_rows_without_valid_ident_or_death_date + stub_csv(HISTORY_URL, <<~CSV) + "MARI";"MAASIKAS";-;"1880-01-01";"1930-05-06" + "JAAN";"TAMM";"370010100";"1970-01-01";"2019-03-04" + "ANU";"SAAR";"47001010004";"1970-01-01";- + "PEETER";"KASK";"39001010003";"1990-01-01";"2026-02-03" + CSV + stub_csv(CURRENT_URL, '') + + assert_equal 1, build + assert_equal "39001010003;2026-02-03\n", File.read(@path) + end + + def test_keeps_earliest_death_date_of_duplicated_ident + stub_csv(HISTORY_URL, <<~CSV) + "JAAN";"TAMM";"37001010002";"1970-01-01";"2019-03-04" + CSV + stub_csv(CURRENT_URL, <<~CSV) + "JAAN";"TAMM";"37001010002";"1970-01-01";"2018-01-01" + CSV + + assert_equal 1, build + assert_equal "37001010002;2018-01-01\n", File.read(@path) + end + + def test_keeps_old_file_when_download_fails + File.write(@path, "37001010002;2019-03-04\n") + stub_csv(HISTORY_URL, %("JAAN";"TAMM";"39001010003";"1990-01-01";"2026-02-03"\n)) + stub_request(:get, CURRENT_URL).to_return(status: 503) + + error = assert_raises(DeathRegistry::Error) { build } + + assert_includes error.message, 'HTTP 503' + assert_equal "37001010002;2019-03-04\n", File.read(@path) + end + + def test_keeps_old_file_when_too_few_records + File.write(@path, "37001010002;2019-03-04\n") + stub_csv(HISTORY_URL, %("JAAN";"TAMM";"39001010003";"1990-01-01";"2026-02-03"\n)) + stub_csv(CURRENT_URL, '') + + error = assert_raises(DeathRegistry::Error) { build(min_records: 2) } + + assert_includes error.message, 'only 1 records' + assert_equal "37001010002;2019-03-04\n", File.read(@path) + assert_equal ['deaths.txt'], Dir.children(@dir) + end + + def test_fails_when_csv_format_changes + stub_request(:get, HISTORY_URL).to_return(status: 200, body: "nimi,kood\nJAAN,37001010002\n") + stub_csv(CURRENT_URL, '') + + assert_raises(DeathRegistry::Error) { build } + assert_not File.exist?(@path) + end + + def test_built_file_works_with_lookup + stub_csv(HISTORY_URL, <<~CSV) + "MARI";"MAASIKAS";"48001010001";"1980-01-01";"2020-05-06" + "JAAN";"TAMM";"37001010002";"1970-01-01";"2019-03-04" + CSV + stub_csv(CURRENT_URL, '') + build + + lookup = DeathRegistry::Lookup.new(path: @path) + + assert_equal Date.new(2020, 5, 6), lookup.death_date('48001010001') + assert_nil lookup.death_date('38001010009') + end + + private + + def build(min_records: 1) + DeathRegistry::FileBuilder.new(path: @path, + source_urls: [HISTORY_URL, CURRENT_URL], + min_records: min_records).call + end + + def stub_csv(url, rows) + stub_request(:get, url).to_return(status: 200, body: HEADER + rows) + end +end diff --git a/test/services/death_registry/lookup_test.rb b/test/services/death_registry/lookup_test.rb new file mode 100644 index 0000000000..359381d830 --- /dev/null +++ b/test/services/death_registry/lookup_test.rb @@ -0,0 +1,72 @@ +require 'test_helper' + +class DeathRegistry::LookupTest < ActiveSupport::TestCase + RECORDS = { + '33109066015' => '2026-01-01', + '35809012714' => '2025-12-31', + '37509205215' => '2024-06-15', + '43812063712' => '2019-03-04', + '60001019906' => '2001-02-03', + }.freeze + + setup do + @dir = Dir.mktmpdir + @path = File.join(@dir, 'deaths.txt') + File.write(@path, RECORDS.map { |ident, date| "#{ident};#{date}\n" }.join) + @lookup = DeathRegistry::Lookup.new(path: @path, max_age: 8.days) + end + + teardown do + FileUtils.rm_rf(@dir) + end + + def test_finds_every_record + RECORDS.each do |ident, date| + assert_equal Date.iso8601(date), @lookup.death_date(ident), ident + end + end + + def test_returns_nil_for_ident_not_in_file + assert_nil @lookup.death_date('30001010000') + assert_nil @lookup.death_date('38001010000') + assert_nil @lookup.death_date('69912319999') + assert_not @lookup.deceased?('38001010000') + end + + def test_returns_nil_for_invalid_ident + assert_nil @lookup.death_date('3750920521') + assert_nil @lookup.death_date('375092052150') + assert_nil @lookup.death_date(nil) + end + + def test_deceased + assert @lookup.deceased?('37509205215') + end + + def test_raises_when_file_is_missing + File.delete(@path) + + assert_not @lookup.available? + assert_raises(DeathRegistry::FileUnavailable) { @lookup.death_date('37509205215') } + end + + def test_raises_when_file_is_stale + File.utime(9.days.ago.to_time, 9.days.ago.to_time, @path) + + assert_not @lookup.available? + assert_raises(DeathRegistry::FileUnavailable) { @lookup.death_date('37509205215') } + end + + def test_raises_when_file_is_malformed + File.write(@path, "37509205215;2024-06-15\npartial") + + assert_not @lookup.available? + assert_raises(DeathRegistry::FileUnavailable) { @lookup.death_date('37509205215') } + end + + def test_empty_file_finds_nothing + File.write(@path, '') + + assert_nil @lookup.death_date('37509205215') + end +end From 897f36ec3ad2f155fec0aeaef9bd3769dbf8ef29 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Mon, 19 Oct 2026 16:21:39 +0300 Subject: [PATCH 02/11] Reject deceased EE private contacts at creation Check new EE private contacts against the local death registry file when validate_deceased_contacts is enabled. A deceased person is rejected with EPP 2003 "Ident is invalid"; a missing or stale file logs a warning and lets the contact through. Add contacts.death_date and death_registry_checked_at with partial indexes, show them in admin, and add a death registry filter to the admin contact search. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/controllers/admin/contacts_controller.rb | 5 + app/interactions/actions/contact_create.rb | 19 ++++ app/models/contact.rb | 3 +- app/views/admin/contacts/index.haml | 5 + .../admin/contacts/partials/_general.haml | 8 ++ config/application.yml.sample | 1 + config/locales/admin/contacts.en.yml | 5 + config/locales/en.yml | 1 + config/locales/errors.et.yml | 1 + ...0_add_death_registry_fields_to_contacts.rb | 6 + ..._add_death_registry_indexes_to_contacts.rb | 10 ++ db/structure.sql | 22 +++- .../epp/contact/create/death_registry_test.rb | 70 ++++++++++++ .../v1/contacts/create_death_registry_test.rb | 103 ++++++++++++++++++ test/system/admin_area/contacts_test.rb | 31 ++++++ 15 files changed, 287 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20261019120000_add_death_registry_fields_to_contacts.rb create mode 100644 db/migrate/20261019120100_add_death_registry_indexes_to_contacts.rb create mode 100644 test/integration/epp/contact/create/death_registry_test.rb create mode 100644 test/integration/repp/v1/contacts/create_death_registry_test.rb diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb index de5397360b..8198c29eef 100644 --- a/app/controllers/admin/contacts_controller.rb +++ b/app/controllers/admin/contacts_controller.rb @@ -33,6 +33,11 @@ def filter_by_flags(contacts) contacts = contacts.where("ident_country_code is null or ident_country_code=''") end + case params[:death_registry] + when 'deceased' then contacts = contacts.where.not(death_date: nil) + when 'not_checked' then contacts = contacts.where(death_registry_checked_at: nil) + end + contacts end diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index 5e2d603036..1b96ba4728 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -15,6 +15,7 @@ def call maybe_validate_ident maybe_change_email maybe_company_is_relevant + maybe_person_is_alive commit maybe_validate_phone_number maybe_validate_contact @@ -115,6 +116,24 @@ def maybe_company_is_relevant @error = true end + # A missing or stale death registry file must not block contact creation: + # the contact is created unchecked and the daily death registry check picks it up. + def maybe_person_is_alive + return true if @error + return true unless ENV['validate_deceased_contacts'] == 'true' + return true unless contact.ident_type == 'priv' && contact.ident_country_code == 'EE' + + if DeathRegistry::Lookup.new.deceased?(contact.ident) + contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.ident_invalid')) + @error = true + else + contact.death_registry_checked_at = Time.zone.now + end + rescue DeathRegistry::FileUnavailable => e + Rails.logger.warn("Death registry check skipped for new contact: #{e.message}") + true + end + def maybe_attach_legal_doc ::Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false) end diff --git a/app/models/contact.rb b/app/models/contact.rb index 70c8cf3af2..8fdc1c9696 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -542,7 +542,8 @@ def modifies_address? def update_related_whois_records # not doing anything if no real changes - ignored_columns = %w[updated_at created_at statuses status_notes checked_company_at company_register_status] + ignored_columns = %w[updated_at created_at statuses status_notes checked_company_at company_register_status + death_date death_registry_checked_at] return if (previous_changes.keys - ignored_columns).empty? diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index 597b013bd4..1642fadf57 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -63,6 +63,11 @@ .form-group = label_tag :only_no_country_code, "Ident CC missing" = check_box_tag :only_no_country_code, '1',params[:only_no_country_code].eql?('1'), style: 'width:auto;height:auto;float:right' + .row + .col-md-3 + .form-group + = label_tag :death_registry, t('.death_registry') + = select_tag :death_registry, options_for_select([[t('.deceased'), 'deceased'], [t('.not_checked'), 'not_checked']], params[:death_registry]), { include_blank: true, class: 'form-control' } .row .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px'} diff --git a/app/views/admin/contacts/partials/_general.haml b/app/views/admin/contacts/partials/_general.haml index 2396861fb6..e4f297d388 100644 --- a/app/views/admin/contacts/partials/_general.haml +++ b/app/views/admin/contacts/partials/_general.haml @@ -26,6 +26,14 @@ %dt.left_25= t(:fax) %dd.left_25= @contact.fax + - if @contact.death_date + %dt.left_25= t('.death_date') + %dd.left_25= l(@contact.death_date) + + - if @contact.death_registry_checked_at + %dt.left_25= t('.death_registry_checked_at') + %dd.left_25= l(@contact.death_registry_checked_at, format: :short) + %br %dt.left_25= t('.created') diff --git a/config/application.yml.sample b/config/application.yml.sample index 770350eb74..84066db53c 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -269,6 +269,7 @@ death_registry_file_path: '' # defaults to tmp/death_registry/deaths.txt death_registry_source_urls: '' # comma-separated; defaults to the opendata.smit.ee CSVs death_registry_max_file_age_days: '8' death_registry_min_records: '100000' +validate_deceased_contacts: 'false' # reject new EE private contacts found in the death registry staging: action_mailer_default_host: 'registry.staging.test' diff --git a/config/locales/admin/contacts.en.yml b/config/locales/admin/contacts.en.yml index 295e33acee..5370d60a31 100644 --- a/config/locales/admin/contacts.en.yml +++ b/config/locales/admin/contacts.en.yml @@ -4,6 +4,9 @@ en: index: reset_btn: Reset csv_btn: CSV + death_registry: Death registry + deceased: Deceased + not_checked: Not checked edit: new_status_btn: Add new status @@ -13,6 +16,8 @@ en: general: created: Created updated: Updated + death_date: Death date + death_registry_checked_at: Death registry checked domains: roles: Roles diff --git a/config/locales/en.yml b/config/locales/en.yml index 4c162fbb7f..f5ed6dcf4d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -208,6 +208,7 @@ en: failed_epp_conn: 'Failed to open connection to EPP server!' epp_conn_error: 'CONNECTION ERROR - Is the EPP server running?' company_not_registered: 'Company is not registered' + ident_invalid: 'Ident is invalid' invalid_ident_type: Invalid ident type domain_name_blocked: 'Data management policy violation: Domain name is blocked [name]' code: 'Code' diff --git a/config/locales/errors.et.yml b/config/locales/errors.et.yml index e72b3bbe91..a0f1c79c67 100644 --- a/config/locales/errors.et.yml +++ b/config/locales/errors.et.yml @@ -3,4 +3,5 @@ et: messages: required_ident_attribute_missing: 'Kohustuslik ident atribuut puudub: %{key}' company_not_registered: Ettevõte pole registreeritud + ident_invalid: Isikukood on kehtetu invalid_ident_type: Vigane identi tüüp diff --git a/db/migrate/20261019120000_add_death_registry_fields_to_contacts.rb b/db/migrate/20261019120000_add_death_registry_fields_to_contacts.rb new file mode 100644 index 0000000000..160fd94cea --- /dev/null +++ b/db/migrate/20261019120000_add_death_registry_fields_to_contacts.rb @@ -0,0 +1,6 @@ +class AddDeathRegistryFieldsToContacts < ActiveRecord::Migration[6.1] + def change + add_column :contacts, :death_date, :date + add_column :contacts, :death_registry_checked_at, :datetime + end +end diff --git a/db/migrate/20261019120100_add_death_registry_indexes_to_contacts.rb b/db/migrate/20261019120100_add_death_registry_indexes_to_contacts.rb new file mode 100644 index 0000000000..0c1d371105 --- /dev/null +++ b/db/migrate/20261019120100_add_death_registry_indexes_to_contacts.rb @@ -0,0 +1,10 @@ +class AddDeathRegistryIndexesToContacts < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def change + add_index :contacts, :death_date, where: 'death_date IS NOT NULL', algorithm: :concurrently + add_index :contacts, :death_registry_checked_at, + where: "ident_type = 'priv' AND ident_country_code = 'EE'", + algorithm: :concurrently + end +end diff --git a/db/structure.sql b/db/structure.sql index 6bff083524..46037583dd 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -800,7 +800,9 @@ CREATE TABLE public.contacts ( company_register_status character varying, system_disclosed_attributes character varying[] DEFAULT '{}'::character varying[], verification_pending_at timestamp without time zone, - verification_snapshot jsonb DEFAULT '{}'::jsonb + verification_snapshot jsonb DEFAULT '{}'::jsonb, + death_date date, + death_registry_checked_at timestamp without time zone ); @@ -4546,6 +4548,20 @@ CREATE INDEX index_contact_requests_on_whois_record_id ON public.contact_request CREATE INDEX index_contacts_on_code ON public.contacts USING btree (code); +-- +-- Name: index_contacts_on_death_date; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_contacts_on_death_date ON public.contacts USING btree (death_date) WHERE (death_date IS NOT NULL); + + +-- +-- Name: index_contacts_on_death_registry_checked_at; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_contacts_on_death_registry_checked_at ON public.contacts USING btree (death_registry_checked_at) WHERE (((ident_type)::text = 'priv'::text) AND ((ident_country_code)::text = 'EE'::text)); + + -- -- Name: index_contacts_on_email; Type: INDEX; Schema: public; Owner: - -- @@ -6085,6 +6101,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20261005090100'), ('20261005090200'), ('20261012120000'), -('20261016100000'); +('20261016100000'), +('20261019120000'), +('20261019120100'); diff --git a/test/integration/epp/contact/create/death_registry_test.rb b/test/integration/epp/contact/create/death_registry_test.rb new file mode 100644 index 0000000000..ea18bb3828 --- /dev/null +++ b/test/integration/epp/contact/create/death_registry_test.rb @@ -0,0 +1,70 @@ +require 'test_helper' + +class EppContactCreateDeathRegistryTest < EppTestCase + DECEASED_IDENT = '39708290069'.freeze + + setup do + adapter = ENV['shunter_default_adapter'].constantize.new + adapter&.clear! + + @dir = Dir.mktmpdir + @death_file = File.join(@dir, 'deaths.txt') + File.write(@death_file, "#{DECEASED_IDENT};2026-01-01\n") + ENV['death_registry_file_path'] = @death_file + ENV['validate_deceased_contacts'] = 'true' + end + + teardown do + ENV.delete('death_registry_file_path') + ENV.delete('validate_deceased_contacts') + FileUtils.rm_rf(@dir) + end + + def test_rejects_estonian_private_person_found_in_death_registry + assert_no_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml(DECEASED_IDENT) }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :required_parameter_missing + assert_includes response.body, 'Ident is invalid' + end + + def test_creates_contact_when_person_is_not_in_death_registry + File.write(@death_file, "38001010000;2026-01-01\n") + + assert_difference 'Contact.count' do + post epp_create_path, params: { frame: request_xml(DECEASED_IDENT) }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :completed_successfully + assert_not_nil Contact.find_by(name: 'John Doe').death_registry_checked_at + end + + private + + def request_xml(ident) + <<-XML + + + + + + + John Doe + + +372.51111112 + john@inbox.test + + + + + #{ident} + + + + + XML + end +end diff --git a/test/integration/repp/v1/contacts/create_death_registry_test.rb b/test/integration/repp/v1/contacts/create_death_registry_test.rb new file mode 100644 index 0000000000..3dca7c2d33 --- /dev/null +++ b/test/integration/repp/v1/contacts/create_death_registry_test.rb @@ -0,0 +1,103 @@ +require 'test_helper' + +class ReppV1ContactsCreateDeathRegistryTest < ActionDispatch::IntegrationTest + DECEASED_IDENT = '39708290069'.freeze + + setup do + @user = users(:api_bestnames) + token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}") + @auth_headers = { 'Authorization' => "Basic #{token}" } + + adapter = ENV['shunter_default_adapter'].constantize.new + adapter&.clear! + + @dir = Dir.mktmpdir + @death_file = File.join(@dir, 'deaths.txt') + File.write(@death_file, "#{DECEASED_IDENT};2026-01-01\n") + ENV['death_registry_file_path'] = @death_file + ENV['validate_deceased_contacts'] = 'true' + end + + teardown do + ENV.delete('death_registry_file_path') + ENV.delete('validate_deceased_contacts') + FileUtils.rm_rf(@dir) + end + + def test_rejects_estonian_private_person_found_in_death_registry + assert_no_difference 'Contact.count' do + post '/repp/v1/contacts', headers: @auth_headers, params: request_body(ident: DECEASED_IDENT) + end + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :bad_request + assert_equal 2003, json[:code] + assert_includes json[:message], 'Ident is invalid' + end + + def test_creates_contact_and_saves_check_time_when_person_is_not_in_death_registry + File.write(@death_file, "38001010000;2026-01-01\n") + + travel_to Time.zone.parse('2026-10-19 10:00') do + post '/repp/v1/contacts', headers: @auth_headers, params: request_body(ident: DECEASED_IDENT) + end + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + contact = Contact.find_by(code: json[:data][:contact][:code]) + assert_equal Time.zone.parse('2026-10-19 10:00'), contact.death_registry_checked_at + assert_nil contact.death_date + end + + def test_creates_contact_without_check_time_when_death_registry_file_is_missing + File.delete(@death_file) + + post '/repp/v1/contacts', headers: @auth_headers, params: request_body(ident: DECEASED_IDENT) + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_nil Contact.find_by(code: json[:data][:contact][:code]).death_registry_checked_at + end + + def test_creates_contact_without_check_time_when_death_registry_file_is_stale + File.utime(9.days.ago.to_time, 9.days.ago.to_time, @death_file) + + post '/repp/v1/contacts', headers: @auth_headers, params: request_body(ident: DECEASED_IDENT) + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_nil Contact.find_by(code: json[:data][:contact][:code]).death_registry_checked_at + end + + def test_does_not_check_foreign_private_person + post '/repp/v1/contacts', headers: @auth_headers, + params: request_body(ident: DECEASED_IDENT, country_code: 'LV') + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_nil Contact.find_by(code: json[:data][:contact][:code]).death_registry_checked_at + end + + def test_does_not_check_when_validation_is_disabled + ENV['validate_deceased_contacts'] = 'false' + + post '/repp/v1/contacts', headers: @auth_headers, params: request_body(ident: DECEASED_IDENT) + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_nil Contact.find_by(code: json[:data][:contact][:code]).death_registry_checked_at + end + + private + + def request_body(ident:, country_code: 'EE') + { + contact: { + name: 'John Doe', + phone: '+372.51111112', + email: 'john@inbox.test', + ident: { ident_type: 'priv', ident_country_code: country_code, ident: ident }, + }, + } + end +end diff --git a/test/system/admin_area/contacts_test.rb b/test/system/admin_area/contacts_test.rb index 8fca6684bf..0e2f7f5870 100644 --- a/test/system/admin_area/contacts_test.rb +++ b/test/system/admin_area/contacts_test.rb @@ -19,6 +19,37 @@ def test_update_contact assert_text 'Contact updated' end + def test_display_death_registry_data + @contact.update_columns(death_date: Date.new(2026, 1, 1), + death_registry_checked_at: Time.zone.parse('2026-10-19 10:00')) + + visit admin_contact_path(@contact) + + assert_text 'Death date' + assert_text 'Death registry checked' + end + + def test_filters_deceased_contacts + @contact.update_columns(death_date: Date.new(2026, 1, 1)) + + visit admin_contacts_path + select 'Deceased', from: 'death_registry' + find('.btn.btn-primary').click + + assert_text @contact.code + assert_no_text contacts(:acme_ltd).code + end + + def test_filters_contacts_not_checked_against_death_registry + Contact.update_all(death_registry_checked_at: Time.zone.now) + @contact.update_columns(death_registry_checked_at: nil) + + visit admin_contacts_path(death_registry: 'not_checked') + + assert_text @contact.code + assert_no_text contacts(:acme_ltd).code + end + def test_display_list visit admin_contacts_path From 0ed6fffa1a26bf41686ab28459fcc7d54e951b17 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 20 Oct 2026 10:01:32 +0300 Subject: [PATCH 03/11] Add daily death registry check of EE private contacts DeathRegistryCheckJob checks each EE private contact linked to a domain once a year against the local death registry file. A deceased person gets a death_date; a deceased registrant whose death is less than six months old triggers a poll message to the registrar for each domain. The job rebuilds the file itself when it is older than seven days, so production needs a single cron line. Dry run mode, on by default, saves nothing and emails the admin a CSV report instead. File problems are emailed to the admin. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/jobs/death_registry_check_job.rb | 163 ++++++++++++++ app/mailers/admin_mailer.rb | 18 ++ .../death_registry_dry_run_report.html.erb | 5 + .../death_registry_problem.html.erb | 7 + config/application.yml.sample | 1 + config/locales/en.yml | 1 + config/schedule.rb | 10 +- test/jobs/death_registry_check_job_test.rb | 207 ++++++++++++++++++ 8 files changed, 407 insertions(+), 5 deletions(-) create mode 100644 app/jobs/death_registry_check_job.rb create mode 100644 app/views/admin_mailer/death_registry_dry_run_report.html.erb create mode 100644 app/views/admin_mailer/death_registry_problem.html.erb create mode 100644 test/jobs/death_registry_check_job_test.rb diff --git a/app/jobs/death_registry_check_job.rb b/app/jobs/death_registry_check_job.rb new file mode 100644 index 0000000000..fffafe6de2 --- /dev/null +++ b/app/jobs/death_registry_check_job.rb @@ -0,0 +1,163 @@ +# frozen_string_literal: true + +require 'csv' + +# Daily check of Estonian private person contacts against the local death +# registry file. Every contact linked to a domain is checked once a year; a run +# only takes the contacts whose last check is older than CHECK_INTERVAL. +# +# The job also rebuilds the death registry file when it is older than +# FILE_REBUILD_AGE, so production needs a single cron line. +# +# In dry run mode (the default) nothing is saved and no poll messages are sent; +# the findings are written to a CSV report that is emailed to the admin. +class DeathRegistryCheckJob < ApplicationJob + CHECK_INTERVAL = 1.year + FORCE_DELETE_DELAY = 6.months + FILE_REBUILD_AGE = 7.days + BATCH_SIZE = 1000 + REPORT_HEADERS = %w[contact_code ident death_date roles domains registrars six_months_passed].freeze + + queue_as :default + + def self.dry_run? + ENV['death_registry_dry_run'] != 'false' + end + + def perform(dry_run: self.class.dry_run?) + @dry_run = dry_run + @problems = [] + @findings = [] + @checked = 0 + + rebuild_file_if_old + lookup = DeathRegistry::Lookup.new + + if lookup.available? + ::PaperTrail.request(whodunnit: "cron - #{self.class.name}") { check_contacts(lookup) } + report_dry_run if dry_run + Rails.logger.info("#{self.class.name}: checked #{@checked} contacts, found #{@findings.size} " \ + "deceased#{' (dry run)' if dry_run}") + else + @problems << "Death registry file #{lookup.path} is missing, stale or malformed. " \ + 'Contacts were not checked.' + end + + notify_admin_about_problems + end + + private + + attr_reader :dry_run + + def rebuild_file_if_old + path = DeathRegistry.file_path + return if File.file?(path) && File.mtime(path) >= FILE_REBUILD_AGE.ago + + count = DeathRegistry::FileBuilder.new.call + Rails.logger.info("#{self.class.name}: rebuilt #{path} with #{count} records") + rescue StandardError => e + Rails.logger.error("#{self.class.name}: rebuilding #{path} failed: #{e.message}") + @problems << "Rebuilding the death registry file failed: #{e.message}" + end + + def check_contacts(lookup) + due_contacts.find_in_batches(batch_size: BATCH_SIZE) do |contacts| + checked_at = Time.zone.now + alive_ids = [] + + contacts.each do |contact| + death_date = lookup.death_date(contact.ident) + death_date ? handle_deceased(contact, death_date, checked_at) : alive_ids << contact.id + end + + Contact.where(id: alive_ids).update_all(death_registry_checked_at: checked_at) unless dry_run || alive_ids.empty? + @checked += contacts.size + end + end + + def due_contacts + Contact.where(ident_type: Contact::PRIV, ident_country_code: 'EE', death_date: nil) + .where('contacts.death_registry_checked_at IS NULL OR contacts.death_registry_checked_at < ?', + CHECK_INTERVAL.ago) + .where('EXISTS (SELECT 1 FROM domains WHERE domains.registrant_id = contacts.id) ' \ + 'OR EXISTS (SELECT 1 FROM domain_contacts WHERE domain_contacts.contact_id = contacts.id)') + end + + def handle_deceased(contact, death_date, checked_at) + registrant_domains = contact.registrant_domains.includes(:registrar).to_a + @findings << finding_row(contact, death_date, registrant_domains) + return if dry_run + + contact.death_date = death_date + contact.death_registry_checked_at = checked_at + contact.save!(validate: false) + + notify_registrars(contact, registrant_domains) unless force_delete_due?(death_date) + end + + def force_delete_due?(death_date) + death_date + FORCE_DELETE_DELAY <= Time.zone.today + end + + # Poll message A1. When six months have already passed, step 4 starts the + # force delete instead and its own poll message is sent. + def notify_registrars(contact, domains) + force_delete_start = contact.death_date + FORCE_DELETE_DELAY + 1.day + + domains.each do |domain| + domain.registrar.notifications.create!( + text: I18n.t('death_registry_registrant_deceased', + domain_name: domain.name, + ident: contact.ident, + death_date: contact.death_date, + force_delete_start: force_delete_start), + attached_obj_id: domain.id, + attached_obj_type: domain.class.name + ) + end + end + + def finding_row(contact, death_date, registrant_domains) + roles = Hash.new { |hash, key| hash[key] = [] } + registrant_domains.each { |domain| roles[domain] << 'registrant' } + contact.domain_contacts.includes(domain: :registrar).each do |domain_contact| + roles[domain_contact.domain] << domain_contact.type.delete_suffix('DomainContact').downcase + end + + [contact.code, contact.ident, death_date, + roles.values.flatten.uniq.sort.join(' '), + roles.map { |domain, domain_roles| "#{domain.name} (#{domain_roles.join(', ')})" }.sort.join(' '), + roles.keys.map { |domain| domain.registrar.name }.uniq.sort.join(', '), + force_delete_due?(death_date)] + end + + def report_dry_run + path = write_report + AdminMailer.death_registry_dry_run_report(report_path: path, checked: @checked, + found: @findings.size).deliver_now + rescue StandardError => e + Rails.logger.error("#{self.class.name}: dry run report failed: #{e.message}") + @problems << "Writing or sending the dry run report failed: #{e.message}" + end + + def write_report + dir = File.join(File.dirname(DeathRegistry.file_path), 'reports') + FileUtils.mkdir_p(dir) + path = File.join(dir, "dry_run_#{Time.zone.today.iso8601}.csv") + + CSV.open(path, 'w') do |csv| + csv << REPORT_HEADERS + @findings.each { |row| csv << row } + end + + path + end + + def notify_admin_about_problems + return if @problems.empty? + + Rails.logger.warn("#{self.class.name}: #{@problems.join(' ')}") + AdminMailer.death_registry_problem(problems: @problems).deliver_now + end +end diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index c6ae3d89ac..fba4b05087 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -7,4 +7,22 @@ def force_delete_daily_summary(force_deleted_summary, lifted_force_delete_summar subject: "Force Delete Daily Summary - #{Date.current}" ) end + + def death_registry_problem(problems:) + @problems = problems + mail( + to: ENV['admin_notification_email'] || 'admin@registry.test', + subject: "Death registry check problem - #{Date.current}" + ) + end + + def death_registry_dry_run_report(report_path:, checked:, found:) + @checked = checked + @found = found + attachments[File.basename(report_path)] = File.read(report_path) + mail( + to: ENV['admin_notification_email'] || 'admin@registry.test', + subject: "Death registry dry run report - #{Date.current}" + ) + end end diff --git a/app/views/admin_mailer/death_registry_dry_run_report.html.erb b/app/views/admin_mailer/death_registry_dry_run_report.html.erb new file mode 100644 index 0000000000..c2bac7df09 --- /dev/null +++ b/app/views/admin_mailer/death_registry_dry_run_report.html.erb @@ -0,0 +1,5 @@ +

Death registry dry run report - <%= Date.current %>

+ +

Checked contacts: <%= @checked %>

+

Deceased contacts found: <%= @found %>

+

The attached CSV lists the deceased contacts. Nothing was saved and no poll messages were sent.

diff --git a/app/views/admin_mailer/death_registry_problem.html.erb b/app/views/admin_mailer/death_registry_problem.html.erb new file mode 100644 index 0000000000..b6dfd8477b --- /dev/null +++ b/app/views/admin_mailer/death_registry_problem.html.erb @@ -0,0 +1,7 @@ +

Death registry check problem - <%= Date.current %>

+ +
    + <% @problems.each do |problem| %> +
  • <%= problem %>
  • + <% end %> +
diff --git a/config/application.yml.sample b/config/application.yml.sample index 84066db53c..4b060de50d 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -270,6 +270,7 @@ death_registry_source_urls: '' # comma-separated; defaults to the opendata.smit. death_registry_max_file_age_days: '8' death_registry_min_records: '100000' validate_deceased_contacts: 'false' # reject new EE private contacts found in the death registry +death_registry_dry_run: 'true' # DeathRegistryCheckJob only reports, saves nothing and sends no polls staging: action_mailer_default_host: 'registry.staging.test' diff --git a/config/locales/en.yml b/config/locales/en.yml index f5ed6dcf4d..79661232b2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -695,6 +695,7 @@ en: 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}. 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}' + death_registry_registrant_deceased: 'According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession.' number: currency: diff --git a/config/schedule.rb b/config/schedule.rb index fd4bf89d49..fcc05b09d4 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -83,11 +83,11 @@ rake 'invoices:process_payments' end - # Population Register death open data omits the newest 7 days, so a weekly - # rebuild is enough; DeathRegistry::Lookup treats the file as stale after - # death_registry_max_file_age_days. - every :monday, at: '4:00am' do - runner 'DeathRegistryFileBuildJob.perform_now' + # Checks EE private contacts against the death registry once a year each. + # The job rebuilds the death registry file itself when it is older than 7 + # days; the open data omits the newest 7 days, so weekly is enough. + every :day, at: '5:00am' do + runner 'DeathRegistryCheckJob.perform_now' end end diff --git a/test/jobs/death_registry_check_job_test.rb b/test/jobs/death_registry_check_job_test.rb new file mode 100644 index 0000000000..c7fe227305 --- /dev/null +++ b/test/jobs/death_registry_check_job_test.rb @@ -0,0 +1,207 @@ +require 'test_helper' + +class DeathRegistryCheckJobTest < ActiveJob::TestCase + REGISTRANT_IDENT = '39708290069'.freeze + ADMIN_IDENT = '49001010000'.freeze + ALIVE_IDENT = '38001010000'.freeze + UNLINKED_IDENT = '38501010000'.freeze + + setup do + @dir = Dir.mktmpdir + @path = File.join(@dir, 'deaths.txt') + @url = 'https://opendata.test/surmaandmed.csv' + ENV['death_registry_file_path'] = @path + ENV['death_registry_source_urls'] = @url + ENV['death_registry_min_records'] = '1' + ActionMailer::Base.deliveries.clear + + @registrant = contacts(:john) + @admin = contacts(:jane) + @alive = contacts(:william) + @unlinked = contacts(:identical_to_william) + make_estonian_person(@registrant, REGISTRANT_IDENT) + make_estonian_person(@admin, ADMIN_IDENT) + make_estonian_person(@alive, ALIVE_IDENT) + make_estonian_person(@unlinked, UNLINKED_IDENT) + + @recent_death = Time.zone.today - 1.month + write_death_file(REGISTRANT_IDENT => @recent_death, ADMIN_IDENT => @recent_death, + UNLINKED_IDENT => @recent_death) + end + + teardown do + ENV.delete('death_registry_file_path') + ENV.delete('death_registry_source_urls') + ENV.delete('death_registry_min_records') + ENV.delete('death_registry_dry_run') + FileUtils.rm_rf(@dir) + end + + def test_dry_run_is_the_default_and_changes_nothing + assert DeathRegistryCheckJob.dry_run? + + assert_no_difference ['Notification.count', 'Version::ContactVersion.count'] do + DeathRegistryCheckJob.perform_now + end + + [@registrant, @admin, @alive].each do |contact| + contact.reload + assert_nil contact.death_date + assert_nil contact.death_registry_checked_at + end + end + + def test_dry_run_emails_report_of_deceased_contacts + DeathRegistryCheckJob.perform_now + + mail = ActionMailer::Base.deliveries.last + assert_equal 'Death registry dry run report', mail.subject.split(' - ').first + report = CSV.parse(mail.attachments.first.decoded, headers: true) + assert_equal [REGISTRANT_IDENT, ADMIN_IDENT].sort, report.map { |row| row['ident'] }.sort + + registrant_row = report.find { |row| row['ident'] == REGISTRANT_IDENT } + assert_equal @registrant.code, registrant_row['contact_code'] + assert_equal @recent_death.iso8601, registrant_row['death_date'] + assert_includes registrant_row['roles'], 'registrant' + assert_includes registrant_row['domains'], 'shop.test (registrant)' + assert_equal 'false', registrant_row['six_months_passed'] + assert File.exist?(File.join(@dir, 'reports', "dry_run_#{Time.zone.today.iso8601}.csv")) + end + + def test_saves_death_date_and_notifies_registrar_of_each_registrant_domain + ENV['death_registry_dry_run'] = 'false' + + assert_difference 'Version::ContactVersion.count', 2 do + DeathRegistryCheckJob.perform_now + end + + @registrant.reload + assert_equal @recent_death, @registrant.death_date + assert_not_nil @registrant.death_registry_checked_at + + texts = Notification.where('text LIKE ?', "%(ident #{REGISTRANT_IDENT})%").pluck(:text) + assert_equal @registrant.registrant_domains.count, texts.size + assert texts.any? { |text| text.include?('domain shop.test') } + assert texts.all? { |text| text.include?((@recent_death + 6.months + 1.day).to_s) } + end + + def test_saves_only_death_date_for_deceased_admin_contact + ENV['death_registry_dry_run'] = 'false' + + DeathRegistryCheckJob.perform_now + + assert_equal @recent_death, @admin.reload.death_date + assert_empty Notification.where('text LIKE ?', "%#{ADMIN_IDENT}%") + end + + def test_no_poll_when_six_months_have_passed + ENV['death_registry_dry_run'] = 'false' + old_death = Time.zone.today - 6.months + write_death_file(REGISTRANT_IDENT => old_death) + + assert_no_difference 'Notification.count' do + DeathRegistryCheckJob.perform_now + end + + assert_equal old_death, @registrant.reload.death_date + end + + def test_saves_check_time_for_alive_contact_without_version + ENV['death_registry_dry_run'] = 'false' + + DeathRegistryCheckJob.perform_now + + @alive.reload + assert_nil @alive.death_date + assert_not_nil @alive.death_registry_checked_at + assert_empty @alive.versions.where('created_at > ?', 1.minute.ago) + end + + def test_skips_contacts_without_domains + ENV['death_registry_dry_run'] = 'false' + assert_not @unlinked.linked? + + DeathRegistryCheckJob.perform_now + + @unlinked.reload + assert_nil @unlinked.death_date + assert_nil @unlinked.death_registry_checked_at + end + + def test_rechecks_contact_only_after_a_year + ENV['death_registry_dry_run'] = 'false' + @registrant.update_columns(death_registry_checked_at: 11.months.ago) + + DeathRegistryCheckJob.perform_now + assert_nil @registrant.reload.death_date + + @registrant.update_columns(death_registry_checked_at: 13.months.ago) + + DeathRegistryCheckJob.perform_now + assert_equal @recent_death, @registrant.reload.death_date + end + + def test_skips_contacts_with_death_date + ENV['death_registry_dry_run'] = 'false' + @registrant.update_columns(death_date: Date.new(2020, 1, 1)) + + assert_no_difference 'Notification.count' do + DeathRegistryCheckJob.perform_now + end + + assert_equal Date.new(2020, 1, 1), @registrant.reload.death_date + end + + def test_rebuilds_file_older_than_seven_days + ENV['death_registry_dry_run'] = 'false' + File.utime(Time.now, (7.days.ago - 1.hour).to_time, @path) + stub_request(:get, @url).to_return(status: 200, body: <<~CSV) + isikukood;surma_kp + #{REGISTRANT_IDENT};2026-01-02 + CSV + + DeathRegistryCheckJob.perform_now + + assert_equal "#{REGISTRANT_IDENT};2026-01-02\n", File.read(@path) + assert_equal Date.new(2026, 1, 2), @registrant.reload.death_date + end + + def test_uses_old_file_and_emails_admin_when_rebuild_fails + ENV['death_registry_dry_run'] = 'false' + File.utime(Time.now, (7.days.ago - 1.hour).to_time, @path) + stub_request(:get, @url).to_return(status: 500) + + DeathRegistryCheckJob.perform_now + + assert_equal @recent_death, @registrant.reload.death_date + mail = ActionMailer::Base.deliveries.last + assert_equal 'Death registry check problem', mail.subject.split(' - ').first + assert_includes mail.body.to_s, 'Rebuilding the death registry file failed' + end + + def test_skips_run_and_emails_admin_when_file_is_unavailable + ENV['death_registry_dry_run'] = 'false' + FileUtils.rm_f(@path) + stub_request(:get, @url).to_return(status: 500) + + assert_no_difference 'Notification.count' do + DeathRegistryCheckJob.perform_now + end + + assert_nil @registrant.reload.death_registry_checked_at + assert_nil @alive.reload.death_registry_checked_at + mail = ActionMailer::Base.deliveries.last + assert_includes mail.body.to_s, 'Contacts were not checked' + end + + private + + def make_estonian_person(contact, ident) + contact.update_columns(ident: ident, ident_type: 'priv', ident_country_code: 'EE', + death_date: nil, death_registry_checked_at: nil) + end + + def write_death_file(records) + File.write(@path, records.sort.map { |ident, date| "#{ident};#{date.iso8601}\n" }.join) + end +end From 54a568df3260d8dd83dfab87ba788b4ae6d3f1c5 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 20 Oct 2026 13:12:37 +0300 Subject: [PATCH 04/11] Start fast track force delete six months after registrant's death DeathRegistryCheckJob starts a fast track force delete with reason deceased_person on the domains of a registrant who died at least six months ago. The person is looked up again before that and every day during the force delete; if they are no longer in the death registry, the death date is cleared and the force delete is cancelled. Domains that already have a force delete are left alone for now. Fast track force delete emails now use the template of the reason and store template_name, so a deleted company no longer gets the invalid email letter. A valid contact email no longer cancels a deceased registrant's force delete, and an admin cancelling it clears the death date. Show the force delete start date in admin, include status notes in the admin daily summary reason, and drop the Russian part of the force delete email subject. --- .../admin/domains/force_delete_controller.rb | 10 + .../domains/force_delete/notify_by_email.rb | 12 +- .../domains/force_delete/notify_registrar.rb | 13 + .../domains/force_delete/set_status.rb | 1 + app/jobs/death_registry_check_job.rb | 71 ++- .../force_delete_daily_admin_notifier_job.rb | 8 +- app/mailers/domain_delete_mailer.rb | 5 +- app/models/concerns/domain/force_delete.rb | 2 +- app/models/concerns/email_verifable.rb | 2 +- .../admin/domains/partials/_general.html.erb | 3 + config/locales/en.yml | 1 + config/locales/mailers/domain_delete.en.yml | 3 +- .../domains/force_delete_controller_test.rb | 444 +++++++++--------- test/jobs/death_registry_check_job_test.rb | 134 +++++- test/mailers/domain_delete_mailer_test.rb | 6 +- test/models/domain/force_delete_test.rb | 14 + 16 files changed, 493 insertions(+), 236 deletions(-) diff --git a/app/controllers/admin/domains/force_delete_controller.rb b/app/controllers/admin/domains/force_delete_controller.rb index 4fe85fa3b3..f630068456 100644 --- a/app/controllers/admin/domains/force_delete_controller.rb +++ b/app/controllers/admin/domains/force_delete_controller.rb @@ -17,12 +17,22 @@ def create def destroy authorize! :manage, domain + deceased_registrant = domain.registrant if domain.template_name == 'deceased_person' domain.cancel_force_delete + clear_death_date(deceased_registrant) if deceased_registrant redirect_to edit_admin_domain_url(domain), notice: t('.cancelled') end private + # Without this the death registry check would start the force delete + # again the next day. The contact is checked again in a year. + def clear_death_date(contact) + contact.death_date = nil + contact.death_registry_checked_at = Time.zone.now + contact.save!(validate: false) + end + def domain @domain ||= Domain.find(params[:domain_id]) end diff --git a/app/interactions/domains/force_delete/notify_by_email.rb b/app/interactions/domains/force_delete/notify_by_email.rb index 0e704ee99e..0bf2cd81f9 100644 --- a/app/interactions/domains/force_delete/notify_by_email.rb +++ b/app/interactions/domains/force_delete/notify_by_email.rb @@ -5,19 +5,21 @@ def execute return unless notify_by_email domain.skip_whois_record_update = false + template_name = domain.notification_template(explicit: reason) + if type == :fast_track - send_email - domain.update(contact_notification_sent_date: Time.zone.today) + send_email(template_name) + domain.update(contact_notification_sent_date: Time.zone.today, template_name: template_name) else - domain.update(template_name: domain.notification_template(explicit: reason)) + domain.update(template_name: template_name) end end - def send_email + def send_email(template_name) DomainDeleteMailer.forced(domain: domain, registrar: domain.registrar, registrant: domain.registrant, - template_name: domain.notification_template).deliver_now + template_name: template_name).deliver_now end end end diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index 8948450380..01be415ba7 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -2,6 +2,8 @@ module Domains module ForceDelete class NotifyRegistrar < Base def execute + return notify_deceased_person if reason == 'deceased_person' + email.present? ? notify_with_email : notify_without_email end @@ -17,6 +19,17 @@ def force_delete_start_date end end + def notify_deceased_person + domain.registrar.notifications.create!( + text: I18n.t('force_delete_deceased_person', + domain_name: domain.name, + ident: domain.registrant.ident, + force_delete_start_date: force_delete_start_date, + outzone_date: domain.outzone_date, + purge_date: domain.purge_date) + ) + end + def notify_without_email template = if reason == 'invalid_company' I18n.t('invalid_ident', diff --git a/app/interactions/domains/force_delete/set_status.rb b/app/interactions/domains/force_delete/set_status.rb index 204783d754..fc43b8e69b 100644 --- a/app/interactions/domains/force_delete/set_status.rb +++ b/app/interactions/domains/force_delete/set_status.rb @@ -29,6 +29,7 @@ def force_delete_soft def set_status_notes domain.status_notes[DomainStatus::FORCE_DELETE] = "Company no: #{domain.registrant.ident} #{"+ #{notes}" if notes.present?}" if reason == 'invalid_company' domain.status_notes[DomainStatus::FORCE_DELETE] = email if reason == 'invalid_email' + domain.status_notes[DomainStatus::FORCE_DELETE] = notes if reason == 'deceased_person' end def soft_forcedelete_dates(years) diff --git a/app/jobs/death_registry_check_job.rb b/app/jobs/death_registry_check_job.rb index fffafe6de2..d36ba371fa 100644 --- a/app/jobs/death_registry_check_job.rb +++ b/app/jobs/death_registry_check_job.rb @@ -6,6 +6,11 @@ # registry file. Every contact linked to a domain is checked once a year; a run # only takes the contacts whose last check is older than CHECK_INTERVAL. # +# When six months have passed since a registrant's death, a fast track force +# delete starts on the registrant's domains. The person is looked up again +# before that, and every day during the force delete; a person who is no longer +# in the file has the death date cleared and the force delete cancelled. +# # The job also rebuilds the death registry file when it is older than # FILE_REBUILD_AGE, so production needs a single cron line. # @@ -17,6 +22,7 @@ class DeathRegistryCheckJob < ApplicationJob FILE_REBUILD_AGE = 7.days BATCH_SIZE = 1000 REPORT_HEADERS = %w[contact_code ident death_date roles domains registrars six_months_passed].freeze + FORCE_DELETE_REASON = 'deceased_person' queue_as :default @@ -29,15 +35,24 @@ def perform(dry_run: self.class.dry_run?) @problems = [] @findings = [] @checked = 0 + @force_deletes = 0 + @cancelled = 0 rebuild_file_if_old lookup = DeathRegistry::Lookup.new if lookup.available? - ::PaperTrail.request(whodunnit: "cron - #{self.class.name}") { check_contacts(lookup) } + ::PaperTrail.request(whodunnit: "cron - #{self.class.name}") do + check_contacts(lookup) + unless dry_run + start_force_deletes(lookup) + cancel_force_deletes_of_living(lookup) + end + end report_dry_run if dry_run Rails.logger.info("#{self.class.name}: checked #{@checked} contacts, found #{@findings.size} " \ - "deceased#{' (dry run)' if dry_run}") + "deceased, started #{@force_deletes} and cancelled #{@cancelled} force deletes" \ + "#{' (dry run)' if dry_run}") else @problems << "Death registry file #{lookup.path} is missing, stale or malformed. " \ 'Contacts were not checked.' @@ -96,6 +111,58 @@ def handle_deceased(contact, death_date, checked_at) notify_registrars(contact, registrant_domains) unless force_delete_due?(death_date) end + # Registrants whose death is at least FORCE_DELETE_DELAY old and who have a + # domain without a force delete. Domains that already have a force delete for + # another reason are left alone. + def start_force_deletes(lookup) + # Same date arithmetic as force_delete_due?: 31.08 + 6 months is 28.02 + Contact.where("(contacts.death_date + INTERVAL '6 months')::date <= ?", Time.zone.today) + .where('EXISTS (SELECT 1 FROM domains WHERE domains.registrant_id = contacts.id)') + .find_each do |contact| + domains = contact.registrant_domains.reject(&:force_delete_scheduled?) + next if domains.empty? + + death_date = lookup.death_date(contact.ident) + next clear_death_date(contact) unless death_date + + if death_date != contact.death_date + contact.death_date = death_date + contact.save!(validate: false) + next unless force_delete_due?(death_date) + end + + domains.each { |domain| schedule_force_delete(domain, contact) } + end + end + + def schedule_force_delete(domain, contact) + result = domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: FORCE_DELETE_REASON, + notes: "Deceased registrant: #{contact.ident}, " \ + "death date #{contact.death_date.iso8601}") + return Rails.logger.warn("#{self.class.name}: #{domain.name}: #{result.errors.full_messages.join(', ')}") \ + unless result.valid? + + @force_deletes += 1 + end + + def cancel_force_deletes_of_living(lookup) + Domain.where("force_delete_data->'template_name' = ?", FORCE_DELETE_REASON) + .includes(:registrant).find_each do |domain| + next if lookup.deceased?(domain.registrant.ident) + + domain.cancel_force_delete + clear_death_date(domain.registrant) if domain.registrant.death_date + @cancelled += 1 + end + end + + def clear_death_date(contact) + Rails.logger.info("#{self.class.name}: contact #{contact.code} is no longer in the death registry") + contact.death_date = nil + contact.death_registry_checked_at = Time.zone.now + contact.save!(validate: false) + end + def force_delete_due?(death_date) death_date + FORCE_DELETE_DELAY <= Time.zone.today end diff --git a/app/jobs/force_delete_daily_admin_notifier_job.rb b/app/jobs/force_delete_daily_admin_notifier_job.rb index 0fd6ca8981..334a377e61 100644 --- a/app/jobs/force_delete_daily_admin_notifier_job.rb +++ b/app/jobs/force_delete_daily_admin_notifier_job.rb @@ -51,10 +51,12 @@ def generate_summary_for_lifted_force_delete_domains(domains) end def determine_reason(domain) + notes = domain.status_notes[DomainStatus::FORCE_DELETE] + if domain.template_name.present? - domain.template_name - elsif domain.status_notes[DomainStatus::FORCE_DELETE].present? - "Manual force delete: #{domain.status_notes[DomainStatus::FORCE_DELETE]}" + [domain.template_name, notes.presence].compact.join(': ') + elsif notes.present? + "Manual force delete: #{notes}" else 'Unknown reason' end diff --git a/app/mailers/domain_delete_mailer.rb b/app/mailers/domain_delete_mailer.rb index 3e45071948..6b6aa2ca77 100644 --- a/app/mailers/domain_delete_mailer.rb +++ b/app/mailers/domain_delete_mailer.rb @@ -1,4 +1,7 @@ class DomainDeleteMailer < ApplicationMailer + # Force delete templates that share the email of another template + FORCED_TEMPLATE_VIEWS = { 'deceased_person' => 'private_person' }.freeze + def confirmation_request(domain:, registrar:, registrant:) @domain = DomainPresenter.new(domain: domain, view: view_context) @registrar = RegistrarPresenter.new(registrar: registrar, view: view_context) @@ -43,7 +46,7 @@ def forced(domain:, registrar:, registrant:, template_name:) to: domain.force_delete_contact_emails, subject: subject, template_path: 'mailers/domain_delete_mailer/forced', - template_name: template_name) + template_name: FORCED_TEMPLATE_VIEWS.fetch(template_name, template_name)) end private diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index 6a7949fef0..dcb113f752 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -32,7 +32,7 @@ def hold_status? def notification_template(explicit: nil) reason = explicit&.downcase - return reason if %w[invalid_email invalid_phone invalid_company].include?(reason) + return reason if %w[invalid_email invalid_phone invalid_company deceased_person].include?(reason) if contact_emails_verification_failed.present? 'invalid_email' diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index f5a1c8465e..deeb634fec 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -19,7 +19,7 @@ def remove_force_delete_for_valid_contact end def cancel_force_delete_if_domain_attributes_are_valid?(domain) - return if domain.template_name == 'invalid_company' + return if %w[invalid_company deceased_person].include?(domain.template_name) domain.cancel_force_delete if contact_emails_valid?(domain) && !is_domain_has_invalid_org_contact?(domain) end diff --git a/app/views/admin/domains/partials/_general.html.erb b/app/views/admin/domains/partials/_general.html.erb index e24e337dfe..ae42242294 100644 --- a/app/views/admin/domains/partials/_general.html.erb +++ b/app/views/admin/domains/partials/_general.html.erb @@ -31,6 +31,9 @@
<%= Domain.human_attribute_name :delete_date %>
<%= l @domain.delete_date %>
+
<%= Domain.human_attribute_name :force_delete_start %>
+
<%= l @domain.force_delete_start %>
+
<%= Domain.human_attribute_name :force_delete_date %>
<%= l @domain.force_delete_date %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 79661232b2..4d89e26680 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -695,6 +695,7 @@ en: 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}. 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}' + force_delete_deceased_person: 'Force delete set on domain %{domain_name} because, according to the Estonian Population Register, the registrant (ident %{ident}) has died. Force Delete Type: Fast Track. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}.' death_registry_registrant_deceased: 'According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession.' number: diff --git a/config/locales/mailers/domain_delete.en.yml b/config/locales/mailers/domain_delete.en.yml index 6b2efead15..6150a7c04e 100644 --- a/config/locales/mailers/domain_delete.en.yml +++ b/config/locales/mailers/domain_delete.en.yml @@ -19,5 +19,4 @@ en: forced: subject: >- Domeen %{domain_name} on kustutusmenetluses - / Domain %{domain_name} is in deletion process - / Домен %{domain_name} в процессе удаления \ No newline at end of file + / Domain %{domain_name} is in deletion process \ No newline at end of file diff --git a/test/integration/admin_area/domains/force_delete_controller_test.rb b/test/integration/admin_area/domains/force_delete_controller_test.rb index 037e72bfd6..dcbdae000f 100644 --- a/test/integration/admin_area/domains/force_delete_controller_test.rb +++ b/test/integration/admin_area/domains/force_delete_controller_test.rb @@ -1,210 +1,234 @@ -require 'test_helper' - -class AdminAreaDomainsForceDeleteControllerTest < ActionDispatch::IntegrationTest - include Devise::Test::IntegrationHelpers - include ActionMailer::TestHelper - - setup do - @admin = users(:admin) - @domain = domains(:shop) - sign_in @admin - ActionMailer::Base.deliveries.clear - end - - def test_create_schedules_force_delete_successfully - refute @domain.force_delete_scheduled? - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: true - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_redirected_to edit_admin_domain_url(@domain) - assert_equal 'Force delete procedure has been scheduled', flash[:notice] - end - - def test_create_schedules_soft_force_delete - refute @domain.force_delete_scheduled? - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: true, - notify_by_email: false - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_redirected_to edit_admin_domain_url(@domain) - assert_equal 'Force delete procedure has been scheduled', flash[:notice] - end - - def test_create_with_fast_track_type - refute @domain.force_delete_scheduled? - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: true - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_equal 'fast_track', @domain.force_delete_data['force_delete_type'] - end - - def test_create_with_soft_type - refute @domain.force_delete_scheduled? - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: true, - notify_by_email: false - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_equal 'soft', @domain.force_delete_data['force_delete_type'] - end - - def test_create_handles_boolean_parameters_correctly - post admin_domain_force_delete_path(@domain), params: { - soft_delete: 'true', - notify_by_email: 'false' - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_equal 'soft', @domain.force_delete_data['force_delete_type'] - end - - def test_create_handles_nil_parameters - post admin_domain_force_delete_path(@domain), params: { - soft_delete: nil, - notify_by_email: nil - } - - @domain.reload - assert @domain.force_delete_scheduled? - assert_equal 'fast_track', @domain.force_delete_data['force_delete_type'] - end - - def test_create_handles_validation_errors - Domain.stub_any_instance(:schedule_force_delete, - OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Some validation error'] }))) do - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: true - } - - assert_redirected_to edit_admin_domain_url(@domain) - assert_equal 'Some validation error', flash[:notice] - end - end - - - def test_destroy_cancels_force_delete_successfully - @domain.schedule_force_delete(type: :fast_track) - assert @domain.force_delete_scheduled? - - delete admin_domain_force_delete_path(@domain) - - @domain.reload - refute @domain.force_delete_scheduled? - assert_redirected_to edit_admin_domain_url(@domain) - assert_equal 'Force delete procedure has been cancelled', flash[:notice] - end - - - def test_destroy_works_when_no_force_delete_scheduled - refute @domain.force_delete_scheduled? - - delete admin_domain_force_delete_path(@domain) - - @domain.reload - refute @domain.force_delete_scheduled? - assert_redirected_to edit_admin_domain_url(@domain) - assert_equal 'Force delete procedure has been cancelled', flash[:notice] - end - - def test_create_uses_correct_domain_from_params - other_domain = domains(:airport) - refute other_domain.force_delete_scheduled? - - post admin_domain_force_delete_path(other_domain), params: { - soft_delete: false, - notify_by_email: true - } - - other_domain.reload - assert other_domain.force_delete_scheduled? - refute @domain.force_delete_scheduled? - end - - def test_destroy_uses_correct_domain_from_params - other_domain = domains(:airport) - other_domain.schedule_force_delete(type: :fast_track) - assert other_domain.force_delete_scheduled? - - delete admin_domain_force_delete_path(other_domain) - - other_domain.reload - refute other_domain.force_delete_scheduled? - end - - def test_create_with_transaction_rollback - Domain.stub_any_instance(:schedule_force_delete, - OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Transaction error'] }))) do - - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: true - } - - @domain.reload - refute @domain.force_delete_scheduled? - end - end - - def test_create_with_email_notification_enabled - assert_emails 1 do - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: true - } - end - - @domain.reload - assert @domain.force_delete_scheduled? - end - - def test_create_with_email_notification_disabled - assert_no_emails do - post admin_domain_force_delete_path(@domain), params: { - soft_delete: false, - notify_by_email: false - } - end - - @domain.reload - assert @domain.force_delete_scheduled? - end - - def test_create_with_soft_delete_and_email_notification - assert_no_emails do - post admin_domain_force_delete_path(@domain), params: { - soft_delete: true, - notify_by_email: true - } - end - - @domain.reload - assert @domain.force_delete_scheduled? - assert_equal 'soft', @domain.force_delete_data['force_delete_type'] - end - - private - - def admin_domain_force_delete_path(domain) - "/admin/domains/#{domain.id}/force_delete" - end -end +require 'test_helper' + +class AdminAreaDomainsForceDeleteControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + include ActionMailer::TestHelper + + setup do + @admin = users(:admin) + @domain = domains(:shop) + sign_in @admin + ActionMailer::Base.deliveries.clear + end + + def test_create_schedules_force_delete_successfully + refute @domain.force_delete_scheduled? + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: true + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Force delete procedure has been scheduled', flash[:notice] + end + + def test_create_schedules_soft_force_delete + refute @domain.force_delete_scheduled? + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: true, + notify_by_email: false + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Force delete procedure has been scheduled', flash[:notice] + end + + def test_create_with_fast_track_type + refute @domain.force_delete_scheduled? + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: true + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'fast_track', @domain.force_delete_data['force_delete_type'] + end + + def test_create_with_soft_type + refute @domain.force_delete_scheduled? + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: true, + notify_by_email: false + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'soft', @domain.force_delete_data['force_delete_type'] + end + + def test_create_handles_boolean_parameters_correctly + post admin_domain_force_delete_path(@domain), params: { + soft_delete: 'true', + notify_by_email: 'false' + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'soft', @domain.force_delete_data['force_delete_type'] + end + + def test_create_handles_nil_parameters + post admin_domain_force_delete_path(@domain), params: { + soft_delete: nil, + notify_by_email: nil + } + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'fast_track', @domain.force_delete_data['force_delete_type'] + end + + def test_create_handles_validation_errors + Domain.stub_any_instance(:schedule_force_delete, + OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Some validation error'] }))) do + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: true + } + + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Some validation error', flash[:notice] + end + end + + + def test_destroy_cancels_force_delete_successfully + @domain.schedule_force_delete(type: :fast_track) + assert @domain.force_delete_scheduled? + + delete admin_domain_force_delete_path(@domain) + + @domain.reload + refute @domain.force_delete_scheduled? + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Force delete procedure has been cancelled', flash[:notice] + end + + + def test_destroy_works_when_no_force_delete_scheduled + refute @domain.force_delete_scheduled? + + delete admin_domain_force_delete_path(@domain) + + @domain.reload + refute @domain.force_delete_scheduled? + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Force delete procedure has been cancelled', flash[:notice] + end + + def test_create_uses_correct_domain_from_params + other_domain = domains(:airport) + refute other_domain.force_delete_scheduled? + + post admin_domain_force_delete_path(other_domain), params: { + soft_delete: false, + notify_by_email: true + } + + other_domain.reload + assert other_domain.force_delete_scheduled? + refute @domain.force_delete_scheduled? + end + + def test_destroy_uses_correct_domain_from_params + other_domain = domains(:airport) + other_domain.schedule_force_delete(type: :fast_track) + assert other_domain.force_delete_scheduled? + + delete admin_domain_force_delete_path(other_domain) + + other_domain.reload + refute other_domain.force_delete_scheduled? + end + + def test_create_with_transaction_rollback + Domain.stub_any_instance(:schedule_force_delete, + OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Transaction error'] }))) do + + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: true + } + + @domain.reload + refute @domain.force_delete_scheduled? + end + end + + def test_create_with_email_notification_enabled + assert_emails 1 do + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: true + } + end + + @domain.reload + assert @domain.force_delete_scheduled? + end + + def test_create_with_email_notification_disabled + assert_no_emails do + post admin_domain_force_delete_path(@domain), params: { + soft_delete: false, + notify_by_email: false + } + end + + @domain.reload + assert @domain.force_delete_scheduled? + end + + def test_create_with_soft_delete_and_email_notification + assert_no_emails do + post admin_domain_force_delete_path(@domain), params: { + soft_delete: true, + notify_by_email: true + } + end + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'soft', @domain.force_delete_data['force_delete_type'] + end + + private + + def admin_domain_force_delete_path(domain) + "/admin/domains/#{domain.id}/force_delete" + end + + def test_cancelling_deceased_registrant_force_delete_clears_death_date + registrant = @domain.registrant + registrant.update_columns(death_date: Date.new(2026, 1, 1), death_registry_checked_at: 1.year.ago) + @domain.schedule_force_delete(type: :fast_track, reason: 'deceased_person', notify_by_email: true, + notes: 'Deceased registrant') + + delete admin_domain_force_delete_path(@domain) + + assert_not @domain.reload.force_delete_scheduled? + registrant.reload + assert_nil registrant.death_date + assert_in_delta Time.zone.now, registrant.death_registry_checked_at, 1.minute + end + + def test_cancelling_other_force_delete_keeps_death_date + registrant = @domain.registrant + registrant.update_columns(death_date: Date.new(2026, 1, 1)) + @domain.schedule_force_delete(type: :fast_track, reason: 'invalid_company', notify_by_email: true) + + delete admin_domain_force_delete_path(@domain) + + assert_equal Date.new(2026, 1, 1), registrant.reload.death_date + end +end diff --git a/test/jobs/death_registry_check_job_test.rb b/test/jobs/death_registry_check_job_test.rb index c7fe227305..7ddb133d9d 100644 --- a/test/jobs/death_registry_check_job_test.rb +++ b/test/jobs/death_registry_check_job_test.rb @@ -94,16 +94,16 @@ def test_saves_only_death_date_for_deceased_admin_contact assert_empty Notification.where('text LIKE ?', "%#{ADMIN_IDENT}%") end - def test_no_poll_when_six_months_have_passed + def test_starts_force_delete_instead_of_death_poll_when_six_months_have_passed ENV['death_registry_dry_run'] = 'false' old_death = Time.zone.today - 6.months write_death_file(REGISTRANT_IDENT => old_death) - assert_no_difference 'Notification.count' do - DeathRegistryCheckJob.perform_now - end + DeathRegistryCheckJob.perform_now assert_equal old_death, @registrant.reload.death_date + assert_not Notification.where('text LIKE ?', 'According to the Estonian Population Register%').exists? + assert domains(:shop).reload.force_delete_scheduled? end def test_saves_check_time_for_alive_contact_without_version @@ -141,15 +141,15 @@ def test_rechecks_contact_only_after_a_year assert_equal @recent_death, @registrant.reload.death_date end - def test_skips_contacts_with_death_date + def test_does_not_check_contacts_with_death_date_again ENV['death_registry_dry_run'] = 'false' - @registrant.update_columns(death_date: Date.new(2020, 1, 1)) + @registrant.update_columns(death_date: @recent_death) assert_no_difference 'Notification.count' do DeathRegistryCheckJob.perform_now end - assert_equal Date.new(2020, 1, 1), @registrant.reload.death_date + assert_nil @registrant.reload.death_registry_checked_at end def test_rebuilds_file_older_than_seven_days @@ -194,8 +194,128 @@ def test_skips_run_and_emails_admin_when_file_is_unavailable assert_includes mail.body.to_s, 'Contacts were not checked' end + def test_starts_fast_track_force_delete_six_months_after_death + ENV['death_registry_dry_run'] = 'false' + death_date = Time.zone.today - 6.months + mark_deceased(@registrant, death_date) + + DeathRegistryCheckJob.perform_now + + @registrant.registrant_domains.each do |domain| + assert domain.force_delete_scheduled?, domain.name + assert_equal 'fast_track', domain.force_delete_type + assert_equal 'deceased_person', domain.template_name + assert_equal Time.zone.tomorrow, domain.force_delete_start.to_date + assert_includes domain.status_notes[DomainStatus::FORCE_DELETE], REGISTRANT_IDENT + end + + polls = Notification.where('text LIKE ?', 'Force delete set on domain % because%').pluck(:text) + assert_equal @registrant.registrant_domains.count, polls.size + assert polls.all? { |text| text.include?("(ident #{REGISTRANT_IDENT}) has died") } + + mail = ActionMailer::Base.deliveries.find { |m| m.subject.include?('shop.test') } + assert_includes mail.text_part.body.to_s, 'on surnud ja sellest on möödunud vähemalt 6 kuud' + end + + def test_force_delete_starts_on_last_day_of_shorter_month + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Date.new(2026, 8, 31)) + + travel_to Time.zone.parse('2027-02-27 05:00') do + File.utime(Time.now, Time.now, @path) + DeathRegistryCheckJob.perform_now + assert_not domains(:shop).reload.force_delete_scheduled? + end + + travel_to Time.zone.parse('2027-02-28 05:00') do + File.utime(Time.now, Time.now, @path) + DeathRegistryCheckJob.perform_now + assert_equal Date.new(2027, 3, 1), domains(:shop).reload.force_delete_start.to_date + end + end + + def test_no_force_delete_before_six_months + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Time.zone.today - 6.months + 1.day) + + DeathRegistryCheckJob.perform_now + + assert_not domains(:shop).reload.force_delete_scheduled? + end + + def test_clears_death_date_instead_of_force_delete_when_person_left_registry + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Time.zone.today - 7.months) + write_death_file(ADMIN_IDENT => @recent_death) + + assert_no_difference 'Notification.count' do + DeathRegistryCheckJob.perform_now + end + + assert_nil @registrant.reload.death_date + assert_not_nil @registrant.death_registry_checked_at + assert_not domains(:shop).reload.force_delete_scheduled? + end + + def test_leaves_existing_force_delete_alone + ENV['death_registry_dry_run'] = 'false' + domain = domains(:shop) + domain.schedule_force_delete(type: :soft, notify_by_email: true, reason: 'invalid_email', + email: 'john@inbox.test') + mark_deceased(@registrant, Time.zone.today - 7.months) + + DeathRegistryCheckJob.perform_now + + assert_equal 'invalid_email', domain.reload.template_name + assert_equal 'soft', domain.force_delete_type + assert_equal 'deceased_person', domains(:airport).reload.template_name + end + + def test_cancels_force_delete_when_person_leaves_registry + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Time.zone.today - 7.months) + DeathRegistryCheckJob.perform_now + assert domains(:shop).reload.force_delete_scheduled? + + write_death_file(ADMIN_IDENT => @recent_death) + DeathRegistryCheckJob.perform_now + + domain = domains(:shop).reload + assert_not domain.force_delete_scheduled? + assert_nil domain.template_name + assert_nil @registrant.reload.death_date + assert Notification.exists?(text: 'Force delete is cancelled on domain shop.test') + end + + def test_keeps_force_delete_while_person_is_in_registry + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Time.zone.today - 7.months) + DeathRegistryCheckJob.perform_now + + assert_no_difference 'Notification.count' do + DeathRegistryCheckJob.perform_now + end + + assert domains(:shop).reload.force_delete_scheduled? + end + + def test_valid_contact_email_does_not_cancel_deceased_registrant_force_delete + ENV['death_registry_dry_run'] = 'false' + mark_deceased(@registrant, Time.zone.today - 7.months) + DeathRegistryCheckJob.perform_now + + @registrant.reload.remove_force_delete_for_valid_contact + + assert domains(:shop).reload.force_delete_scheduled? + end + private + def mark_deceased(contact, death_date) + contact.update_columns(death_date: death_date, death_registry_checked_at: Time.zone.now) + write_death_file(contact.ident => death_date) + end + def make_estonian_person(contact, ident) contact.update_columns(ident: ident, ident_type: 'priv', ident_country_code: 'EE', death_date: nil, death_registry_checked_at: nil) diff --git a/test/mailers/domain_delete_mailer_test.rb b/test/mailers/domain_delete_mailer_test.rb index 8bd2e0e921..0149b3619c 100644 --- a/test/mailers/domain_delete_mailer_test.rb +++ b/test/mailers/domain_delete_mailer_test.rb @@ -70,8 +70,7 @@ def test_delivers_domain_force_delete_email assert_equal ['legal@registry.test'], email.from assert @domain.force_delete_contact_emails.sort == email.to.sort assert_equal 'Domeen shop.test on kustutusmenetluses' \ - ' / Domain shop.test is in deletion process' \ - ' / Домен shop.test в процессе удаления', email.subject + ' / Domain shop.test is in deletion process', email.subject end def test_forced_invalid_email @@ -87,7 +86,6 @@ def test_forced_invalid_email assert_equal ['legal@registry.test'], email.from assert @domain.force_delete_contact_emails.sort == email.to.sort assert_equal 'Domeen shop.test on kustutusmenetluses' \ - ' / Domain shop.test is in deletion process' \ - ' / Домен shop.test в процессе удаления', email.subject + ' / Domain shop.test is in deletion process', email.subject end end diff --git a/test/models/domain/force_delete_test.rb b/test/models/domain/force_delete_test.rb index 3806368111..18e5350c02 100644 --- a/test/models/domain/force_delete_test.rb +++ b/test/models/domain/force_delete_test.rb @@ -53,6 +53,20 @@ def test_schedules_force_delete_fast_track assert_equal Date.parse('2010-07-06'), @domain.force_delete_start.to_date end + def test_fast_track_email_uses_template_of_reason + @domain.registrant.update_columns(ident_type: 'org') + + # Without the reason, a failed contact email would select the invalid_email letter + @domain.stub(:contact_emails_verification_failed, ['bad@inbox.test']) do + @domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: 'invalid_company') + end + + assert_equal 'invalid_company', @domain.reload.template_name + body = ActionMailer::Base.deliveries.last.text_part.body.to_s + assert_includes body, 'äriregistrist kustutatud' + assert_not_includes body, 'kontaktandmed on puudulikud' + end + def test_schedules_force_delete_soft_year_ahead @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled? From fd4c600e9150919187900356113162de960f04aa Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 20 Oct 2026 13:40:14 +0300 Subject: [PATCH 05/11] Handle deceased admin and tech contacts A deceased tech contact, or an admin contact the domain can do without, is removed from the domain and the registrar gets a poll message. When the last required admin contact of an organisation's or a minor's domain has died, a soft force delete starts with reason deceased_admin_contact, blocking renewal and transfer until a new admin contact is added. CheckForceDeleteLift lifts it once the domain has enough living admin contacts. The person is looked up in the death registry again first; one who is no longer there has the death date cleared. A valid contact email no longer cancels the soft force delete, and an admin cancelling it clears the deceased admin contacts' death date. --- .../admin/domains/force_delete_controller.rb | 17 +-- .../domains/force_delete/notify_registrar.rb | 11 ++ .../domains/force_delete/set_status.rb | 2 +- app/jobs/check_force_delete_lift.rb | 14 +++ app/jobs/death_registry_check_job.rb | 18 ++- app/models/concerns/domain/force_delete.rb | 3 +- app/models/concerns/email_verifable.rb | 2 +- app/models/contact.rb | 8 ++ app/models/domain.rb | 4 + .../deceased_domain_contacts.rb | 84 +++++++++++++ .../forced/deceased_admin_contact.html.erb | 29 +++++ .../forced/deceased_admin_contact.text.erb | 29 +++++ config/locales/en.yml | 3 + .../domains/force_delete_controller_test.rb | 13 ++ test/jobs/check_force_delete_lift_test.rb | 30 +++++ test/jobs/death_registry_check_job_test.rb | 11 +- test/mailers/domain_delete_mailer_test.rb | 20 ++++ .../deceased_domain_contacts_test.rb | 111 ++++++++++++++++++ 18 files changed, 389 insertions(+), 20 deletions(-) create mode 100644 app/services/death_registry/deceased_domain_contacts.rb create mode 100644 app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb create mode 100644 app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb create mode 100644 test/services/death_registry/deceased_domain_contacts_test.rb diff --git a/app/controllers/admin/domains/force_delete_controller.rb b/app/controllers/admin/domains/force_delete_controller.rb index f630068456..bfa5a39f0e 100644 --- a/app/controllers/admin/domains/force_delete_controller.rb +++ b/app/controllers/admin/domains/force_delete_controller.rb @@ -17,20 +17,21 @@ def create def destroy authorize! :manage, domain - deceased_registrant = domain.registrant if domain.template_name == 'deceased_person' + deceased_contacts = deceased_contacts_of_force_delete domain.cancel_force_delete - clear_death_date(deceased_registrant) if deceased_registrant + # Otherwise the death registry check would start it again the next day + deceased_contacts.each(&:clear_death_date!) redirect_to edit_admin_domain_url(domain), notice: t('.cancelled') end private - # Without this the death registry check would start the force delete - # again the next day. The contact is checked again in a year. - def clear_death_date(contact) - contact.death_date = nil - contact.death_registry_checked_at = Time.zone.now - contact.save!(validate: false) + def deceased_contacts_of_force_delete + case domain.template_name + when 'deceased_person' then [domain.registrant] + when 'deceased_admin_contact' then domain.admin_contacts.select(&:death_date) + else [] + end end def domain diff --git a/app/interactions/domains/force_delete/notify_registrar.rb b/app/interactions/domains/force_delete/notify_registrar.rb index 01be415ba7..f921515698 100644 --- a/app/interactions/domains/force_delete/notify_registrar.rb +++ b/app/interactions/domains/force_delete/notify_registrar.rb @@ -3,6 +3,7 @@ module ForceDelete class NotifyRegistrar < Base def execute return notify_deceased_person if reason == 'deceased_person' + return notify_deceased_admin_contact if reason == 'deceased_admin_contact' email.present? ? notify_with_email : notify_without_email end @@ -30,6 +31,16 @@ def notify_deceased_person ) end + def notify_deceased_admin_contact + domain.registrar.notifications.create!( + text: I18n.t('force_delete_deceased_admin_contact', + domain_name: domain.name, + notes: notes, + force_delete_start_date: domain.force_delete_start&.strftime('%d.%m.%Y') || '-', + valid_to: domain.valid_to.strftime('%d.%m.%Y')) + ) + end + def notify_without_email template = if reason == 'invalid_company' I18n.t('invalid_ident', diff --git a/app/interactions/domains/force_delete/set_status.rb b/app/interactions/domains/force_delete/set_status.rb index fc43b8e69b..ed2eb88705 100644 --- a/app/interactions/domains/force_delete/set_status.rb +++ b/app/interactions/domains/force_delete/set_status.rb @@ -29,7 +29,7 @@ def force_delete_soft def set_status_notes domain.status_notes[DomainStatus::FORCE_DELETE] = "Company no: #{domain.registrant.ident} #{"+ #{notes}" if notes.present?}" if reason == 'invalid_company' domain.status_notes[DomainStatus::FORCE_DELETE] = email if reason == 'invalid_email' - domain.status_notes[DomainStatus::FORCE_DELETE] = notes if reason == 'deceased_person' + domain.status_notes[DomainStatus::FORCE_DELETE] = notes if %w[deceased_person deceased_admin_contact].include?(reason) end def soft_forcedelete_dates(years) diff --git a/app/jobs/check_force_delete_lift.rb b/app/jobs/check_force_delete_lift.rb index 1357807d4e..0c21fa8124 100644 --- a/app/jobs/check_force_delete_lift.rb +++ b/app/jobs/check_force_delete_lift.rb @@ -13,10 +13,24 @@ def perform end sync_force_delete_status_notes + lift_deceased_admin_contact_force_deletes end private + # Started by DeathRegistry::DeceasedDomainContacts when the last required + # admin contact of a domain died. The deceased contact itself is removed by + # DeathRegistryCheckJob once it is no longer required. + def lift_deceased_admin_contact_force_deletes + Domain.where("force_delete_data->'template_name' = ?", 'deceased_admin_contact') + .includes(:admin_contacts, :registrant).find_each do |domain| + living_admin_contacts = domain.admin_contacts.count { |contact| contact.death_date.nil? } + next if living_admin_contacts < domain.required_admin_contacts_count + + domain.cancel_force_delete + end + end + def find_domains_to_lift_force_delete Domain.where("'#{DomainStatus::FORCE_DELETE}' = ANY (statuses)").includes(:registrant, :contacts) .select { |d| d.registrant.need_to_lift_force_delete? && d.contacts.all?(&:need_to_lift_force_delete?) } diff --git a/app/jobs/death_registry_check_job.rb b/app/jobs/death_registry_check_job.rb index d36ba371fa..146d7f291e 100644 --- a/app/jobs/death_registry_check_job.rb +++ b/app/jobs/death_registry_check_job.rb @@ -11,6 +11,9 @@ # before that, and every day during the force delete; a person who is no longer # in the file has the death date cleared and the force delete cancelled. # +# Deceased admin and tech contacts are handled by +# DeathRegistry::DeceasedDomainContacts. +# # The job also rebuilds the death registry file when it is older than # FILE_REBUILD_AGE, so production needs a single cron line. # @@ -37,6 +40,7 @@ def perform(dry_run: self.class.dry_run?) @checked = 0 @force_deletes = 0 @cancelled = 0 + @contacts_removed = 0 rebuild_file_if_old lookup = DeathRegistry::Lookup.new @@ -47,11 +51,13 @@ def perform(dry_run: self.class.dry_run?) unless dry_run start_force_deletes(lookup) cancel_force_deletes_of_living(lookup) + handle_deceased_domain_contacts(lookup) end end report_dry_run if dry_run Rails.logger.info("#{self.class.name}: checked #{@checked} contacts, found #{@findings.size} " \ - "deceased, started #{@force_deletes} and cancelled #{@cancelled} force deletes" \ + "deceased, started #{@force_deletes} and cancelled #{@cancelled} force deletes, " \ + "removed #{@contacts_removed} admin and tech contacts" \ "#{' (dry run)' if dry_run}") else @problems << "Death registry file #{lookup.path} is missing, stale or malformed. " \ @@ -156,11 +162,15 @@ def cancel_force_deletes_of_living(lookup) end end + def handle_deceased_domain_contacts(lookup) + result = DeathRegistry::DeceasedDomainContacts.new(lookup: lookup).call + @contacts_removed += result.removed + @force_deletes += result.force_deletes + end + def clear_death_date(contact) Rails.logger.info("#{self.class.name}: contact #{contact.code} is no longer in the death registry") - contact.death_date = nil - contact.death_registry_checked_at = Time.zone.now - contact.save!(validate: false) + contact.clear_death_date! end def force_delete_due?(death_date) diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index dcb113f752..d2c4eb9952 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -32,7 +32,8 @@ def hold_status? def notification_template(explicit: nil) reason = explicit&.downcase - return reason if %w[invalid_email invalid_phone invalid_company deceased_person].include?(reason) + return reason if %w[invalid_email invalid_phone invalid_company deceased_person + deceased_admin_contact].include?(reason) if contact_emails_verification_failed.present? 'invalid_email' diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index deeb634fec..f926076cad 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -19,7 +19,7 @@ def remove_force_delete_for_valid_contact end def cancel_force_delete_if_domain_attributes_are_valid?(domain) - return if %w[invalid_company deceased_person].include?(domain.template_name) + return if %w[invalid_company deceased_person deceased_admin_contact].include?(domain.template_name) domain.cancel_force_delete if contact_emails_valid?(domain) && !is_domain_has_invalid_org_contact?(domain) end diff --git a/app/models/contact.rb b/app/models/contact.rb index 8fdc1c9696..d3fdc1975a 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -581,6 +581,14 @@ def linked? registrant_domains.any? || domain_contacts.any? end + # For a person who is no longer in the death registry, or whose death force + # delete an admin cancelled. The next death registry check is in a year. + def clear_death_date! + self.death_date = nil + self.death_registry_checked_at = Time.zone.now + save!(validate: false) + end + def domain_names_with_roles domain_names = {} diff --git a/app/models/domain.rb b/app/models/domain.rb index b801f74e22..94800b130f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -893,6 +893,10 @@ def require_admin_contacts? registrant.underage? && Setting.admin_contacts_required_for_minors end + def required_admin_contacts_count + require_admin_contacts? ? Setting.admin_contacts_min_count : 0 + end + def require_tech_contacts? registrant.present? && registrant.org? end diff --git a/app/services/death_registry/deceased_domain_contacts.rb b/app/services/death_registry/deceased_domain_contacts.rb new file mode 100644 index 0000000000..0c74813192 --- /dev/null +++ b/app/services/death_registry/deceased_domain_contacts.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +module DeathRegistry + # Handles admin and tech contacts with a death date. Death gives grounds for + # a force delete only against the registrant, so: + # - a contact the domain can do without (a tech contact, or an admin contact + # when the domain still meets the admin contact requirement) is removed; + # - the last required admin contact (an organisation's or a minor's domain) + # puts the domain into a soft force delete until it is replaced. + # CheckForceDeleteLift lifts it once the domain has enough living admin + # contacts. + # + # The person is looked up again first; one who is no longer in the death + # registry has the death date cleared. + class DeceasedDomainContacts + FORCE_DELETE_REASON = 'deceased_admin_contact' + + attr_reader :removed, :force_deletes + + def initialize(lookup:) + @lookup = lookup + @removed = 0 + @force_deletes = 0 + end + + def call + Contact.where.not(death_date: nil) + .where('EXISTS (SELECT 1 FROM domain_contacts WHERE domain_contacts.contact_id = contacts.id)') + .find_each do |contact| + next contact.clear_death_date! unless @lookup.deceased?(contact.ident) + + contact.domain_contacts.includes(domain: :registrar).find_each do |domain_contact| + handle(domain_contact, contact) + end + end + + self + end + + private + + def handle(domain_contact, contact) + domain = domain_contact.domain + + if domain_contact.is_a?(TechDomainContact) || admin_contact_removable?(domain) + remove(domain_contact, contact) + elsif !domain.force_delete_scheduled? + schedule_force_delete(domain, contact) + end + end + + def admin_contact_removable?(domain) + domain.admin_domain_contacts.count > domain.required_admin_contacts_count + end + + # Saving the domain afterwards records the change in the domain history + # and updates WHOIS. + def remove(domain_contact, contact) + domain = domain_contact.domain + role = domain_contact.is_a?(TechDomainContact) ? 'tech' : 'admin' + + Domain.transaction do + domain_contact.destroy! + domain.reload.save!(validate: false) + end + + domain.registrar.notifications.create!( + text: I18n.t("death_registry_#{role}_contact_removed", domain_name: domain.name, + contact_code: contact.code), + attached_obj_id: domain.id, + attached_obj_type: domain.class.name + ) + @removed += 1 + end + + def schedule_force_delete(domain, contact) + result = domain.schedule_force_delete(type: :soft, notify_by_email: true, reason: FORCE_DELETE_REASON, + notes: "Admin contact #{contact.code} has died") + return @force_deletes += 1 if result.valid? + + Rails.logger.warn("#{self.class.name}: #{domain.name}: #{result.errors.full_messages.join(', ')}") + end + end +end diff --git a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb new file mode 100644 index 0000000000..5e029be150 --- /dev/null +++ b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb @@ -0,0 +1,29 @@ +

Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt

+ +

Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni <%= @domain.name %> halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt.

+ +

Et see olukord on vastuolus .ee domeenireeglitega, algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.

+ +

Uue halduskontakti lisamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole.

+ +

Kui uut halduskontakti ei ole <%= @delete_period_length %> päeva jooksul lisatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe siit.

+ +

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

+<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> +<%= render 'mailers/shared/signatures/signature.et.html' %> + +
+ +

Dear registrant/administrative contact of .ee domain,

+ +

According to the Estonian Population Register, the administrative contact of the domain <%= @domain.name %> has died. The domain must have a valid administrative contact.

+ +

Since this is a violation of Estonian domain regulations, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.

+ +

To add a new administrative contact, please contact your registrar <%= @registrar.name %>.

+ +

If no new administrative contact is added within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results here.

+ +

Should you have additional questions, please contact your registrar:

+<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> +<%= render 'mailers/shared/signatures/signature.en.html' %> diff --git a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb new file mode 100644 index 0000000000..a518bed71f --- /dev/null +++ b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb @@ -0,0 +1,29 @@ +Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt + +Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni <%= @domain.name %> halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt. + +Et see olukord on vastuolus .ee domeenireeglitega (https://www.internet.ee/domains/ee-domain-regulation), algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav. + +Uue halduskontakti lisamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. + +Kui uut halduskontakti ei ole <%= @delete_period_length %> päeva jooksul lisatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe https://www.internet.ee/domeenid/domeenide-oksjonikeskkonna-kasutajatingimused#3-oksjonikeskkonna-enampakkumisel-osalemise-tingimused. + +Lisaküsimuste korral võtke palun ühendust oma registripidajaga: +<%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> +<%= render 'mailers/shared/signatures/signature.et.text' %> + +-------------------------------------- + +Dear registrant/administrative contact of .ee domain, + +According to the Estonian Population Register, the administrative contact of the domain <%= @domain.name %> has died. The domain must have a valid administrative contact. + +Since this is a violation of Estonian domain regulations (https://www.internet.ee/domains/ee-domain-regulation), <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process. + +To add a new administrative contact, please contact your registrar <%= @registrar.name %>. + +If no new administrative contact is added within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment https://auction.internet.ee. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results at https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment. + +Should you have additional questions, please contact your registrar: +<%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> +<%= render 'mailers/shared/signatures/signature.en.text' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 4d89e26680..e29ebeac4c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -696,6 +696,9 @@ en: 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}. 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}' force_delete_deceased_person: 'Force delete set on domain %{domain_name} because, according to the Estonian Population Register, the registrant (ident %{ident}) has died. Force Delete Type: Fast Track. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}.' + force_delete_deceased_admin_contact: 'Force delete set on domain %{domain_name}. %{notes} according to the Estonian Population Register. Add a new admin contact; until then the domain cannot be renewed or transferred to another registrar. Force Delete Type: Soft. Force Delete Start Date: %{force_delete_start_date}. Expire date: %{valid_to}.' + death_registry_admin_contact_removed: 'Admin contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died.' + death_registry_tech_contact_removed: 'Tech contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. Add a new tech contact if needed.' death_registry_registrant_deceased: 'According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession.' number: diff --git a/test/integration/admin_area/domains/force_delete_controller_test.rb b/test/integration/admin_area/domains/force_delete_controller_test.rb index dcbdae000f..dea558a466 100644 --- a/test/integration/admin_area/domains/force_delete_controller_test.rb +++ b/test/integration/admin_area/domains/force_delete_controller_test.rb @@ -231,4 +231,17 @@ def test_cancelling_other_force_delete_keeps_death_date assert_equal Date.new(2026, 1, 1), registrant.reload.death_date end + + def test_cancelling_deceased_admin_contact_force_delete_clears_death_date + domain = domains(:library) + admin_contact = domain.admin_contacts.first + admin_contact.update_columns(death_date: Date.new(2026, 1, 1)) + domain.schedule_force_delete(type: :soft, reason: 'deceased_admin_contact', notify_by_email: true, + notes: 'Admin contact has died') + + delete admin_domain_force_delete_path(domain) + + assert_not domain.reload.force_delete_scheduled? + assert_nil admin_contact.reload.death_date + end end diff --git a/test/jobs/check_force_delete_lift_test.rb b/test/jobs/check_force_delete_lift_test.rb index 8ee1bfd47b..3b28b0385d 100644 --- a/test/jobs/check_force_delete_lift_test.rb +++ b/test/jobs/check_force_delete_lift_test.rb @@ -159,4 +159,34 @@ def test_does_not_update_notes_for_invalid_company_template assert_equal original_notes, @domain.status_notes[DomainStatus::FORCE_DELETE], 'Status notes for invalid_company should not be modified' end + + def test_lifts_deceased_admin_contact_force_delete_when_living_admin_contact_is_added + domain = deceased_admin_contact_force_delete + domain.admin_domain_contacts.create!(contact: contacts(:william)) + + CheckForceDeleteLift.perform_now + + domain.reload + assert_not domain.force_delete_scheduled? + assert_nil domain.template_name + end + + def test_keeps_deceased_admin_contact_force_delete_while_only_deceased_admin_contact_remains + domain = deceased_admin_contact_force_delete + + CheckForceDeleteLift.perform_now + + assert domain.reload.force_delete_scheduled? + end + + private + + def deceased_admin_contact_force_delete + domain = domains(:library) + domain.admin_contacts.each { |contact| contact.update_columns(death_date: Date.new(2026, 1, 1)) } + domain.schedule_force_delete(type: :soft, notify_by_email: true, reason: 'deceased_admin_contact', + notes: 'Admin contact acme-ltd-001 has died') + assert_equal 'deceased_admin_contact', domain.reload.template_name + domain + end end diff --git a/test/jobs/death_registry_check_job_test.rb b/test/jobs/death_registry_check_job_test.rb index 7ddb133d9d..721423bd8a 100644 --- a/test/jobs/death_registry_check_job_test.rb +++ b/test/jobs/death_registry_check_job_test.rb @@ -85,12 +85,13 @@ def test_saves_death_date_and_notifies_registrar_of_each_registrant_domain assert texts.all? { |text| text.include?((@recent_death + 6.months + 1.day).to_s) } end - def test_saves_only_death_date_for_deceased_admin_contact + def test_removes_deceased_admin_contact_found_in_same_run ENV['death_registry_dry_run'] = 'false' DeathRegistryCheckJob.perform_now assert_equal @recent_death, @admin.reload.death_date + assert_not_includes domains(:shop).reload.admin_contacts, @admin assert_empty Notification.where('text LIKE ?', "%#{ADMIN_IDENT}%") end @@ -145,9 +146,9 @@ def test_does_not_check_contacts_with_death_date_again ENV['death_registry_dry_run'] = 'false' @registrant.update_columns(death_date: @recent_death) - assert_no_difference 'Notification.count' do - DeathRegistryCheckJob.perform_now - end + DeathRegistryCheckJob.perform_now + + assert_not Notification.where('text LIKE ?', "%(ident #{REGISTRANT_IDENT}) died%").exists? assert_nil @registrant.reload.death_registry_checked_at end @@ -246,7 +247,7 @@ def test_no_force_delete_before_six_months def test_clears_death_date_instead_of_force_delete_when_person_left_registry ENV['death_registry_dry_run'] = 'false' mark_deceased(@registrant, Time.zone.today - 7.months) - write_death_file(ADMIN_IDENT => @recent_death) + write_death_file(UNLINKED_IDENT => @recent_death) assert_no_difference 'Notification.count' do DeathRegistryCheckJob.perform_now diff --git a/test/mailers/domain_delete_mailer_test.rb b/test/mailers/domain_delete_mailer_test.rb index 0149b3619c..0fdcb58680 100644 --- a/test/mailers/domain_delete_mailer_test.rb +++ b/test/mailers/domain_delete_mailer_test.rb @@ -88,4 +88,24 @@ def test_forced_invalid_email assert_equal 'Domeen shop.test on kustutusmenetluses' \ ' / Domain shop.test is in deletion process', email.subject end + + def test_forced_deceased_admin_contact + email = DomainDeleteMailer.forced(domain: @domain, + registrar: @domain.registrar, + registrant: @domain.registrant, + template_name: 'deceased_admin_contact').deliver_now + + assert_emails 1 + assert_includes email.text_part.body.to_s, 'halduskontakt on surnud' + assert_includes email.html_part.body.to_s, 'administrative contact of the domain shop.test has died' + end + + def test_forced_deceased_person_uses_private_person_letter + email = DomainDeleteMailer.forced(domain: @domain, + registrar: @domain.registrar, + registrant: @domain.registrant, + template_name: 'deceased_person').deliver_now + + assert_includes email.text_part.body.to_s, 'on surnud ja sellest on möödunud vähemalt 6 kuud' + end end diff --git a/test/services/death_registry/deceased_domain_contacts_test.rb b/test/services/death_registry/deceased_domain_contacts_test.rb new file mode 100644 index 0000000000..2262bb9bca --- /dev/null +++ b/test/services/death_registry/deceased_domain_contacts_test.rb @@ -0,0 +1,111 @@ +require 'test_helper' + +class DeathRegistryDeceasedDomainContactsTest < ActiveSupport::TestCase + Lookup = Struct.new(:deceased_idents) do + def deceased?(ident) + deceased_idents.include?(ident) + end + end + + DECEASED_IDENT = '49001010000'.freeze + + setup do + @lookup = Lookup.new([DECEASED_IDENT]) + @deceased = contacts(:jane) + @deceased.update_columns(ident: DECEASED_IDENT, ident_type: 'priv', ident_country_code: 'EE', + death_date: Date.new(2026, 1, 1)) + end + + def test_removes_deceased_tech_contact + domain = domains(:shop) + domain_contacts(:shop_jane).update_columns(type: 'TechDomainContact') + + assert_difference -> { domain.versions.count } do + call + end + + assert_not_includes domain.reload.tech_contacts, @deceased + assert Notification.exists?(text: 'Tech contact jane-001 was removed from domain shop.test because, ' \ + 'according to the Estonian Population Register, the person has died. ' \ + 'Add a new tech contact if needed.') + end + + def test_removes_deceased_admin_contact_of_private_registrant + domain = domains(:shop) + assert domain.registrant.priv? + + call + + assert_not_includes domain.reload.admin_contacts, @deceased + assert_not domain.force_delete_scheduled? + assert Notification.exists?(text: 'Admin contact jane-001 was removed from domain shop.test because, ' \ + 'according to the Estonian Population Register, the person has died.') + end + + def test_starts_soft_force_delete_when_last_admin_contact_of_organisation_dies + domain = domains(:library) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + + call + + domain.reload + assert_includes domain.admin_contacts, @deceased + assert domain.force_delete_scheduled? + assert_equal 'soft', domain.force_delete_type + assert_equal 'deceased_admin_contact', domain.template_name + assert_equal 'Admin contact jane-001 has died', domain.status_notes[DomainStatus::FORCE_DELETE] + assert_includes domain.statuses, DomainStatus::SERVER_RENEW_PROHIBITED + assert Notification.where('text LIKE ?', 'Force delete set on domain library.test. Admin contact jane-001 ' \ + 'has died according to the Estonian Population Register.%').exists? + end + + def test_removes_deceased_admin_contact_when_organisation_has_another + domain = domains(:library) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + domain.admin_domain_contacts.create!(contact: contacts(:william)) + + call + + domain.reload + assert_equal [contacts(:william)], domain.admin_contacts + assert_not domain.force_delete_scheduled? + end + + def test_starts_soft_force_delete_when_only_admin_contact_of_minor_dies + domain = domains(:shop) + domain.registrant.update_columns(ident: "5#{(Time.zone.today - 10.years).strftime('%y%m%d')}0000", + ident_type: 'priv', ident_country_code: 'EE') + assert domain.registrant.underage? + + call + + assert_equal 'deceased_admin_contact', domain.reload.template_name + assert_includes domain.admin_contacts, @deceased + end + + def test_leaves_domain_with_existing_force_delete_alone + domain = domains(:library) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + domain.schedule_force_delete(type: :fast_track, reason: 'invalid_company') + + call + + assert_equal 'fast_track', domain.reload.force_delete_type + assert_includes domain.admin_contacts, @deceased + end + + def test_clears_death_date_of_person_no_longer_in_registry + @lookup = Lookup.new([]) + + call + + assert_nil @deceased.reload.death_date + assert_includes domains(:shop).reload.admin_contacts, @deceased + end + + private + + def call + DeathRegistry::DeceasedDomainContacts.new(lookup: @lookup).call + end +end From f17c8403526cdfddc633a600a4aec8dfb9ae8869 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Wed, 21 Oct 2026 14:16:40 +0300 Subject: [PATCH 06/11] Let death force delete take priority over a later force delete A deceased registrant's fast track force delete replaces an existing force delete when it releases the domain earlier. The replaced force delete is saved and restored when the death force delete stops (the person is no longer in the death registry, or an admin cancels it), if its reason still exists. Its dates are not moved; when its outzone date has passed, the domain goes out of the zone at once. The registrar gets a poll message. --- .../admin/domains/force_delete_controller.rb | 7 +- app/jobs/death_registry_check_job.rb | 22 ++- .../death_registry/force_delete_priority.rb | 130 ++++++++++++++++ config/locales/en.yml | 1 + .../domains/force_delete_controller_test.rb | 18 +++ test/jobs/death_registry_check_job_test.rb | 23 ++- .../force_delete_priority_test.rb | 140 ++++++++++++++++++ 7 files changed, 331 insertions(+), 10 deletions(-) create mode 100644 app/services/death_registry/force_delete_priority.rb create mode 100644 test/services/death_registry/force_delete_priority_test.rb diff --git a/app/controllers/admin/domains/force_delete_controller.rb b/app/controllers/admin/domains/force_delete_controller.rb index bfa5a39f0e..8927d36ed3 100644 --- a/app/controllers/admin/domains/force_delete_controller.rb +++ b/app/controllers/admin/domains/force_delete_controller.rb @@ -18,7 +18,12 @@ def create def destroy authorize! :manage, domain deceased_contacts = deceased_contacts_of_force_delete - domain.cancel_force_delete + if domain.template_name == 'deceased_person' + # Restores the force delete it replaced, if any + DeathRegistry::ForceDeletePriority.new(domain).stop + else + domain.cancel_force_delete + end # Otherwise the death registry check would start it again the next day deceased_contacts.each(&:clear_death_date!) redirect_to edit_admin_domain_url(domain), notice: t('.cancelled') diff --git a/app/jobs/death_registry_check_job.rb b/app/jobs/death_registry_check_job.rb index 146d7f291e..6f05f834eb 100644 --- a/app/jobs/death_registry_check_job.rb +++ b/app/jobs/death_registry_check_job.rb @@ -9,7 +9,8 @@ # When six months have passed since a registrant's death, a fast track force # delete starts on the registrant's domains. The person is looked up again # before that, and every day during the force delete; a person who is no longer -# in the file has the death date cleared and the force delete cancelled. +# in the file has the death date cleared and the force delete stopped (an +# earlier force delete it replaced is restored). # # Deceased admin and tech contacts are handled by # DeathRegistry::DeceasedDomainContacts. @@ -118,14 +119,17 @@ def handle_deceased(contact, death_date, checked_at) end # Registrants whose death is at least FORCE_DELETE_DELAY old and who have a - # domain without a force delete. Domains that already have a force delete for - # another reason are left alone. + # domain without a death force delete. A force delete for another reason is + # replaced only when the fast track releases the domain earlier + # (DeathRegistry::ForceDeletePriority). def start_force_deletes(lookup) # Same date arithmetic as force_delete_due?: 31.08 + 6 months is 28.02 Contact.where("(contacts.death_date + INTERVAL '6 months')::date <= ?", Time.zone.today) .where('EXISTS (SELECT 1 FROM domains WHERE domains.registrant_id = contacts.id)') .find_each do |contact| - domains = contact.registrant_domains.reject(&:force_delete_scheduled?) + domains = contact.registrant_domains.select do |domain| + domain.template_name != FORCE_DELETE_REASON && DeathRegistry::ForceDeletePriority.new(domain).takes_priority? + end next if domains.empty? death_date = lookup.death_date(contact.ident) @@ -142,9 +146,11 @@ def start_force_deletes(lookup) end def schedule_force_delete(domain, contact) - result = domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: FORCE_DELETE_REASON, - notes: "Deceased registrant: #{contact.ident}, " \ - "death date #{contact.death_date.iso8601}") + result = DeathRegistry::ForceDeletePriority.new(domain).replace_current_force_delete do + domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: FORCE_DELETE_REASON, + notes: "Deceased registrant: #{contact.ident}, " \ + "death date #{contact.death_date.iso8601}") + end return Rails.logger.warn("#{self.class.name}: #{domain.name}: #{result.errors.full_messages.join(', ')}") \ unless result.valid? @@ -156,7 +162,7 @@ def cancel_force_deletes_of_living(lookup) .includes(:registrant).find_each do |domain| next if lookup.deceased?(domain.registrant.ident) - domain.cancel_force_delete + DeathRegistry::ForceDeletePriority.new(domain).stop clear_death_date(domain.registrant) if domain.registrant.death_date @cancelled += 1 end diff --git a/app/services/death_registry/force_delete_priority.rb b/app/services/death_registry/force_delete_priority.rb new file mode 100644 index 0000000000..dde37913a2 --- /dev/null +++ b/app/services/death_registry/force_delete_priority.rb @@ -0,0 +1,130 @@ +# frozen_string_literal: true + +module DeathRegistry + # A deceased registrant's fast track force delete takes priority over a force + # delete the domain already has, when it releases the domain earlier. The + # earlier force delete is saved in force_delete_data and restored when the + # death force delete stops (the person turns out to be alive, or an admin + # cancels it), if its reason still exists. Its dates are not moved: when its + # outzone date has passed, the domain goes out of the zone at once. + # + # A registrant change cancels both force deletes (Domain#cancel_force_delete + # clears force_delete_data). + class ForceDeletePriority + PREVIOUS_KEY = 'previous_force_delete' + PREVIOUS_ATTRIBUTES = %w[force_delete_start force_delete_date].freeze + + def self.fast_track_purge_date + Time.zone.today + Setting.expire_warning_period.days + Setting.redemption_grace_period.days + 1.day + end + + def initialize(domain) + @domain = domain + end + + def takes_priority? + fast_track_purge_date_earlier = self.class.fast_track_purge_date < domain.purge_date.to_date + !domain.force_delete_scheduled? || fast_track_purge_date_earlier + end + + # Yields to start the new force delete. Without the fixes afterwards, the + # new force delete would record the current force delete statuses as the + # statuses to restore when it is cancelled. + def replace_current_force_delete + return yield unless domain.force_delete_scheduled? + + previous = previous_state + domain.force_delete_data = {} + result = yield + return result unless result.valid? + + domain.reload + domain.force_delete_domain_statuses_history = previous['statuses_history'] + domain.force_delete_data = domain.force_delete_data.merge(PREVIOUS_KEY => previous.to_json) + domain.save!(validate: false) + result + end + + # Returns :restored or :cancelled. + def stop + previous = saved_previous_state + return cancel unless previous && previous_reason_exists?(previous) + + restore(previous) + :restored + end + + private + + attr_reader :domain + + def previous_state + { + 'force_delete_data' => domain.force_delete_data.to_h.except(PREVIOUS_KEY), + 'force_delete_start' => domain.force_delete_start&.iso8601, + 'force_delete_date' => domain.force_delete_date&.iso8601, + 'status_note' => domain.status_notes[DomainStatus::FORCE_DELETE], + 'statuses_history' => domain.force_delete_domain_statuses_history, + } + end + + def saved_previous_state + json = domain.force_delete_data&.dig(PREVIOUS_KEY) + JSON.parse(json) if json.present? + end + + def previous_reason_exists?(previous) + case previous.dig('force_delete_data', 'template_name') + when 'invalid_email' + domain.contacts.any?(&:email_verification_failed?) || domain.registrant.email_verification_failed? + when 'deceased_admin_contact' + domain.admin_contacts.count { |contact| contact.death_date.nil? } < domain.required_admin_contacts_count + else + # Manual force deletes cannot be checked; an admin cancels them if needed + true + end + end + + def cancel + domain.cancel_force_delete + :cancelled + end + + def restore(previous) + domain.force_delete_data = previous['force_delete_data'] + domain.force_delete_start = previous['force_delete_start'] + domain.force_delete_date = previous['force_delete_date'] + domain.status_notes[DomainStatus::FORCE_DELETE] = previous['status_note'] + domain.force_delete_domain_statuses_history = previous['statuses_history'] + outzone_passed? ? hold : domain.statuses.delete(DomainStatus::CLIENT_HOLD) + domain.save!(validate: false) + + notify_registrar + end + + def outzone_passed? + return false if domain.force_delete_start.blank? + + outzone = domain.force_delete_start + Setting.expire_warning_period.days + outzone <= Time.zone.now && outzone <= domain.valid_to + end + + def hold + domain.statuses |= [DomainStatus::CLIENT_HOLD] + domain.force_delete_data['client_hold_mandatory'] = Domains::ClientHold::ProcessClientHold::CLIENT_HOLD_SET_NOTE + end + + def notify_registrar + domain.registrar.notifications.create!( + text: I18n.t('death_registry_force_delete_restored', + domain_name: domain.name, + reason: domain.template_name.presence || domain.status_notes[DomainStatus::FORCE_DELETE], + force_delete_start_date: domain.force_delete_start&.strftime('%d.%m.%Y') || '-', + outzone_date: domain.outzone_date, + purge_date: domain.purge_date), + attached_obj_id: domain.id, + attached_obj_type: domain.class.name + ) + end + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index e29ebeac4c..82f2b14da7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -699,6 +699,7 @@ en: force_delete_deceased_admin_contact: 'Force delete set on domain %{domain_name}. %{notes} according to the Estonian Population Register. Add a new admin contact; until then the domain cannot be renewed or transferred to another registrar. Force Delete Type: Soft. Force Delete Start Date: %{force_delete_start_date}. Expire date: %{valid_to}.' death_registry_admin_contact_removed: 'Admin contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died.' death_registry_tech_contact_removed: 'Tech contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. Add a new tech contact if needed.' + death_registry_force_delete_restored: 'Force delete because of the registrant''s death was stopped on domain %{domain_name}. The earlier force delete continues: %{reason}. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}.' death_registry_registrant_deceased: 'According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession.' number: diff --git a/test/integration/admin_area/domains/force_delete_controller_test.rb b/test/integration/admin_area/domains/force_delete_controller_test.rb index dea558a466..a0b9285a11 100644 --- a/test/integration/admin_area/domains/force_delete_controller_test.rb +++ b/test/integration/admin_area/domains/force_delete_controller_test.rb @@ -244,4 +244,22 @@ def test_cancelling_deceased_admin_contact_force_delete_clears_death_date assert_not domain.reload.force_delete_scheduled? assert_nil admin_contact.reload.death_date end + + def test_cancelling_deceased_registrant_force_delete_restores_replaced_force_delete + @domain.update_columns(valid_to: Time.zone.today + 3.years) + @domain.reload.schedule_force_delete(type: :soft) + @domain.reload.update_columns(status_notes: { DomainStatus::FORCE_DELETE => 'Manual' }) + @domain.reload + DeathRegistry::ForceDeletePriority.new(@domain).replace_current_force_delete do + @domain.schedule_force_delete(type: :fast_track, reason: 'deceased_person', notify_by_email: true, + notes: 'Deceased registrant') + end + + delete admin_domain_force_delete_path(@domain) + + @domain.reload + assert @domain.force_delete_scheduled? + assert_equal 'soft', @domain.force_delete_type + assert_equal 'Manual', @domain.status_notes[DomainStatus::FORCE_DELETE] + end end diff --git a/test/jobs/death_registry_check_job_test.rb b/test/jobs/death_registry_check_job_test.rb index 721423bd8a..00878850dd 100644 --- a/test/jobs/death_registry_check_job_test.rb +++ b/test/jobs/death_registry_check_job_test.rb @@ -258,7 +258,7 @@ def test_clears_death_date_instead_of_force_delete_when_person_left_registry assert_not domains(:shop).reload.force_delete_scheduled? end - def test_leaves_existing_force_delete_alone + def test_keeps_existing_force_delete_with_earlier_purge_date ENV['death_registry_dry_run'] = 'false' domain = domains(:shop) domain.schedule_force_delete(type: :soft, notify_by_email: true, reason: 'invalid_email', @@ -272,6 +272,27 @@ def test_leaves_existing_force_delete_alone assert_equal 'deceased_person', domains(:airport).reload.template_name end + def test_replaces_later_force_delete_and_restores_it_when_person_leaves_registry + ENV['death_registry_dry_run'] = 'false' + domain = domains(:shop) + # The soft force delete starts at the registration anniversary in two months + domain.update_columns(valid_to: Time.zone.today + 3.years + 2.months) + domain.reload.schedule_force_delete(type: :soft) + mark_deceased(@registrant, Time.zone.today - 7.months) + + DeathRegistryCheckJob.perform_now + assert_equal 'deceased_person', domain.reload.template_name + + write_death_file(UNLINKED_IDENT => @recent_death) + DeathRegistryCheckJob.perform_now + + domain.reload + assert domain.force_delete_scheduled? + assert_equal 'soft', domain.force_delete_type + assert_nil domain.template_name + assert Notification.where('text LIKE ?', "%death was stopped on domain shop.test%").exists? + end + def test_cancels_force_delete_when_person_leaves_registry ENV['death_registry_dry_run'] = 'false' mark_deceased(@registrant, Time.zone.today - 7.months) diff --git a/test/services/death_registry/force_delete_priority_test.rb b/test/services/death_registry/force_delete_priority_test.rb new file mode 100644 index 0000000000..859c56dc9c --- /dev/null +++ b/test/services/death_registry/force_delete_priority_test.rb @@ -0,0 +1,140 @@ +require 'test_helper' + +class DeathRegistryForceDeletePriorityTest < ActiveSupport::TestCase + setup do + @domain = domains(:shop) + @domain.update_columns(valid_to: Time.zone.today + 3.years + 1.month, statuses: [DomainStatus::OK]) + @original_statuses = @domain.statuses.dup + ValidationEvent.destroy_all + end + + def test_takes_priority_without_force_delete + assert priority.takes_priority? + end + + def test_takes_priority_over_force_delete_with_later_purge_date + schedule_invalid_email_force_delete + + assert priority.takes_priority? + end + + def test_does_not_take_priority_over_force_delete_with_earlier_purge_date + @domain.reload.schedule_force_delete(type: :fast_track, reason: 'invalid_company') + + assert_not priority.takes_priority? + end + + def test_replaces_force_delete_and_keeps_original_statuses + schedule_invalid_email_force_delete + + schedule_death_force_delete + @domain.reload + + assert_equal 'deceased_person', @domain.template_name + assert_equal 'fast_track', @domain.force_delete_type + assert_equal Time.zone.tomorrow, @domain.force_delete_start.to_date + assert_equal @original_statuses, @domain.force_delete_domain_statuses_history + previous = JSON.parse(@domain.force_delete_data['previous_force_delete']) + assert_equal 'invalid_email', previous['force_delete_data']['template_name'] + end + + def test_restores_replaced_force_delete_when_its_reason_exists + schedule_invalid_email_force_delete + previous_start = @domain.reload.force_delete_start + schedule_death_force_delete + + assert_equal :restored, priority.stop + + @domain.reload + assert_equal 'invalid_email', @domain.template_name + assert_equal 'soft', @domain.force_delete_type + assert_equal previous_start, @domain.force_delete_start + assert_equal 'invalid@inbox.test', @domain.status_notes[DomainStatus::FORCE_DELETE] + assert_equal @original_statuses, @domain.force_delete_domain_statuses_history + assert_nil @domain.force_delete_data['previous_force_delete'] + assert_not_includes @domain.statuses, DomainStatus::CLIENT_HOLD + assert Notification.where('text LIKE ?', "Force delete because of the registrant's death was stopped " \ + 'on domain shop.test. The earlier force delete continues: ' \ + 'invalid_email.%').exists? + end + + def test_cancels_both_force_deletes_when_replaced_reason_is_gone + schedule_invalid_email_force_delete + schedule_death_force_delete + ValidationEvent.destroy_all + + assert_equal :cancelled, priority.stop + + @domain.reload + assert_not @domain.force_delete_scheduled? + assert_equal @original_statuses, @domain.statuses + end + + def test_always_restores_manual_force_delete + @domain.reload.schedule_force_delete(type: :soft) + @domain.reload.update_columns(status_notes: { DomainStatus::FORCE_DELETE => 'Manual' }) + schedule_death_force_delete + + assert_equal :restored, priority.stop + + assert_equal 'Manual', @domain.reload.status_notes[DomainStatus::FORCE_DELETE] + assert_equal 'soft', @domain.force_delete_type + end + + def test_restored_force_delete_past_outzone_date_takes_domain_out_of_zone_at_once + @domain.update_columns(valid_to: Time.zone.today + 1.year + 1.month) + schedule_invalid_email_force_delete + schedule_death_force_delete + + travel_to @domain.reload.valid_to - 1.year + Setting.expire_warning_period.days + 1.day do + priority.stop + end + + assert_includes @domain.reload.statuses, DomainStatus::CLIENT_HOLD + end + + def test_cancels_when_nothing_was_replaced + schedule_death_force_delete + + assert_equal :cancelled, priority.stop + assert_not @domain.reload.force_delete_scheduled? + end + + def test_registrant_change_cancels_both_force_deletes + schedule_invalid_email_force_delete + schedule_death_force_delete + + @domain.reload + @domain.registrant = contacts(:william).becomes(Registrant) + @domain.save!(validate: false) + + @domain.reload + assert_not @domain.force_delete_scheduled? + assert_nil @domain.force_delete_data + end + + private + + def priority + DeathRegistry::ForceDeletePriority.new(@domain.reload) + end + + def schedule_invalid_email_force_delete + contact = @domain.admin_contacts.first + contact.update_columns(email: 'invalid@inbox.test') + ValidationEvent.create!(validation_eventable: contact, success: false, event_type: 'email_validation', + event_data: { 'check_level' => 'regex', 'email' => contact.email }) + @domain.reload.schedule_force_delete(type: :soft, notify_by_email: true, reason: 'invalid_email', + email: contact.email) + assert_equal 'invalid_email', @domain.reload.template_name + end + + def schedule_death_force_delete + domain = @domain.reload + result = DeathRegistry::ForceDeletePriority.new(domain).replace_current_force_delete do + domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: 'deceased_person', + notes: 'Deceased registrant') + end + assert result.valid? + end +end From 8e1ad13a78cda5d610eeb466d7126749cff423cb Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Wed, 21 Oct 2026 14:28:48 +0300 Subject: [PATCH 07/11] Add death registry check documentation --- doc/death_registry.md | 395 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 395 insertions(+) create mode 100644 doc/death_registry.md diff --git a/doc/death_registry.md b/doc/death_registry.md new file mode 100644 index 0000000000..c81a93a740 --- /dev/null +++ b/doc/death_registry.md @@ -0,0 +1,395 @@ +# Death Registry Check + +Status as of 2026-10-21: implemented on branch `feature/death-registry-check`, not released. Everything is off by default. + +## 1. Summary + +The registry (EIS) checks Estonian private-person contacts against the death open data of the Estonian Population Register. Until now, domains of deceased registrants were found and handled by hand (ENTITY_BURIED force delete). This feature does it automatically: + +- **At contact creation:** a new contact whose Estonian personal identity code belongs to a deceased person is refused (EPP and REPP, error 2003 "Ident is invalid"). +- **Once a year per contact:** a daily job checks the contacts whose last check is older than a year, so about 1/365 of the contacts are checked each night. +- **Deceased registrant:** the registrar gets a poll message at once. A fast-track force delete starts at death date + 6 months + 1 day, unless the registrant has been changed by then (for example to an heir with a certificate of succession). +- **Deceased admin or tech contact:** an optional contact is removed from the domain. A required admin contact (organisation or minor registrant) puts the domain into a soft force delete until a new admin contact is added. +- **Notifications:** registrars get a poll message for every action. Registrants and contacts get only the existing force delete emails; no new email to the registrant is sent. + +| Reader | Sections | +| --- | --- | +| Lawyer | 2 Legal basis and data handling, 3 How it works, 4 Timeline, 9 Messages | +| System administrator | 5 Production setup, 6 Go-live, 7 Operation, 8 Settings | +| Text reviewers | 9 Messages and notification texts | + +## 2. Legal basis and data handling + +### Legal basis + +The .ee domain regulation gives EIS the right to start a deletion procedure when the registrant is a natural person who has died. Six months are given for succession; after that the domain enters a deletion procedure, as in the current manual process (the existing `private_person` email). + +Death of an **admin or tech contact** does not give grounds for deleting the domain: those contacts are not domain holders. Therefore: + +- a tech contact (always optional) and an admin contact of a private registrant (optional) are removed from the domain, and the registrar is informed; +- an organisation's or minor's last admin contact cannot be removed, because the domain must have one. The domain gets a **soft** force delete: it stays in the zone, but cannot be renewed or transferred until a new admin contact is added. If it is not renewed, it expires on its normal date. + +Decisions: Helen and Timo, 20.10.2026 and 21.10.2026. + +### Data source + +- Population Register death data on the Estonian open data portal: https://andmed.eesti.ee/datasets/surmaandmed +- Files used (published by SMIT): + - `https://opendata.smit.ee/etl/rahvastik/surmaandmed_1926_kuni_eelmise_aasta_lopuni.csv` (1926 to end of last year) + - `https://opendata.smit.ee/etl/rahvastik/surmaandmed_jooksev_aasta.csv` (current year) +- Licence: CC BY 4.0. The data is used only inside the registry and not redistributed (see open question 1). +- The open data omits roughly the last 7 days of deaths, so the copy is refreshed weekly. + +### What is stored + +| Data | Where | Kept for | +| --- | --- | --- | +| Personal identity code + death date of every deceased person in the open data | Local file (`deaths.txt`) on the registry server | Replaced weekly by a fresh copy; no older copies are kept | +| Death date of a matching contact | `contacts.death_date` | Until the contact is deleted (contact archiving), or cleared when the person is no longer in the open data | +| Time of the last check | `contacts.death_registry_checked_at` | Same as the contact | +| Dry run report (CSV: contact code, ident, death date, roles, domains, registrars) | `reports/` next to the death file, and emailed to the admin address | Until deleted manually | + +No names, addresses or other fields of the source data are stored. Data protection rules do not grant rights to deceased persons, so no legal assessment was deemed necessary for keeping the copy (decided earlier; see section 10 for the licence question). + +### Who sees it + +- The death date and the check time are shown **only in the admin interface** (contact page; contact list filter "Death registry: deceased / not checked"). +- They are **not** shown in WHOIS, EPP `contact:info` or REPP. +- Registrars learn of a death only through poll messages about their own domains (texts in section 9). The poll for a deceased registrant includes the ident and death date. +- The force delete status note on the domain (visible in admin) contains the ident and death date. + +### Corrections in the Population Register + +If a person was wrongly marked as deceased and later disappears from the open data: + +- before the force delete starts: the death date is cleared silently, nothing is sent; +- during the force delete: it is stopped and the registrar gets a poll message (A4, or A5 when an earlier force delete is restored); +- the person is re-checked from a fresh file right before the force delete starts and every day while it runs. + +## 3. How it works + +### 3.1 Check at contact creation + +Applies to EPP and REPP `contact create`, only for `ident_type = priv` and country `EE`, only when `validate_deceased_contacts = true`. + +- Person found in the file: the contact is not created, error 2003 "Ident is invalid" / "Isikukood on kehtetu". +- Person not found: the contact is created and `death_registry_checked_at` is set, so the yearly check skips it for a year. +- File missing, stale or malformed: the contact is created unchecked, a warning is logged, and the daily job checks it the next night. A file problem never blocks registrars. + +Contact **updates** and the use of an existing contact on a new domain are not checked (open question 10). + +### 3.2 Daily job `DeathRegistryCheckJob` + +One run does, in order: + +1. **Refresh the file** if it is older than 7 days (download, validate, atomic replace). On failure the old file is kept and the admin gets an email. +2. **Yearly check:** EE private contacts linked to at least one domain (as registrant, admin or tech), without a death date, whose last check is empty or older than 1 year. Each is looked up; living persons get `death_registry_checked_at = now`, deceased ones get `death_date`. + - For a deceased registrant whose death is less than 6 months ago, the registrar gets poll **A1** for each of the person's domains. +3. **Start fast-track force deletes** for registrants who died at least 6 months ago (see 3.3). +4. **Stop force deletes of persons no longer in the file** (see 3.5). +5. **Handle deceased admin and tech contacts** (see 3.4). + +In **dry run mode** (the default) only step 1 and the lookups run: nothing is saved, no polls or emails go to registrars, and a CSV report is emailed to the admin address. + +Volume: after the first full run, about 1/365 of the linked contacts per night; a lookup is a binary search in the file, so the job is light. + +### 3.3 Deceased registrant + +- At discovery (death < 6 months ago): poll **A1** to the registrar with the expected force delete start date. No email to the registrant. +- At death + 6 months + 1 day: the person is looked up again in the fresh file, then a **fast-track force delete** starts on every domain where the person is registrant: + - reason `deceased_person`, status note "Deceased registrant: , death date "; + - starts the next day; outzone after 15 days; deletion (auction) after another 30 + 1 days (current settings); + - registrar gets poll **A3**; registrant and admin contacts get the existing "deceased person" force delete email (**E1**, template `private_person`). +- If the registrant is changed (e.g. to an heir), every force delete on the domain is cancelled, as for any registrant change. +- If the run on the due day is missed, the next run picks the contact up and the start moves by a day. + +### 3.4 Deceased admin or tech contact + +| Situation | Action | Message | +| --- | --- | --- | +| Tech contact dies | Removed from the domain (domain history and WHOIS updated; the contact object stays) | Poll **B1** | +| Admin contact dies, domain still has enough admin contacts (private registrant, or organisation with another admin) | Removed from the domain | Poll **C1** | +| Last required admin contact of an organisation or minor registrant dies | Soft force delete, reason `deceased_admin_contact`; statuses `serverForceDelete`, `serverRenewProhibited`, `serverTransferProhibited` | Poll **C2**; email **E2** at the force delete start | +| A new admin contact is added afterwards | `CheckForceDeleteLift` cancels the soft force delete | Poll **A4** (standard cancel text) | +| Domain already has a force delete | Left alone | — | + +Soft force delete start: if the domain expires more than a year from now, the start moves to the nearest registration anniversary; if it expires within a year, there is no start date and the domain simply cannot be renewed (open question 2). + +### 3.5 Domain already has a force delete + +The force delete that releases the domain **earlier** wins (Timo, 21.10.2026). + +- Fast-track deletion date = today + 15 + 30 + 1 days. If the existing force delete's deletion date is the same or earlier, it stays and nothing changes. +- Otherwise the existing force delete is **saved** on the domain and the death fast track replaces it. +- When the death force delete stops (the person is no longer in the file, or an admin cancels it): + - the saved force delete is **restored** if its reason still exists: + - invalid email: restored only if a contact's email still fails verification; + - deceased admin contact: restored only if the domain still lacks a living required admin contact; + - manual (admin, ENTITY_BURIED) and invalid phone: always restored; an admin cancels it by hand if needed; + - its dates are **not moved**; if its outzone date has already passed, the domain goes out of the zone (`clientHold`) at once; + - the registrar gets poll **A5**; no email is sent; + - if the reason is gone, or nothing was saved, the force delete is cancelled completely (poll **A4**). +- A registrant change cancels all force deletes, the saved one included. + +### 3.6 Admin actions + +- **Cancel force delete** (admin → domain → Edit → Cancel force delete) on a death force delete: + - restores a saved earlier force delete (3.5), otherwise cancels; + - clears the contact's death date and marks it checked now, so the job does not restart the force delete; the person is checked again in a year. +- Contact list filter **Death registry**: "deceased" or "not checked". +- The domain page shows the force delete start date, deletion date and the status note with the reason. +- The daily admin force delete summary shows the reason and note (for example `deceased_person: Deceased registrant: …`). + +## 4. Timeline example + +Registrant dies on 15.03.2026; the yearly check finds it on 02.05.2026. + +| Date | Event | +| --- | --- | +| 15.03.2026 | Death | +| ~22.03.2026 | Appears in the open data (about a week's delay) | +| 02.05.2026 | Found by the daily job; death date saved; poll A1 to the registrar ("force delete will start on 16.09.2026") | +| 15.09.2026 | 6 months after death; person looked up again | +| 16.09.2026 | Fast-track force delete starts; poll A3; email E1 to registrant and admin contacts | +| 01.10.2026 | Outzone: domain removed from the zone (`clientHold`) | +| 31.10.2026 | Deletion date: domain goes to auction (start day − 1 + 15 + 30 + 1 days) | + +A registrant change at any point before the deletion date cancels the force delete. If the yearly check finds the death only after 6 months have passed, A1 is skipped and the force delete starts the next day. + +## 5. Production setup + +### 5.1 Release + +1. Deploy the release. +2. Run migrations: `bin/rails db:migrate RAILS_ENV=production`. They add `contacts.death_date`, `contacts.death_registry_checked_at` and indexes. Existing data is not changed. + +### 5.2 Configuration (`config/application.yml`) + +```yaml +death_registry_file_path: '/shared/death_registry/deaths.txt' # shared disk, see below +death_registry_source_urls: '' # empty = the two opendata.smit.ee CSVs +death_registry_max_file_age_days: '8' +death_registry_min_records: '100000' +validate_deceased_contacts: 'false' # turned on at go-live +death_registry_dry_run: 'true' # turned off at go-live +admin_notification_email: 'admin@…' # receives problems and dry run reports (existing setting) +``` + +### 5.3 File location + +- The file must be readable by **every** process that creates contacts (EPP and REPP app servers) and by the server that runs the job. Use a shared disk if they are on different machines. +- The job's user must be able to write to the directory: the file is written as `deaths.txt..tmp` and renamed over the old one. The `reports/` subdirectory is created next to it. +- Size: 23 bytes per record (`<11-digit ident>;\n`), sorted by ident. +- The server needs outbound HTTPS to `opendata.smit.ee`. + +### 5.4 Cron + +Production uses a hand-maintained crontab (`config/schedule.rb` is not used there). Add **one** line: + +``` +0 5 * * * cd /path/to/registry && bin/rails r -e production "DeathRegistryCheckJob.perform_now" +``` + +The job rebuilds the file itself when it is older than 7 days; a separate file job is not needed. + +The existing `CheckForceDeleteLift` cron line (already in the production crontab) also lifts the `deceased_admin_contact` soft force delete once a new admin contact is added. It must keep running daily; no change is needed. + +## 6. Go-live + +1. **Build the file** on the production server and check it: + ``` + bin/rails r -e production "DeathRegistryFileBuildJob.perform_now" + ls -l /shared/death_registry/deaths.txt # size divisible by 23, fresh mtime + ``` +2. **Dry run** (`death_registry_dry_run: 'true'`), run once by hand: + ``` + bin/rails r -e production "DeathRegistryCheckJob.perform_now" + ``` + The admin address receives "Death registry dry run report" with a CSV of every deceased contact found, their roles, domains, registrars and whether 6 months have passed. The first run checks all linked contacts, not 1/365. +3. **Review the report** (Timo, Helen): + - check a random sample of 10–20 rows against the Population Register; + - compare with recent manual ENTITY_BURIED cases; + - count rows with `six_months_passed = true`: each of their domains gets a fast-track force delete on the first real run. Decide whether registrars are warned beforehand or the start is spread out (open question 8). +4. **Add the cron line** (5.4). +5. **Turn on the creation check:** `validate_deceased_contacts: 'true'`, restart the app servers. +6. **Turn off dry run:** `death_registry_dry_run: 'false'`. The next night's run saves death dates, sends polls and starts force deletes. + +**Rollback:** set `death_registry_dry_run: 'true'` and `validate_deceased_contacts: 'false'`. Started force deletes stay and are cancelled by hand in admin if needed. + +## 7. Operation + +### 7.1 Monitoring + +- **Log line** after each run (`log/production.log`): + `DeathRegistryCheckJob: checked N contacts, found N deceased, started N and cancelled N force deletes, removed N admin and tech contacts` +- **Problem email** "Death registry check problem - " to `admin_notification_email` when: + - the file rebuild failed (download error, HTTP error, missing columns, fewer than `death_registry_min_records` records); the old file is kept; + - the file is missing, stale (older than `death_registry_max_file_age_days`) or malformed; contacts are not checked that night; + - the dry run report could not be written or sent. +- A stale file never blocks contact creation; it only logs a warning per contact. + +### 7.2 Commands + +``` +# Run the check (respects death_registry_dry_run) +bin/rails r -e production "DeathRegistryCheckJob.perform_now" + +# Force a dry run regardless of the setting +bin/rails r -e production "DeathRegistryCheckJob.perform_now(dry_run: true)" + +# Rebuild the file now +bin/rails r -e production "DeathRegistryFileBuildJob.perform_now" + +# Look up one ident +bin/rails r -e production "p DeathRegistry::Lookup.new.death_date('38001010000')" + +# Contacts with a death date +bin/rails r -e production "p Contact.where.not(death_date: nil).count" + +# Domains in a death force delete +bin/rails r -e production "puts Domain.where(\"force_delete_data->'template_name' = 'deceased_person'\").pluck(:name)" +``` + +### 7.3 Manual actions + +| Case | What to do | +| --- | --- | +| Person is alive (registrant or heir contacts EIS) | Admin → domain → Edit → Cancel force delete. The death date is cleared and the contact is not checked again for a year. | +| Person is alive but the open data is not yet corrected | Same; also ask the Population Register to correct the data, otherwise the person is found again in a year. | +| Restored earlier force delete is not wanted | Cancel force delete once more. | +| Soft force delete for a deceased admin contact should be lifted | Add a living admin contact; `CheckForceDeleteLift` lifts it the next run, or cancel by hand. | + +### 7.4 Troubleshooting + +| Symptom | Cause / fix | +| --- | --- | +| Problem email "file is missing, stale or malformed" | Rebuild failed for 2+ weeks or the path is wrong. Run the rebuild by hand and read the error. | +| "only N records, expected at least 100000" | Source returned partial data. Old file kept; retry later. Check the source URLs. | +| "CSV is missing columns" | SMIT changed the file format. Code change needed in `DeathRegistry::FileBuilder`. | +| Contacts created without check | `validate_deceased_contacts` off, or the file is not readable from the EPP/REPP server. | +| Domain stays in `deceased_admin_contact` after admin contact replaced | Check that the `CheckForceDeleteLift` cron line ran; the domain needs as many living admin contacts as `admin_contacts_min_count`. | + +## 8. Settings + +| Setting | Default | Purpose | +| --- | --- | --- | +| `death_registry_file_path` | `tmp/death_registry/deaths.txt` | Location of the local copy; use a shared disk in production | +| `death_registry_source_urls` | the two opendata.smit.ee CSVs | Comma-separated source URLs | +| `death_registry_max_file_age_days` | 8 | Older file counts as stale; lookups refuse it | +| `death_registry_min_records` | 100000 | A download with fewer records is rejected | +| `validate_deceased_contacts` | false | Refuse deceased persons at contact creation | +| `death_registry_dry_run` | true | Job only reports; saves nothing and sends nothing | +| `admin_notification_email` | existing | Receives problem emails and dry run reports | +| `expire_warning_period` | existing (15) | Days from force delete start to outzone | +| `redemption_grace_period` | existing (30) | Days from outzone to deletion | +| `admin_contacts_min_count` | existing | Required admin contacts for organisation and minor registrants | + +Fixed in code: check interval 1 year, force delete 6 months after death, file rebuild after 7 days. + +## 9. Messages and notification texts for review + +All poll texts are **English drafts** and need review (Helen, Mare). Estonian versions are to be added. Placeholders are in `%{…}`. Dates in polls follow the existing force delete messages. + +### Registrar poll messages + +| Code | When | Text | +| --- | --- | --- | +| **A1** | Registrant found deceased, less than 6 months ago | According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession. | +| **A3** | Fast-track force delete started | Force delete set on domain %{domain_name} because, according to the Estonian Population Register, the registrant (ident %{ident}) has died. Force Delete Type: Fast Track. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | +| **A4** | Force delete cancelled (person alive, admin cancel, admin contact replaced) — existing text | Force delete is cancelled on domain %{domain_name} | +| **A5** | Death force delete stopped, earlier force delete restored | Force delete because of the registrant's death was stopped on domain %{domain_name}. The earlier force delete continues: %{reason}. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | +| **B1** | Deceased tech contact removed | Tech contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. Add a new tech contact if needed. | +| **C1** | Deceased admin contact removed | Admin contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. | +| **C2** | Soft force delete for the last required admin contact | Force delete set on domain %{domain_name}. Admin contact %{contact_code} has died according to the Estonian Population Register. Add a new admin contact; until then the domain cannot be renewed or transferred to another registrar. Force Delete Type: Soft. Force Delete Start Date: %{force_delete_start_date}. Expire date: %{valid_to}. | + +Notes for reviewers: + +- A5 `%{reason}` is a technical reason code (`invalid_email`, `deceased_admin_contact`, …) or the manual status note. Consider mapping it to readable words. +- A4 is the existing generic cancel text and does not say why. + +### EPP / REPP error + +| When | Code | Text (en / et) | +| --- | --- | --- | +| Contact create with a deceased person's ident | 2003 | Ident is invalid / Isikukood on kehtetu | + +The error deliberately does not say that the person is deceased. + +### Emails to registrant and contacts + +Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses / Domain %{domain_name} is in deletion process". The Russian line was removed from the subject. + +**E1 — deceased registrant (existing template `private_person`, unchanged), sent at the fast-track start:** + +> Lugupeetud domeeni %{domain} registreerija/halduskontakt +> +> Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et füüsiline isik isikukoodiga %{ident} on surnud ja sellest on möödunud vähemalt 6 kuud. +> +> Kuna surnud isik ei saa olla domeeni registreerijaks, algas domeeni %{domain} suhtes %{delete_period_length} päevane kustutusmenetlus. Menetluse käigus on domeen %{expire_warning_period} esimest päeva internetis kättesaadav. +> +> Domeeni suhtes õigust omaval isikul on võimalus esitada domeeni %{domain} registripidajale %{registrar} domeeni üleandmise taotlus, millele tuleb lisada pärimisõiguse tõend. Dokumentatsioon tuleb esitada registripidajale %{delete_period_length} päeva jooksul. +> +> Kui üleandmine ei ole %{delete_period_length} päeva jooksul toimunud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. … +> +> --- +> +> Dear registrant/administrative contact of %{domain} domain +> +> Estonian Internet Foundation (EIF) has learned that the natural person with identification code %{ident} has been deceased more than 6 months. +> +> The registrant holding a right to the domain name %{domain} can submit a domain name transfer application to the registrar %{registrar}. The application must be submitted together with succession evidence certifying the acquisition of the domain. The relevant documents should be submitted to the registrar within %{delete_period_length} days. +> +> As a deceased natural person can not be the registrant of a domain, a %{delete_period_length}-day deletion process of %{domain} domain has started. For the first %{expire_warning_period} days the domain will remain available on the Internet during the deletion process. +> +> If the transfer is not made within %{delete_period_length} days, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing template) + +**E2 — deceased admin contact (new template `deceased_admin_contact`, draft), sent at the soft force delete start:** + +> Lugupeetud domeeni %{domain} registreerija/halduskontakt +> +> Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni %{domain} halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt. +> +> Et see olukord on vastuolus .ee domeenireeglitega (https://www.internet.ee/domains/ee-domain-regulation), algatas EIS %{delete_period_length} päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen %{expire_warning_period} esimest päeva internetis kättesaadav. +> +> Uue halduskontakti lisamiseks pöörduge palun oma registripidaja %{registrar} poole. +> +> Kui uut halduskontakti ei ole %{delete_period_length} päeva jooksul lisatud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. … +> +> --- +> +> Dear registrant/administrative contact of .ee domain, +> +> According to the Estonian Population Register, the administrative contact of the domain %{domain} has died. The domain must have a valid administrative contact. +> +> Since this is a violation of Estonian domain regulations (https://www.internet.ee/domains/ee-domain-regulation), %{delete_period_length}-day deletion process has started for the %{domain} domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first %{expire_warning_period} days the domain will remain available on the Internet during the deletion process. +> +> To add a new administrative contact, please contact your registrar %{registrar}. +> +> If no new administrative contact is added within %{delete_period_length} days, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing templates) + +No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a stopped or restored force delete (A4, A5). + +### Admin emails (to `admin_notification_email`) + +| Subject | When | Body | +| --- | --- | --- | +| Death registry check problem - %{date} | File rebuild failed, file unusable, or report failed | List of problems, e.g. "Rebuilding the death registry file failed: …", "Death registry file … is missing, stale or malformed. Contacts were not checked." | +| Death registry dry run report - %{date} | Every run in dry run mode | "Checked contacts: N. Deceased contacts found: N. The attached CSV lists the deceased contacts. Nothing was saved and no poll messages were sent." + CSV attachment | + +### Admin interface + +- Domain status note: "Deceased registrant: , death date " or "Admin contact has died". +- Contact page: "Death date", "Death registry checked". + +## 10. Open questions + +1. **Licence (Helen):** does CC BY 4.0 impose obligations when the data is used only internally? Likely not. +2. **Soft force delete on a domain expiring within a year** (also affects ENTITY_BURIED and invalid email): no start date, so no `clientHold` and no force delete email; the domain just cannot be renewed and expires. Acceptable? +3. **Combined check (Timo):** death + email + phone in one yearly check? Decides whether the field stays `death_registry_checked_at` or becomes a shared `contact_checked_at`. Better decided before go-live. +4. **Manual fast track without a reason:** the email template is then chosen from the domain's data and may be the invalid email letter. Make the reason mandatory on the admin form? +5. **Source URLs:** keep them in code (overridable by setting) with an admin alert on failure? +6. **ENTITY_BURIED manual force delete:** switch it to fast track too, now that deceased registrants are handled automatically? +7. **Dry run review:** who reviews, and at what number of findings do we warn registrars or spread force deletes over days (would need a daily limit setting)? +8. **New year:** if SMIT updates the historical file late in January, last year's deaths may be missing for a few days. Keep the old file when the record count drops sharply? +9. **Existing deceased contact on a new domain or registrant change:** refuse via EPP/REPP? Not checked today. +10. **Text review:** poll texts A1–C2 and email E2 (section 9), plus Estonian versions of the polls. From 14ebabf446b35471b14202897ab071af13d23f61 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Wed, 21 Oct 2026 15:21:52 +0300 Subject: [PATCH 08/11] Require a reason for manual force delete The reason selects the email to the registrant and administrative contacts. Before, the letter was guessed from the domain data: any private registrant got the "registrant has died" letter, and a contact with a failing email turned any letter into the invalid email one. "Other" sends no email. "Invalid email" is refused when no contact email fails, as CheckForceDeleteLift would lift it the next day. Mass action ENTITY_BURIED now uses the private or legal person letter by registrant type instead of the guessed one. --- .../admin/domains/force_delete_controller.rb | 31 +++++++- app/models/concerns/domain/force_delete.rb | 2 +- app/models/mass_action.rb | 11 ++- .../domains/_force_delete_dialog.html.erb | 10 +++ config/locales/admin/domains.en.yml | 8 +++ .../locales/admin/domains/force_delete.en.yml | 2 + doc/death_registry.md | 36 +++++++--- .../domains/force_delete_controller_test.rb | 71 +++++++++++++++++++ test/models/mass_action_test.rb | 28 ++++++++ .../admin_area/domains/force_delete_test.rb | 9 ++- 10 files changed, 192 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/domains/force_delete_controller.rb b/app/controllers/admin/domains/force_delete_controller.rb index 8927d36ed3..88541b6792 100644 --- a/app/controllers/admin/domains/force_delete_controller.rb +++ b/app/controllers/admin/domains/force_delete_controller.rb @@ -1,14 +1,24 @@ module Admin module Domains class ForceDeleteController < BaseController + # The reason picks the email template; without it the template was + # guessed from the domain data, e.g. "the registrant has died" for any + # private registrant. "other" sends no email, as there is no letter for it. + REASONS = %w[private_person legal_person invalid_email invalid_phone other].freeze + def create authorize! :manage, domain + return redirect_to edit_admin_domain_url(domain), alert: t('.reason_missing') unless reason_valid? + # CheckForceDeleteLift would lift it the next day + return redirect_to edit_admin_domain_url(domain), alert: t('.no_invalid_emails') if no_invalid_emails? notice = t('.scheduled') domain.transaction do result = domain.schedule_force_delete(type: force_delete_type, - notify_by_email: notify_by_email?) + notify_by_email: notify_by_email?, + reason: template_reason, + email: invalid_emails) notice = result.errors.messages[:domain].first unless result.valid? end @@ -43,8 +53,25 @@ def domain @domain ||= Domain.find(params[:domain_id]) end + def reason_valid? + REASONS.include?(params[:reason]) + end + + def template_reason + params[:reason] unless params[:reason] == 'other' + end + + def no_invalid_emails? + params[:reason] == 'invalid_email' && invalid_emails.blank? + end + + # Shown in the force delete status note and the registrar's poll message + def invalid_emails + domain.contact_emails_verification_failed.join(', ').presence if params[:reason] == 'invalid_email' + end + def notify_by_email? - ActiveRecord::Type::Boolean.new.cast(params[:notify_by_email]) + template_reason.present? && ActiveRecord::Type::Boolean.new.cast(params[:notify_by_email]) end def force_delete_type diff --git a/app/models/concerns/domain/force_delete.rb b/app/models/concerns/domain/force_delete.rb index d2c4eb9952..2bff27d52f 100644 --- a/app/models/concerns/domain/force_delete.rb +++ b/app/models/concerns/domain/force_delete.rb @@ -33,7 +33,7 @@ def hold_status? def notification_template(explicit: nil) reason = explicit&.downcase return reason if %w[invalid_email invalid_phone invalid_company deceased_person - deceased_admin_contact].include?(reason) + deceased_admin_contact private_person legal_person].include?(reason) if contact_emails_verification_failed.present? 'invalid_email' diff --git a/app/models/mass_action.rb b/app/models/mass_action.rb index c9cc1fe140..50b5fa1409 100644 --- a/app/models/mass_action.rb +++ b/app/models/mass_action.rb @@ -23,7 +23,7 @@ def self.apply_force_deletes(entries) dn = Domain.find_by(name_puny: e['domain_name']) log[:fail] << e['domain_name'] and next unless dn - dn.schedule_force_delete(type: :soft, notify_by_email: true, reason: e['delete_reason']) + dn.schedule_force_delete(type: :soft, notify_by_email: true, reason: force_delete_reason(dn, e['delete_reason'])) log[:ok] << dn.name end @@ -31,6 +31,15 @@ def self.apply_force_deletes(entries) log end + # ENTITY_BURIED has no letter of its own. Without an explicit letter the + # template is guessed from the domain data, and a contact with a failing + # email would get the invalid email letter instead. + def self.force_delete_reason(domain, delete_reason) + return delete_reason unless delete_reason == 'ENTITY_BURIED' + + domain.registrant.org? ? 'legal_person' : 'private_person' + end + def self.force_delete_entries_valid?(entries) entries.each do |e| reasons = %w[ENTITY_BURIED INVALID_EMAIL INVALID_PHONE] diff --git a/app/views/admin/domains/_force_delete_dialog.html.erb b/app/views/admin/domains/_force_delete_dialog.html.erb index 79b2fd2a73..be1f393989 100644 --- a/app/views/admin/domains/_force_delete_dialog.html.erb +++ b/app/views/admin/domains/_force_delete_dialog.html.erb @@ -10,6 +10,16 @@ <%= form_tag admin_domain_force_delete_path(domain), id: 'domain-force-delete-form', class: 'modal-body form-horizontal' do %> +
+
+ <%= label_tag 'reason', t('.reason') %> + <%= select_tag 'reason', + options_for_select(Admin::Domains::ForceDeleteController::REASONS.map { |reason| [t(".reasons.#{reason}"), reason] }), + include_blank: true, required: true, class: 'form-control' %> +

<%= t '.reason_hint' %>

+
+
+
diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index 35e2090116..464531b811 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -35,6 +35,14 @@ en: notify_by_email: Notify registrant and administrative contacts by email use_soft_delete: Use soft delete procedure email_template: Email template + reason: Reason + reason_hint: The reason selects the email to the registrant and administrative contacts. "Other" sends no email. + reasons: + private_person: Registrant (private person) has died + legal_person: Registrant (company) is deleted from the Business Register + invalid_email: Invalid email + invalid_phone: Invalid phone + other: Other (no email) close_btn: Close dialog submit_btn: Force delete domain diff --git a/config/locales/admin/domains/force_delete.en.yml b/config/locales/admin/domains/force_delete.en.yml index 470a3cd3b8..45b838674f 100644 --- a/config/locales/admin/domains/force_delete.en.yml +++ b/config/locales/admin/domains/force_delete.en.yml @@ -4,6 +4,8 @@ en: force_delete: create: scheduled: Force delete procedure has been scheduled + reason_missing: Choose the reason of the force delete + no_invalid_emails: No contact of the domain has an invalid email destroy: cancelled: Force delete procedure has been cancelled diff --git a/doc/death_registry.md b/doc/death_registry.md index c81a93a740..745aab33f5 100644 --- a/doc/death_registry.md +++ b/doc/death_registry.md @@ -133,6 +133,7 @@ The force delete that releases the domain **earlier** wins (Timo, 21.10.2026). ### 3.6 Admin actions +- **Schedule force delete** requires a reason, which selects the email: registrant (private person) has died, registrant (company) deleted from the Business Register, invalid email, invalid phone, or other (no email). Before, the email was guessed from the domain data, and any private registrant got the "registrant has died" letter. - **Cancel force delete** (admin → domain → Edit → Cancel force delete) on a death force delete: - restores a saved earlier force delete (3.5), otherwise cancels; - clears the contact's death date and marks it checked now, so the job does not restart the force delete; the person is checked again in a year. @@ -378,18 +379,31 @@ No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a ### Admin interface -- Domain status note: "Deceased registrant: , death date " or "Admin contact has died". -- Contact page: "Death date", "Death registry checked". +| Where | Text | +| --- | --- | +| Domain page, force delete status note | "Deceased registrant: , death date " or "Admin contact has died" | +| Domain page | "Force delete start" (new row, next to the force delete date) | +| Contact page | "Death date", "Death registry checked" (shown only when set) | +| Contact list filter | "Death registry": "Deceased" / "Not checked" | +| Daily force delete summary email (reason column) | "deceased_person: Deceased registrant: , death date ", "deceased_admin_contact: Admin contact has died" | + +**Schedule force delete dialog** (admin → domain → Edit → Schedule force delete): + +| Element | Text | +| --- | --- | +| Field | Reason (required) | +| Option → email | "Registrant (private person) has died" → E1 `private_person` | +| Option → email | "Registrant (company) is deleted from the Business Register" → `legal_person` | +| Option → email | "Invalid email" → `invalid_email` (failing addresses go into the status note) | +| Option → email | "Invalid phone" → `invalid_phone` | +| Option → email | "Other (no email)" → no email to registrant and contacts | +| Hint | The reason selects the email to the registrant and administrative contacts. "Other" sends no email. | +| Error, no reason chosen | Choose the reason of the force delete | +| Error, "Invalid email" chosen but no contact email fails verification | No contact of the domain has an invalid email | + +The automatic reasons `deceased_person` and `deceased_admin_contact` are not offered manually: the death registry check would stop such a force delete when the person is not in the open data. ## 10. Open questions -1. **Licence (Helen):** does CC BY 4.0 impose obligations when the data is used only internally? Likely not. -2. **Soft force delete on a domain expiring within a year** (also affects ENTITY_BURIED and invalid email): no start date, so no `clientHold` and no force delete email; the domain just cannot be renewed and expires. Acceptable? -3. **Combined check (Timo):** death + email + phone in one yearly check? Decides whether the field stays `death_registry_checked_at` or becomes a shared `contact_checked_at`. Better decided before go-live. -4. **Manual fast track without a reason:** the email template is then chosen from the domain's data and may be the invalid email letter. Make the reason mandatory on the admin form? -5. **Source URLs:** keep them in code (overridable by setting) with an admin alert on failure? -6. **ENTITY_BURIED manual force delete:** switch it to fast track too, now that deceased registrants are handled automatically? -7. **Dry run review:** who reviews, and at what number of findings do we warn registrars or spread force deletes over days (would need a daily limit setting)? -8. **New year:** if SMIT updates the historical file late in January, last year's deaths may be missing for a few days. Keep the old file when the record count drops sharply? +6. **ENTITY_BURIED manual force delete** (admin Mass actions, always soft): switch it to fast track too, now that deceased registrants and deleted companies are handled automatically with fast track? Its letter is already fixed: it now always uses `private_person` or `legal_person` by registrant type, never the invalid email letter. 9. **Existing deceased contact on a new domain or registrant change:** refuse via EPP/REPP? Not checked today. -10. **Text review:** poll texts A1–C2 and email E2 (section 9), plus Estonian versions of the polls. diff --git a/test/integration/admin_area/domains/force_delete_controller_test.rb b/test/integration/admin_area/domains/force_delete_controller_test.rb index a0b9285a11..7271c02691 100644 --- a/test/integration/admin_area/domains/force_delete_controller_test.rb +++ b/test/integration/admin_area/domains/force_delete_controller_test.rb @@ -15,6 +15,7 @@ def test_create_schedules_force_delete_successfully refute @domain.force_delete_scheduled? post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -29,6 +30,7 @@ def test_create_schedules_soft_force_delete refute @domain.force_delete_scheduled? post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: true, notify_by_email: false } @@ -43,6 +45,7 @@ def test_create_with_fast_track_type refute @domain.force_delete_scheduled? post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -56,6 +59,7 @@ def test_create_with_soft_type refute @domain.force_delete_scheduled? post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: true, notify_by_email: false } @@ -67,6 +71,7 @@ def test_create_with_soft_type def test_create_handles_boolean_parameters_correctly post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: 'true', notify_by_email: 'false' } @@ -78,6 +83,7 @@ def test_create_handles_boolean_parameters_correctly def test_create_handles_nil_parameters post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: nil, notify_by_email: nil } @@ -92,6 +98,7 @@ def test_create_handles_validation_errors OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Some validation error'] }))) do post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -131,6 +138,7 @@ def test_create_uses_correct_domain_from_params refute other_domain.force_delete_scheduled? post admin_domain_force_delete_path(other_domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -156,6 +164,7 @@ def test_create_with_transaction_rollback OpenStruct.new(valid?: false, errors: OpenStruct.new(messages: { domain: ['Transaction error'] }))) do post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -168,6 +177,7 @@ def test_create_with_transaction_rollback def test_create_with_email_notification_enabled assert_emails 1 do post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: true } @@ -180,6 +190,7 @@ def test_create_with_email_notification_enabled def test_create_with_email_notification_disabled assert_no_emails do post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: false, notify_by_email: false } @@ -192,6 +203,7 @@ def test_create_with_email_notification_disabled def test_create_with_soft_delete_and_email_notification assert_no_emails do post admin_domain_force_delete_path(@domain), params: { + reason: 'private_person', soft_delete: true, notify_by_email: true } @@ -202,6 +214,65 @@ def test_create_with_soft_delete_and_email_notification assert_equal 'soft', @domain.force_delete_data['force_delete_type'] end + def test_create_requires_reason + post admin_domain_force_delete_path(@domain), params: { soft_delete: false, notify_by_email: true } + + refute @domain.reload.force_delete_scheduled? + assert_redirected_to edit_admin_domain_url(@domain) + assert_equal 'Choose the reason of the force delete', flash[:alert] + end + + def test_create_rejects_unknown_reason + post admin_domain_force_delete_path(@domain), params: { reason: 'deceased_person', soft_delete: false } + + refute @domain.reload.force_delete_scheduled? + end + + def test_create_sends_email_of_chosen_reason + assert_equal 'private_person', @domain.notification_template + + post admin_domain_force_delete_path(@domain), params: { + reason: 'legal_person', soft_delete: false, notify_by_email: true + } + + assert_equal 'legal_person', @domain.reload.template_name + assert_emails 1 + assert_match 'äriregistrist kustutatud', ActionMailer::Base.deliveries.last.text_part.body.to_s + end + + def test_create_with_reason_other_sends_no_email + assert_no_emails do + post admin_domain_force_delete_path(@domain), params: { + reason: 'other', soft_delete: false, notify_by_email: true + } + end + + @domain.reload + assert @domain.force_delete_scheduled? + assert_nil @domain.template_name + end + + def test_create_with_invalid_email_reason_notes_invalid_emails + @domain.stub(:contact_emails_verification_failed, ['invalid@inbox.test']) do + Domain.stub(:find, @domain) do + post admin_domain_force_delete_path(@domain), params: { reason: 'invalid_email', soft_delete: true, notify_by_email: true } + end + end + + @domain.reload + assert_equal 'invalid_email', @domain.template_name + assert_equal 'invalid@inbox.test', @domain.status_notes[DomainStatus::FORCE_DELETE] + end + + def test_create_rejects_invalid_email_reason_without_invalid_emails + assert_empty @domain.contact_emails_verification_failed + + post admin_domain_force_delete_path(@domain), params: { reason: 'invalid_email', soft_delete: true } + + refute @domain.reload.force_delete_scheduled? + assert_equal 'No contact of the domain has an invalid email', flash[:alert] + end + private def admin_domain_force_delete_path(domain) diff --git a/test/models/mass_action_test.rb b/test/models/mass_action_test.rb index 8c730a5e6b..892ca67bd0 100644 --- a/test/models/mass_action_test.rb +++ b/test/models/mass_action_test.rb @@ -17,4 +17,32 @@ def test_mass_action_proccess_with_invalid_data def test_mass_action_invalid_attributes assert_not MassAction.process("force_restart", @csv_valid) end + + def test_entity_buried_uses_letter_of_registrant_type_even_with_invalid_email + domain = domains(:shop) + contact = domain.admin_contacts.first + ValidationEvent.create!(validation_eventable: contact, success: false, event_type: 'email_validation', + event_data: { 'check_level' => 'regex', 'email' => contact.email }) + assert_equal 'invalid_email', domain.reload.notification_template + + MassAction.process('force_delete', @csv_valid) + + assert_equal 'private_person', domain.reload.template_name + end + + def test_entity_buried_uses_legal_person_letter_for_organisation + domain = domains(:shop) + domain.registrant.update_columns(ident_type: 'org') + + MassAction.process('force_delete', @csv_valid) + + assert_equal 'legal_person', domain.reload.template_name + end + + def test_invalid_email_and_phone_keep_their_letters + MassAction.process('force_delete', @csv_valid) + + assert_equal 'invalid_phone', domains(:airport).reload.template_name + assert_equal 'invalid_email', domains(:library).reload.template_name + end end \ No newline at end of file diff --git a/test/system/admin_area/domains/force_delete_test.rb b/test/system/admin_area/domains/force_delete_test.rb index 27d0a8770b..955e8db699 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -13,6 +13,7 @@ def test_schedules_domain_force_delete refute @domain.force_delete_scheduled? visit edit_admin_domain_url(@domain) + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' @domain.reload @@ -25,6 +26,7 @@ def test_force_delete_prohibit_adding_deleteprohibited_status refute @domain.force_delete_scheduled? visit edit_admin_domain_url(@domain) + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' @domain.reload @@ -50,6 +52,7 @@ def test_force_delete_prohibit_adding_deleteprohibited_status def test_notifies_registrar assert_difference '@domain.registrar.notifications.size' do visit edit_admin_domain_url(@domain) + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' end end @@ -58,6 +61,7 @@ def test_notifies_registrant_and_admin_contacts_by_email_if_fast_delete assert_emails 1 do visit edit_admin_domain_url(@domain) find(:css, '#soft_delete').set(false) + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' end end @@ -66,6 +70,7 @@ def test_notifies_registrant_and_admin_contacts_by_email_if_soft_delete assert_emails 0 do visit edit_admin_domain_url(@domain) find(:css, '#soft_delete').set(true) + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' end @@ -79,11 +84,12 @@ def test_uses_legal_template_if_registrant_org assert_emails 0 do visit edit_admin_domain_url(@domain) find(:css, '#soft_delete').set(true) + select 'Registrant (company) is deleted from the Business Register', from: 'reason' click_link_or_button 'Force delete domain' end @domain.reload - assert_equal @domain.notification_template, @domain.template_name + assert_equal 'legal_person', @domain.template_name end # def test_uses_legal_template_if_invalid_email @@ -111,6 +117,7 @@ def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email assert_no_emails do visit edit_admin_domain_url(@domain) uncheck 'notify_by_email' + select 'Registrant (private person) has died', from: 'reason' click_link_or_button 'Force delete domain' end end From 842775fb6db6e9c25f48a4919cc77c43a1afd6b0 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Wed, 21 Oct 2026 15:22:44 +0300 Subject: [PATCH 09/11] Reformat death registry documentation --- doc/death_registry.md | 273 ++++++++++++++++++++++++++---------------- 1 file changed, 168 insertions(+), 105 deletions(-) diff --git a/doc/death_registry.md b/doc/death_registry.md index 745aab33f5..6252aaaa71 100644 --- a/doc/death_registry.md +++ b/doc/death_registry.md @@ -12,14 +12,20 @@ The registry (EIS) checks Estonian private-person contacts against the death ope - **Deceased admin or tech contact:** an optional contact is removed from the domain. A required admin contact (organisation or minor registrant) puts the domain into a soft force delete until a new admin contact is added. - **Notifications:** registrars get a poll message for every action. Registrants and contacts get only the existing force delete emails; no new email to the registrant is sent. -| Reader | Sections | -| --- | --- | -| Lawyer | 2 Legal basis and data handling, 3 How it works, 4 Timeline, 9 Messages | -| System administrator | 5 Production setup, 6 Go-live, 7 Operation, 8 Settings | -| Text reviewers | 9 Messages and notification texts | + +| Reader | Sections | +| -------------------- | ----------------------------------------------------------------------- | +| Lawyer | 2 Legal basis and data handling, 3 How it works, 4 Timeline, 9 Messages | +| System administrator | 5 Production setup, 6 Go-live, 7 Operation, 8 Settings | +| Text reviewers | 9 Messages and notification texts | + + + ## 2. Legal basis and data handling + + ### Legal basis The .ee domain regulation gives EIS the right to start a deletion procedure when the registrant is a natural person who has died. Six months are given for succession; after that the domain enters a deletion procedure, as in the current manual process (the existing `private_person` email). @@ -33,21 +39,25 @@ Decisions: Helen and Timo, 20.10.2026 and 21.10.2026. ### Data source -- Population Register death data on the Estonian open data portal: https://andmed.eesti.ee/datasets/surmaandmed +- Population Register death data on the Estonian open data portal: [https://andmed.eesti.ee/datasets/surmaandmed](https://andmed.eesti.ee/datasets/surmaandmed) - Files used (published by SMIT): - `https://opendata.smit.ee/etl/rahvastik/surmaandmed_1926_kuni_eelmise_aasta_lopuni.csv` (1926 to end of last year) - `https://opendata.smit.ee/etl/rahvastik/surmaandmed_jooksev_aasta.csv` (current year) - Licence: CC BY 4.0. The data is used only inside the registry and not redistributed (see open question 1). - The open data omits roughly the last 7 days of deaths, so the copy is refreshed weekly. + + ### What is stored -| Data | Where | Kept for | -| --- | --- | --- | -| Personal identity code + death date of every deceased person in the open data | Local file (`deaths.txt`) on the registry server | Replaced weekly by a fresh copy; no older copies are kept | -| Death date of a matching contact | `contacts.death_date` | Until the contact is deleted (contact archiving), or cleared when the person is no longer in the open data | -| Time of the last check | `contacts.death_registry_checked_at` | Same as the contact | -| Dry run report (CSV: contact code, ident, death date, roles, domains, registrars) | `reports/` next to the death file, and emailed to the admin address | Until deleted manually | + +| Data | Where | Kept for | +| --------------------------------------------------------------------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | +| Personal identity code + death date of every deceased person in the open data | Local file (`deaths.txt`) on the registry server | Replaced weekly by a fresh copy; no older copies are kept | +| Death date of a matching contact | `contacts.death_date` | Until the contact is deleted (contact archiving), or cleared when the person is no longer in the open data | +| Time of the last check | `contacts.death_registry_checked_at` | Same as the contact | +| Dry run report (CSV: contact code, ident, death date, roles, domains, registrars) | `reports/` next to the death file, and emailed to the admin address | Until deleted manually | + No names, addresses or other fields of the source data are stored. Data protection rules do not grant rights to deceased persons, so no legal assessment was deemed necessary for keeping the copy (decided earlier; see section 10 for the licence question). @@ -58,6 +68,8 @@ No names, addresses or other fields of the source data are stored. Data protecti - Registrars learn of a death only through poll messages about their own domains (texts in section 9). The poll for a deceased registrant includes the ident and death date. - The force delete status note on the domain (visible in admin) contains the ident and death date. + + ### Corrections in the Population Register If a person was wrongly marked as deceased and later disappears from the open data: @@ -66,8 +78,12 @@ If a person was wrongly marked as deceased and later disappears from the open da - during the force delete: it is stopped and the registrar gets a poll message (A4, or A5 when an earlier force delete is restored); - the person is re-checked from a fresh file right before the force delete starts and every day while it runs. + + ## 3. How it works + + ### 3.1 Check at contact creation Applies to EPP and REPP `contact create`, only for `ident_type = priv` and country `EE`, only when `validate_deceased_contacts = true`. @@ -97,21 +113,25 @@ Volume: after the first full run, about 1/365 of the linked contacts per night; - At discovery (death < 6 months ago): poll **A1** to the registrar with the expected force delete start date. No email to the registrant. - At death + 6 months + 1 day: the person is looked up again in the fresh file, then a **fast-track force delete** starts on every domain where the person is registrant: - - reason `deceased_person`, status note "Deceased registrant: , death date "; + - reason `deceased_person`, status note `Deceased registrant: , death date `; - starts the next day; outzone after 15 days; deletion (auction) after another 30 + 1 days (current settings); - registrar gets poll **A3**; registrant and admin contacts get the existing "deceased person" force delete email (**E1**, template `private_person`). - If the registrant is changed (e.g. to an heir), every force delete on the domain is cancelled, as for any registrant change. - If the run on the due day is missed, the next run picks the contact up and the start moves by a day. + + ### 3.4 Deceased admin or tech contact -| Situation | Action | Message | -| --- | --- | --- | -| Tech contact dies | Removed from the domain (domain history and WHOIS updated; the contact object stays) | Poll **B1** | -| Admin contact dies, domain still has enough admin contacts (private registrant, or organisation with another admin) | Removed from the domain | Poll **C1** | -| Last required admin contact of an organisation or minor registrant dies | Soft force delete, reason `deceased_admin_contact`; statuses `serverForceDelete`, `serverRenewProhibited`, `serverTransferProhibited` | Poll **C2**; email **E2** at the force delete start | -| A new admin contact is added afterwards | `CheckForceDeleteLift` cancels the soft force delete | Poll **A4** (standard cancel text) | -| Domain already has a force delete | Left alone | — | + +| Situation | Action | Message | +| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | +| Tech contact dies | Removed from the domain (domain history and WHOIS updated; the contact object stays) | Poll **B1** | +| Admin contact dies, domain still has enough admin contacts (private registrant, or organisation with another admin) | Removed from the domain | Poll **C1** | +| Last required admin contact of an organisation or minor registrant dies | Soft force delete, reason `deceased_admin_contact`; statuses `serverForceDelete`, `serverRenewProhibited`, `serverTransferProhibited` | Poll **C2**; email **E2** at the force delete start | +| A new admin contact is added afterwards | `CheckForceDeleteLift` cancels the soft force delete | Poll **A4** (standard cancel text) | +| Domain already has a force delete | Left alone | — | + Soft force delete start: if the domain expires more than a year from now, the start moves to the nearest registration anniversary; if it expires within a year, there is no start date and the domain simply cannot be renewed (open question 2). @@ -131,6 +151,8 @@ The force delete that releases the domain **earlier** wins (Timo, 21.10.2026). - if the reason is gone, or nothing was saved, the force delete is cancelled completely (poll **A4**). - A registrant change cancels all force deletes, the saved one included. + + ### 3.6 Admin actions - **Schedule force delete** requires a reason, which selects the email: registrant (private person) has died, registrant (company) deleted from the Business Register, invalid email, invalid phone, or other (no email). Before, the email was guessed from the domain data, and any private registrant got the "registrant has died" letter. @@ -141,29 +163,37 @@ The force delete that releases the domain **earlier** wins (Timo, 21.10.2026). - The domain page shows the force delete start date, deletion date and the status note with the reason. - The daily admin force delete summary shows the reason and note (for example `deceased_person: Deceased registrant: …`). + + ## 4. Timeline example Registrant dies on 15.03.2026; the yearly check finds it on 02.05.2026. -| Date | Event | -| --- | --- | -| 15.03.2026 | Death | -| ~22.03.2026 | Appears in the open data (about a week's delay) | -| 02.05.2026 | Found by the daily job; death date saved; poll A1 to the registrar ("force delete will start on 16.09.2026") | -| 15.09.2026 | 6 months after death; person looked up again | -| 16.09.2026 | Fast-track force delete starts; poll A3; email E1 to registrant and admin contacts | -| 01.10.2026 | Outzone: domain removed from the zone (`clientHold`) | -| 31.10.2026 | Deletion date: domain goes to auction (start day − 1 + 15 + 30 + 1 days) | + +| Date | Event | +| ----------- | ------------------------------------------------------------------------------------------------------------ | +| 15.03.2026 | Death | +| ~22.03.2026 | Appears in the open data (about a week's delay) | +| 02.05.2026 | Found by the daily job; death date saved; poll A1 to the registrar ("force delete will start on 16.09.2026") | +| 15.09.2026 | 6 months after death; person looked up again | +| 16.09.2026 | Fast-track force delete starts; poll A3; email E1 to registrant and admin contacts | +| 01.10.2026 | Outzone: domain removed from the zone (`clientHold`) | +| 31.10.2026 | Deletion date: domain goes to auction (start day − 1 + 15 + 30 + 1 days) | + A registrant change at any point before the deletion date cancels the force delete. If the yearly check finds the death only after 6 months have passed, A1 is skipped and the force delete starts the next day. ## 5. Production setup + + ### 5.1 Release 1. Deploy the release. 2. Run migrations: `bin/rails db:migrate RAILS_ENV=production`. They add `contacts.death_date`, `contacts.death_registry_checked_at` and indexes. Existing data is not changed. + + ### 5.2 Configuration (`config/application.yml`) ```yaml @@ -176,6 +206,8 @@ death_registry_dry_run: 'true' # turned off at go-live admin_notification_email: 'admin@…' # receives problems and dry run reports (existing setting) ``` + + ### 5.3 File location - The file must be readable by **every** process that creates contacts (EPP and REPP app servers) and by the server that runs the job. Use a shared disk if they are on different machines. @@ -183,6 +215,8 @@ admin_notification_email: 'admin@…' # receives problems and dry run reports - Size: 23 bytes per record (`<11-digit ident>;\n`), sorted by ident. - The server needs outbound HTTPS to `opendata.smit.ee`. + + ### 5.4 Cron Production uses a hand-maintained crontab (`config/schedule.rb` is not used there). Add **one** line: @@ -198,19 +232,19 @@ The existing `CheckForceDeleteLift` cron line (already in the production crontab ## 6. Go-live 1. **Build the file** on the production server and check it: - ``` + ``` bin/rails r -e production "DeathRegistryFileBuildJob.perform_now" ls -l /shared/death_registry/deaths.txt # size divisible by 23, fresh mtime - ``` + ``` 2. **Dry run** (`death_registry_dry_run: 'true'`), run once by hand: - ``` + ``` bin/rails r -e production "DeathRegistryCheckJob.perform_now" - ``` + ``` The admin address receives "Death registry dry run report" with a CSV of every deceased contact found, their roles, domains, registrars and whether 6 months have passed. The first run checks all linked contacts, not 1/365. 3. **Review the report** (Timo, Helen): - - check a random sample of 10–20 rows against the Population Register; - - compare with recent manual ENTITY_BURIED cases; - - count rows with `six_months_passed = true`: each of their domains gets a fast-track force delete on the first real run. Decide whether registrars are warned beforehand or the start is spread out (open question 8). + - check a random sample of 10–20 rows against the Population Register; + - compare with recent manual ENTITY_BURIED cases; + - count rows with `six_months_passed = true`: each of their domains gets a fast-track force delete on the first real run. Decide whether registrars are warned beforehand or the start is spread out (open question 8). 4. **Add the cron line** (5.4). 5. **Turn on the creation check:** `validate_deceased_contacts: 'true'`, restart the app servers. 6. **Turn off dry run:** `death_registry_dry_run: 'false'`. The next night's run saves death dates, sends polls and starts force deletes. @@ -219,16 +253,20 @@ The existing `CheckForceDeleteLift` cron line (already in the production crontab ## 7. Operation + + ### 7.1 Monitoring - **Log line** after each run (`log/production.log`): - `DeathRegistryCheckJob: checked N contacts, found N deceased, started N and cancelled N force deletes, removed N admin and tech contacts` -- **Problem email** "Death registry check problem - " to `admin_notification_email` when: +`DeathRegistryCheckJob: checked N contacts, found N deceased, started N and cancelled N force deletes, removed N admin and tech contacts` +- **Problem email** `Death registry check problem - ` to `admin_notification_email` when: - the file rebuild failed (download error, HTTP error, missing columns, fewer than `death_registry_min_records` records); the old file is kept; - the file is missing, stale (older than `death_registry_max_file_age_days`) or malformed; contacts are not checked that night; - the dry run report could not be written or sent. - A stale file never blocks contact creation; it only logs a warning per contact. + + ### 7.2 Commands ``` @@ -251,39 +289,51 @@ bin/rails r -e production "p Contact.where.not(death_date: nil).count" bin/rails r -e production "puts Domain.where(\"force_delete_data->'template_name' = 'deceased_person'\").pluck(:name)" ``` + + ### 7.3 Manual actions -| Case | What to do | -| --- | --- | -| Person is alive (registrant or heir contacts EIS) | Admin → domain → Edit → Cancel force delete. The death date is cleared and the contact is not checked again for a year. | -| Person is alive but the open data is not yet corrected | Same; also ask the Population Register to correct the data, otherwise the person is found again in a year. | -| Restored earlier force delete is not wanted | Cancel force delete once more. | -| Soft force delete for a deceased admin contact should be lifted | Add a living admin contact; `CheckForceDeleteLift` lifts it the next run, or cancel by hand. | + +| Case | What to do | +| --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| Person is alive (registrant or heir contacts EIS) | Admin → domain → Edit → Cancel force delete. The death date is cleared and the contact is not checked again for a year. | +| Person is alive but the open data is not yet corrected | Same; also ask the Population Register to correct the data, otherwise the person is found again in a year. | +| Restored earlier force delete is not wanted | Cancel force delete once more. | +| Soft force delete for a deceased admin contact should be lifted | Add a living admin contact; `CheckForceDeleteLift` lifts it the next run, or cancel by hand. | + + + ### 7.4 Troubleshooting -| Symptom | Cause / fix | -| --- | --- | -| Problem email "file is missing, stale or malformed" | Rebuild failed for 2+ weeks or the path is wrong. Run the rebuild by hand and read the error. | -| "only N records, expected at least 100000" | Source returned partial data. Old file kept; retry later. Check the source URLs. | -| "CSV is missing columns" | SMIT changed the file format. Code change needed in `DeathRegistry::FileBuilder`. | -| Contacts created without check | `validate_deceased_contacts` off, or the file is not readable from the EPP/REPP server. | + +| Symptom | Cause / fix | +| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | +| Problem email "file is missing, stale or malformed" | Rebuild failed for 2+ weeks or the path is wrong. Run the rebuild by hand and read the error. | +| "only N records, expected at least 100000" | Source returned partial data. Old file kept; retry later. Check the source URLs. | +| "CSV is missing columns" | SMIT changed the file format. Code change needed in `DeathRegistry::FileBuilder`. | +| Contacts created without check | `validate_deceased_contacts` off, or the file is not readable from the EPP/REPP server. | | Domain stays in `deceased_admin_contact` after admin contact replaced | Check that the `CheckForceDeleteLift` cron line ran; the domain needs as many living admin contacts as `admin_contacts_min_count`. | + + + ## 8. Settings -| Setting | Default | Purpose | -| --- | --- | --- | -| `death_registry_file_path` | `tmp/death_registry/deaths.txt` | Location of the local copy; use a shared disk in production | -| `death_registry_source_urls` | the two opendata.smit.ee CSVs | Comma-separated source URLs | -| `death_registry_max_file_age_days` | 8 | Older file counts as stale; lookups refuse it | -| `death_registry_min_records` | 100000 | A download with fewer records is rejected | -| `validate_deceased_contacts` | false | Refuse deceased persons at contact creation | -| `death_registry_dry_run` | true | Job only reports; saves nothing and sends nothing | -| `admin_notification_email` | existing | Receives problem emails and dry run reports | -| `expire_warning_period` | existing (15) | Days from force delete start to outzone | -| `redemption_grace_period` | existing (30) | Days from outzone to deletion | -| `admin_contacts_min_count` | existing | Required admin contacts for organisation and minor registrants | + +| Setting | Default | Purpose | +| ---------------------------------- | ------------------------------- | -------------------------------------------------------------- | +| `death_registry_file_path` | `tmp/death_registry/deaths.txt` | Location of the local copy; use a shared disk in production | +| `death_registry_source_urls` | the two opendata.smit.ee CSVs | Comma-separated source URLs | +| `death_registry_max_file_age_days` | 8 | Older file counts as stale; lookups refuse it | +| `death_registry_min_records` | 100000 | A download with fewer records is rejected | +| `validate_deceased_contacts` | false | Refuse deceased persons at contact creation | +| `death_registry_dry_run` | true | Job only reports; saves nothing and sends nothing | +| `admin_notification_email` | existing | Receives problem emails and dry run reports | +| `expire_warning_period` | existing (15) | Days from force delete start to outzone | +| `redemption_grace_period` | existing (30) | Days from outzone to deletion | +| `admin_contacts_min_count` | existing | Required admin contacts for organisation and minor registrants | + Fixed in code: check interval 1 year, force delete 6 months after death, file rebuild after 7 days. @@ -293,34 +343,40 @@ All poll texts are **English drafts** and need review (Helen, Mare). Estonian ve ### Registrar poll messages -| Code | When | Text | -| --- | --- | --- | -| **A1** | Registrant found deceased, less than 6 months ago | According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession. | -| **A3** | Fast-track force delete started | Force delete set on domain %{domain_name} because, according to the Estonian Population Register, the registrant (ident %{ident}) has died. Force Delete Type: Fast Track. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | -| **A4** | Force delete cancelled (person alive, admin cancel, admin contact replaced) — existing text | Force delete is cancelled on domain %{domain_name} | -| **A5** | Death force delete stopped, earlier force delete restored | Force delete because of the registrant's death was stopped on domain %{domain_name}. The earlier force delete continues: %{reason}. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | -| **B1** | Deceased tech contact removed | Tech contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. Add a new tech contact if needed. | -| **C1** | Deceased admin contact removed | Admin contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. | -| **C2** | Soft force delete for the last required admin contact | Force delete set on domain %{domain_name}. Admin contact %{contact_code} has died according to the Estonian Population Register. Add a new admin contact; until then the domain cannot be renewed or transferred to another registrar. Force Delete Type: Soft. Force Delete Start Date: %{force_delete_start_date}. Expire date: %{valid_to}. | + +| Code | When | Text | +| ------ | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **A1** | Registrant found deceased, less than 6 months ago | According to the Estonian Population Register, the registrant of domain %{domain_name} (ident %{ident}) died on %{death_date}. Force delete will start on %{force_delete_start} unless the registrant is changed. An heir can take over the domain by a registrant change with a certificate of succession. | +| **A3** | Fast-track force delete started | Force delete set on domain %{domain_name} because, according to the Estonian Population Register, the registrant (ident %{ident}) has died. Force Delete Type: Fast Track. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | +| **A4** | Force delete cancelled (person alive, admin cancel, admin contact replaced) — existing text | Force delete is cancelled on domain %{domain_name} | +| **A5** | Death force delete stopped, earlier force delete restored | Force delete because of the registrant's death was stopped on domain %{domain_name}. The earlier force delete continues: %{reason}. Force Delete Start Date: %{force_delete_start_date}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. | +| **B1** | Deceased tech contact removed | Tech contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. Add a new tech contact if needed. | +| **C1** | Deceased admin contact removed | Admin contact %{contact_code} was removed from domain %{domain_name} because, according to the Estonian Population Register, the person has died. | +| **C2** | Soft force delete for the last required admin contact | Force delete set on domain %{domain_name}. Admin contact %{contact_code} has died according to the Estonian Population Register. Add a new admin contact; until then the domain cannot be renewed or transferred to another registrar. Force Delete Type: Soft. Force Delete Start Date: %{force_delete_start_date}. Expire date: %{valid_to}. | + Notes for reviewers: - A5 `%{reason}` is a technical reason code (`invalid_email`, `deceased_admin_contact`, …) or the manual status note. Consider mapping it to readable words. - A4 is the existing generic cancel text and does not say why. + + ### EPP / REPP error -| When | Code | Text (en / et) | -| --- | --- | --- | + +| When | Code | Text (en / et) | +| --------------------------------------------- | ---- | --------------------------------------- | | Contact create with a deceased person's ident | 2003 | Ident is invalid / Isikukood on kehtetu | + The error deliberately does not say that the person is deceased. ### Emails to registrant and contacts Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses / Domain %{domain_name} is in deletion process". The Russian line was removed from the subject. -**E1 — deceased registrant (existing template `private_person`, unchanged), sent at the fast-track start:** +**E1 — deceased registrant (existing template** `private_person`**, unchanged), sent at the fast-track start:** > Lugupeetud domeeni %{domain} registreerija/halduskontakt > @@ -330,7 +386,7 @@ Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses > > Domeeni suhtes õigust omaval isikul on võimalus esitada domeeni %{domain} registripidajale %{registrar} domeeni üleandmise taotlus, millele tuleb lisada pärimisõiguse tõend. Dokumentatsioon tuleb esitada registripidajale %{delete_period_length} päeva jooksul. > -> Kui üleandmine ei ole %{delete_period_length} päeva jooksul toimunud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. … +> Kui üleandmine ei ole %{delete_period_length} päeva jooksul toimunud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda [https://auction.internet.ee](https://auction.internet.ee). … > > --- > @@ -344,17 +400,17 @@ Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses > > If the transfer is not made within %{delete_period_length} days, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing template) -**E2 — deceased admin contact (new template `deceased_admin_contact`, draft), sent at the soft force delete start:** +**E2 — deceased admin contact (new template** `deceased_admin_contact`**, draft), sent at the soft force delete start:** > Lugupeetud domeeni %{domain} registreerija/halduskontakt > > Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni %{domain} halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt. > -> Et see olukord on vastuolus .ee domeenireeglitega (https://www.internet.ee/domains/ee-domain-regulation), algatas EIS %{delete_period_length} päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen %{expire_warning_period} esimest päeva internetis kättesaadav. +> Et see olukord on vastuolus .ee domeenireeglitega ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), algatas EIS %{delete_period_length} päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen %{expire_warning_period} esimest päeva internetis kättesaadav. > > Uue halduskontakti lisamiseks pöörduge palun oma registripidaja %{registrar} poole. > -> Kui uut halduskontakti ei ole %{delete_period_length} päeva jooksul lisatud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. … +> Kui uut halduskontakti ei ole %{delete_period_length} päeva jooksul lisatud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda [https://auction.internet.ee](https://auction.internet.ee). … > > --- > @@ -362,7 +418,7 @@ Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses > > According to the Estonian Population Register, the administrative contact of the domain %{domain} has died. The domain must have a valid administrative contact. > -> Since this is a violation of Estonian domain regulations (https://www.internet.ee/domains/ee-domain-regulation), %{delete_period_length}-day deletion process has started for the %{domain} domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first %{expire_warning_period} days the domain will remain available on the Internet during the deletion process. +> Since this is a violation of Estonian domain regulations ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), %{delete_period_length}-day deletion process has started for the %{domain} domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first %{expire_warning_period} days the domain will remain available on the Internet during the deletion process. > > To add a new administrative contact, please contact your registrar %{registrar}. > @@ -372,38 +428,45 @@ No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a ### Admin emails (to `admin_notification_email`) -| Subject | When | Body | -| --- | --- | --- | -| Death registry check problem - %{date} | File rebuild failed, file unusable, or report failed | List of problems, e.g. "Rebuilding the death registry file failed: …", "Death registry file … is missing, stale or malformed. Contacts were not checked." | -| Death registry dry run report - %{date} | Every run in dry run mode | "Checked contacts: N. Deceased contacts found: N. The attached CSV lists the deceased contacts. Nothing was saved and no poll messages were sent." + CSV attachment | + +| Subject | When | Body | +| --------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Death registry check problem - %{date} | File rebuild failed, file unusable, or report failed | List of problems, e.g. "Rebuilding the death registry file failed: …", "Death registry file … is missing, stale or malformed. Contacts were not checked." | +| Death registry dry run report - %{date} | Every run in dry run mode | "Checked contacts: N. Deceased contacts found: N. The attached CSV lists the deceased contacts. Nothing was saved and no poll messages were sent." + CSV attachment | + + + ### Admin interface -| Where | Text | -| --- | --- | -| Domain page, force delete status note | "Deceased registrant: , death date " or "Admin contact has died" | -| Domain page | "Force delete start" (new row, next to the force delete date) | -| Contact page | "Death date", "Death registry checked" (shown only when set) | -| Contact list filter | "Death registry": "Deceased" / "Not checked" | -| Daily force delete summary email (reason column) | "deceased_person: Deceased registrant: , death date ", "deceased_admin_contact: Admin contact has died" | + +| Where | Text | +| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | +| Domain page, force delete status note | `Deceased registrant: , death date ` or `Admin contact has died` | +| Domain page | "Force delete start" (new row, next to the force delete date) | +| Contact page | "Death date", "Death registry checked" (shown only when set) | +| Contact list filter | "Death registry": "Deceased" / "Not checked" | +| Daily force delete summary email (reason column) | `deceased_person: Deceased registrant: , death date `, `deceased_admin_contact: Admin contact has died` | + **Schedule force delete dialog** (admin → domain → Edit → Schedule force delete): -| Element | Text | -| --- | --- | -| Field | Reason (required) | -| Option → email | "Registrant (private person) has died" → E1 `private_person` | -| Option → email | "Registrant (company) is deleted from the Business Register" → `legal_person` | -| Option → email | "Invalid email" → `invalid_email` (failing addresses go into the status note) | -| Option → email | "Invalid phone" → `invalid_phone` | -| Option → email | "Other (no email)" → no email to registrant and contacts | -| Hint | The reason selects the email to the registrant and administrative contacts. "Other" sends no email. | -| Error, no reason chosen | Choose the reason of the force delete | -| Error, "Invalid email" chosen but no contact email fails verification | No contact of the domain has an invalid email | -The automatic reasons `deceased_person` and `deceased_admin_contact` are not offered manually: the death registry check would stop such a force delete when the person is not in the open data. +| Element | Text | +| --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | +| Field | Reason (required) | +| Option → email | "Registrant (private person) has died" → E1 `private_person` | +| Option → email | "Registrant (company) is deleted from the Business Register" → `legal_person` | +| Option → email | "Invalid email" → `invalid_email` (failing addresses go into the status note) | +| Option → email | "Invalid phone" → `invalid_phone` | +| Option → email | "Other (no email)" → no email to registrant and contacts | +| Hint | The reason selects the email to the registrant and administrative contacts. "Other" sends no email. | +| Error, no reason chosen | Choose the reason of the force delete | +| Error, "Invalid email" chosen but no contact email fails verification | No contact of the domain has an invalid email | + + +The automatic reasons `deceased_person` and `deceased_admin_contact` are not offered manually: the death registry check would stop such a force delete when the person is not in the open dat10. Open questions -## 10. Open questions +1. **ENTITY_BURIED manual force delete:** switch it to fast track too, now that deceased registrants are handled automatically? +2. **Existing deceased contact on a new domain or registrant change:** refuse via EPP/REPP? Not checked today. -6. **ENTITY_BURIED manual force delete** (admin Mass actions, always soft): switch it to fast track too, now that deceased registrants and deleted companies are handled automatically with fast track? Its letter is already fixed: it now always uses `private_person` or `legal_person` by registrant type, never the invalid email letter. -9. **Existing deceased contact on a new domain or registrant change:** refuse via EPP/REPP? Not checked today. From 845398e8e2a72267185071761fd42a2421f61e86 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Wed, 21 Oct 2026 15:24:31 +0300 Subject: [PATCH 10/11] Updated death registry doc --- doc/death_registry.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/doc/death_registry.md b/doc/death_registry.md index 6252aaaa71..151adf7635 100644 --- a/doc/death_registry.md +++ b/doc/death_registry.md @@ -100,7 +100,7 @@ One run does, in order: 1. **Refresh the file** if it is older than 7 days (download, validate, atomic replace). On failure the old file is kept and the admin gets an email. 2. **Yearly check:** EE private contacts linked to at least one domain (as registrant, admin or tech), without a death date, whose last check is empty or older than 1 year. Each is looked up; living persons get `death_registry_checked_at = now`, deceased ones get `death_date`. - - For a deceased registrant whose death is less than 6 months ago, the registrar gets poll **A1** for each of the person's domains. + - For a deceased registrant whose death is less than 6 months ago, the registrar gets poll **A1** for each of the person's domains. 3. **Start fast-track force deletes** for registrants who died at least 6 months ago (see 3.3). 4. **Stop force deletes of persons no longer in the file** (see 3.5). 5. **Handle deceased admin and tech contacts** (see 3.4). @@ -113,7 +113,7 @@ Volume: after the first full run, about 1/365 of the linked contacts per night; - At discovery (death < 6 months ago): poll **A1** to the registrar with the expected force delete start date. No email to the registrant. - At death + 6 months + 1 day: the person is looked up again in the fresh file, then a **fast-track force delete** starts on every domain where the person is registrant: - - reason `deceased_person`, status note `Deceased registrant: , death date `; + - reason `deceased_person`, status note "Deceased registrant: , death date "; - starts the next day; outzone after 15 days; deletion (auction) after another 30 + 1 days (current settings); - registrar gets poll **A3**; registrant and admin contacts get the existing "deceased person" force delete email (**E1**, template `private_person`). - If the registrant is changed (e.g. to an heir), every force delete on the domain is cancelled, as for any registrant change. @@ -259,7 +259,7 @@ The existing `CheckForceDeleteLift` cron line (already in the production crontab - **Log line** after each run (`log/production.log`): `DeathRegistryCheckJob: checked N contacts, found N deceased, started N and cancelled N force deletes, removed N admin and tech contacts` -- **Problem email** `Death registry check problem - ` to `admin_notification_email` when: +- **Problem email** "Death registry check problem - " to `admin_notification_email` when: - the file rebuild failed (download error, HTTP error, missing columns, fewer than `death_registry_min_records` records); the old file is kept; - the file is missing, stale (older than `death_registry_max_file_age_days`) or malformed; contacts are not checked that night; - the dry run report could not be written or sent. @@ -442,11 +442,11 @@ No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a | Where | Text | | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | -| Domain page, force delete status note | `Deceased registrant: , death date ` or `Admin contact has died` | +| Domain page, force delete status note | "Deceased registrant: , death date " or "Admin contact has died" | | Domain page | "Force delete start" (new row, next to the force delete date) | | Contact page | "Death date", "Death registry checked" (shown only when set) | | Contact list filter | "Death registry": "Deceased" / "Not checked" | -| Daily force delete summary email (reason column) | `deceased_person: Deceased registrant: , death date `, `deceased_admin_contact: Admin contact has died` | +| Daily force delete summary email (reason column) | "deceased_person: Deceased registrant: , death date ", "deceased_admin_contact: Admin contact has died" | **Schedule force delete dialog** (admin → domain → Edit → Schedule force delete): @@ -465,7 +465,9 @@ No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a | Error, "Invalid email" chosen but no contact email fails verification | No contact of the domain has an invalid email | -The automatic reasons `deceased_person` and `deceased_admin_contact` are not offered manually: the death registry check would stop such a force delete when the person is not in the open dat10. Open questions +The automatic reasons `deceased_person` and `deceased_admin_contact` are not offered manually: the death registry check would stop such a force delete when the person is not in the open data. + +## 10. Open questions 1. **ENTITY_BURIED manual force delete:** switch it to fast track too, now that deceased registrants are handled automatically? 2. **Existing deceased contact on a new domain or registrant change:** refuse via EPP/REPP? Not checked today. From b81088fd40a0b8676bd14603a3e1d9eaa6a10675 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Fri, 13 Nov 2026 15:57:34 +0200 Subject: [PATCH 11/11] Updated mail texts --- Dockerfile | 6 +++ Dockerfile.production | 5 +++ .../domains/force_delete/set_status.rb | 16 ++++++- app/presenters/domain_presenter.rb | 4 ++ .../forced/deceased_admin_contact.html.erb | 8 ++-- .../forced/deceased_admin_contact.text.erb | 8 ++-- doc/death_registry.md | 10 ++--- test/mailers/domain_delete_mailer_test.rb | 20 +++++++++ .../deceased_domain_contacts_test.rb | 45 +++++++++++++++++++ 9 files changed, 108 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index fdfb9f9751..98e0a8c925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,12 @@ FROM --platform=linux/amd64 ruby:3.0.3-bullseye SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +# bullseye is EOL: its packages were moved from deb.debian.org/security.debian.org to archive.debian.org +RUN sed -i -e 's|http://deb.debian.org/debian|http://archive.debian.org/debian|g' \ + -e 's|http://security.debian.org/debian-security|http://archive.debian.org/debian-security|g' \ + /etc/apt/sources.list + RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \ build-essential=* \ imagemagick=* \ diff --git a/Dockerfile.production b/Dockerfile.production index 898bfbaee8..e2f48b0da0 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -11,6 +11,11 @@ ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" +# bullseye is EOL: its packages were moved from deb.debian.org/security.debian.org to archive.debian.org +RUN sed -i -e 's|http://deb.debian.org/debian|http://archive.debian.org/debian|g' \ + -e 's|http://security.debian.org/debian-security|http://archive.debian.org/debian-security|g' \ + /etc/apt/sources.list + # Throw-away build stage to reduce size of final image FROM base AS build diff --git a/app/interactions/domains/force_delete/set_status.rb b/app/interactions/domains/force_delete/set_status.rb index ed2eb88705..c386d4857a 100644 --- a/app/interactions/domains/force_delete/set_status.rb +++ b/app/interactions/domains/force_delete/set_status.rb @@ -21,7 +21,11 @@ def force_delete_fast_track def force_delete_soft years = (domain.valid_to.to_date - Time.zone.today).to_i / 365 - soft_forcedelete_dates(years) if years.positive? + if years.positive? + soft_forcedelete_dates(years) + elsif reason == 'deceased_admin_contact' + deceased_admin_contact_dates + end end private @@ -39,6 +43,16 @@ def soft_forcedelete_dates(years) Setting.redemption_grace_period.days end + # A domain expiring within a year gets no soft force delete dates, but the + # deceased admin contact email must name the deletion date. The process + # starts at expiry, or tomorrow if the domain has already expired. + def deceased_admin_contact_dates + domain.force_delete_start = [domain.valid_to, Time.zone.now.beginning_of_day + 1.day].max + domain.force_delete_date = domain.force_delete_start + + Setting.expire_warning_period.days + + Setting.redemption_grace_period.days + end + def redemption_grace_period_days Setting.redemption_grace_period.days + 1.day end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 9f0ac450a9..cc7405b040 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -46,6 +46,10 @@ def force_delete_start domain.force_delete_start end + def force_delete_outzone_date + view.l(domain.outzone_date.to_date) if domain.force_delete_scheduled? + end + def force_delete_toggle_btn return inactive_schedule_force_delete_btn if domain.discarded? diff --git a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb index 5e029be150..bfc096487d 100644 --- a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb +++ b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.html.erb @@ -2,11 +2,11 @@

Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni <%= @domain.name %> halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt.

-

Et see olukord on vastuolus .ee domeenireeglitega, algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.

+

Et see olukord on vastuolus .ee domeenireeglitega, algatas EIS domeeni <%= @domain.name %> suhtes kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen internetis kättesaadav kuni <%= @domain.force_delete_outzone_date %>.

Uue halduskontakti lisamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole.

-

Kui uut halduskontakti ei ole <%= @delete_period_length %> päeva jooksul lisatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe siit.

+

Kui uut halduskontakti ei ole lisatud enne <%= @domain.force_delete_date %>, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe siit.

Lisaküsimuste korral võtke palun ühendust oma registripidajaga:

<%= render 'mailers/shared/registrar/registrar.et.html', registrar: @registrar %> @@ -18,11 +18,11 @@

According to the Estonian Population Register, the administrative contact of the domain <%= @domain.name %> has died. The domain must have a valid administrative contact.

-

Since this is a violation of Estonian domain regulations, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.

+

Since this is a violation of Estonian domain regulations, a deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. During the deletion process the domain will remain available on the Internet until <%= @domain.force_delete_outzone_date %>.

To add a new administrative contact, please contact your registrar <%= @registrar.name %>.

-

If no new administrative contact is added within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results here.

+

If no new administrative contact is added before <%= @domain.force_delete_date %>, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results here.

Should you have additional questions, please contact your registrar:

<%= render 'mailers/shared/registrar/registrar.en.html', registrar: @registrar %> diff --git a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb index a518bed71f..c82e202a9a 100644 --- a/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb +++ b/app/views/mailers/domain_delete_mailer/forced/deceased_admin_contact.text.erb @@ -2,11 +2,11 @@ Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni <%= @domain.name %> halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt. -Et see olukord on vastuolus .ee domeenireeglitega (https://www.internet.ee/domains/ee-domain-regulation), algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav. +Et see olukord on vastuolus .ee domeenireeglitega (https://www.internet.ee/domains/ee-domain-regulation), algatas EIS domeeni <%= @domain.name %> suhtes kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen internetis kättesaadav kuni <%= @domain.force_delete_outzone_date %>. Uue halduskontakti lisamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole. -Kui uut halduskontakti ei ole <%= @delete_period_length %> päeva jooksul lisatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe https://www.internet.ee/domeenid/domeenide-oksjonikeskkonna-kasutajatingimused#3-oksjonikeskkonna-enampakkumisel-osalemise-tingimused. +Kui uut halduskontakti ei ole lisatud enne <%= @domain.force_delete_date %>, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile .ee oksjonikeskkonda https://auction.internet.ee. Juhul kui domeenile <%= @domain.name %> ei tehta oksjonil 24h möödudes pakkumist, domeen vabaneb ja on registreerimiseks vabalt kättesaadav kõigile huvilistele. Muude võimalike oksjoni tulemuste kohta loe https://www.internet.ee/domeenid/domeenide-oksjonikeskkonna-kasutajatingimused#3-oksjonikeskkonna-enampakkumisel-osalemise-tingimused. Lisaküsimuste korral võtke palun ühendust oma registripidajaga: <%= render 'mailers/shared/registrar/registrar.et.text', registrar: @registrar %> @@ -18,11 +18,11 @@ Dear registrant/administrative contact of .ee domain, According to the Estonian Population Register, the administrative contact of the domain <%= @domain.name %> has died. The domain must have a valid administrative contact. -Since this is a violation of Estonian domain regulations (https://www.internet.ee/domains/ee-domain-regulation), <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process. +Since this is a violation of Estonian domain regulations (https://www.internet.ee/domains/ee-domain-regulation), a deletion process has started for the <%= @domain.name %> domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. During the deletion process the domain will remain available on the Internet until <%= @domain.force_delete_outzone_date %>. To add a new administrative contact, please contact your registrar <%= @registrar.name %>. -If no new administrative contact is added within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment https://auction.internet.ee. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results at https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment. +If no new administrative contact is added before <%= @domain.force_delete_date %>, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the .ee auction environment https://auction.internet.ee. If no offer is made for the domain <%= @domain.name %> at auction within 24 hours, the domain will be released and made freely available for registration to anyone interested on a first-come, first-served basis. Read more about other potential auction results at https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment. Should you have additional questions, please contact your registrar: <%= render 'mailers/shared/registrar/registrar.en.text', registrar: @registrar %> diff --git a/doc/death_registry.md b/doc/death_registry.md index 151adf7635..79c3be7223 100644 --- a/doc/death_registry.md +++ b/doc/death_registry.md @@ -400,17 +400,17 @@ Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses > > If the transfer is not made within %{delete_period_length} days, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing template) -**E2 — deceased admin contact (new template** `deceased_admin_contact`**, draft), sent at the soft force delete start:** +**E2 — deceased admin contact (new template** `deceased_admin_contact`**, draft), sent at the soft force delete start.** The email names dates, not a day count: a soft force delete starts at the next anniversary of `valid_to`, so "45 days" would be wrong. `%{outzone_date}` = `force_delete_start` + `expire_warning_period`. If the domain expires within a year, the force delete starts at `valid_to` (tomorrow if already expired), so `%{force_delete_date}` is never empty: > Lugupeetud domeeni %{domain} registreerija/halduskontakt > > Eesti Interneti Sihtasutusele (EIS) on Rahvastikuregistri andmetel saanud teatavaks, et domeeni %{domain} halduskontakt on surnud. Domeenil peab olema kehtiv halduskontakt. > -> Et see olukord on vastuolus .ee domeenireeglitega ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), algatas EIS %{delete_period_length} päeva pikkuse kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen %{expire_warning_period} esimest päeva internetis kättesaadav. +> Et see olukord on vastuolus .ee domeenireeglitega ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), algatas EIS domeeni %{domain} suhtes kustutusmenetluse. Kuni uus halduskontakt pole lisatud, ei saa domeeni pikendada ega registripidajat vahetada. Menetluse käigus on domeen internetis kättesaadav kuni %{outzone_date}. > > Uue halduskontakti lisamiseks pöörduge palun oma registripidaja %{registrar} poole. > -> Kui uut halduskontakti ei ole %{delete_period_length} päeva jooksul lisatud, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda [https://auction.internet.ee](https://auction.internet.ee). … +> Kui uut halduskontakti ei ole lisatud enne %{force_delete_date}, läheb domeen %{domain} %{force_delete_date} domeenioksjonile .ee oksjonikeskkonda [https://auction.internet.ee](https://auction.internet.ee). … > > --- > @@ -418,11 +418,11 @@ Subject (all force delete emails): "Domeen %{domain_name} on kustutusmenetluses > > According to the Estonian Population Register, the administrative contact of the domain %{domain} has died. The domain must have a valid administrative contact. > -> Since this is a violation of Estonian domain regulations ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), %{delete_period_length}-day deletion process has started for the %{domain} domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. For the first %{expire_warning_period} days the domain will remain available on the Internet during the deletion process. +> Since this is a violation of Estonian domain regulations ([https://www.internet.ee/domains/ee-domain-regulation](https://www.internet.ee/domains/ee-domain-regulation)), a deletion process has started for the %{domain} domain. Until a new administrative contact is added, the domain cannot be renewed or transferred to another registrar. During the deletion process the domain will remain available on the Internet until %{outzone_date}. > > To add a new administrative contact, please contact your registrar %{registrar}. > -> If no new administrative contact is added within %{delete_period_length} days, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing templates) +> If no new administrative contact is added before %{force_delete_date}, the domain %{domain} will go to domain auction on %{force_delete_date} … (auction paragraph, registrar contacts and signature as in the existing templates) No email is sent for: A1 (discovery), removal of an optional contact (B1, C1), a stopped or restored force delete (A4, A5). diff --git a/test/mailers/domain_delete_mailer_test.rb b/test/mailers/domain_delete_mailer_test.rb index 0fdcb58680..7bf5761617 100644 --- a/test/mailers/domain_delete_mailer_test.rb +++ b/test/mailers/domain_delete_mailer_test.rb @@ -100,6 +100,26 @@ def test_forced_deceased_admin_contact assert_includes email.html_part.body.to_s, 'administrative contact of the domain shop.test has died' end + def test_forced_deceased_admin_contact_names_dates_not_day_count + Setting.expire_warning_period = 15 + @domain.update_columns(statuses: [DomainStatus::FORCE_DELETE], + force_delete_start: Time.zone.parse('2027-03-01'), + force_delete_date: Date.new(2027, 4, 15)) + + email = DomainDeleteMailer.forced(domain: @domain, + registrar: @domain.registrar, + registrant: @domain.registrant, + template_name: 'deceased_admin_contact').deliver_now + + text = email.text_part.body.to_s + assert_includes text, 'Kui uut halduskontakti ei ole lisatud enne 2027-04-15' + assert_includes text, 'internetis kättesaadav kuni 2027-03-16' + assert_includes text, 'If no new administrative contact is added before 2027-04-15' + assert_includes text, 'remain available on the Internet until 2027-03-16' + assert_not_includes text, 'päeva jooksul' + assert_not_includes text, 'päeva pikkuse' + end + def test_forced_deceased_person_uses_private_person_letter email = DomainDeleteMailer.forced(domain: @domain, registrar: @domain.registrar, diff --git a/test/services/death_registry/deceased_domain_contacts_test.rb b/test/services/death_registry/deceased_domain_contacts_test.rb index 2262bb9bca..73e95ff985 100644 --- a/test/services/death_registry/deceased_domain_contacts_test.rb +++ b/test/services/death_registry/deceased_domain_contacts_test.rb @@ -59,6 +59,51 @@ def test_starts_soft_force_delete_when_last_admin_contact_of_organisation_dies 'has died according to the Estonian Population Register.%').exists? end + def test_soft_force_delete_dates_follow_expiry_anniversary_for_multiyear_domain + Setting.expire_warning_period = 15 + Setting.redemption_grace_period = 30 + travel_to Time.zone.parse('2026-11-13') + domain = domains(:library) + domain.update_columns(valid_to: Time.zone.parse('2029-03-01')) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + + call + + domain.reload + assert_equal Time.zone.parse('2027-03-01'), domain.force_delete_start + assert_equal Date.new(2027, 4, 15), domain.force_delete_date + end + + def test_soft_force_delete_starts_at_expiry_when_domain_expires_within_a_year + Setting.expire_warning_period = 15 + Setting.redemption_grace_period = 30 + travel_to Time.zone.parse('2026-11-13') + domain = domains(:library) + domain.update_columns(valid_to: Time.zone.parse('2027-02-01')) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + + call + + domain.reload + assert_equal Time.zone.parse('2027-02-01'), domain.force_delete_start + assert_equal Date.new(2027, 3, 18), domain.force_delete_date + end + + def test_soft_force_delete_starts_tomorrow_when_domain_has_expired + Setting.expire_warning_period = 15 + Setting.redemption_grace_period = 30 + travel_to Time.zone.parse('2026-11-13') + domain = domains(:library) + domain.update_columns(valid_to: Time.zone.parse('2026-11-01')) + domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id) + + call + + domain.reload + assert_equal Time.zone.parse('2026-11-14'), domain.force_delete_start + assert_equal Date.new(2026, 12, 29), domain.force_delete_date + end + def test_removes_deceased_admin_contact_when_organisation_has_another domain = domains(:library) domain_contacts(:library_acme_admin).update_columns(contact_id: @deceased.id)