Skip to content

Commit

Permalink
refactoring, add mail templates
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Jul 11, 2023
1 parent 791aaa0 commit b393eda
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion app/interactions/actions/contact_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def maybe_company_is_relevant
return true unless contact.org?

company_status = contact.return_company_status
return if company_status == Contact::REGISTERED || company_status == Contact::LIQUIDATED
return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status

contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))
@error = true
Expand Down
48 changes: 27 additions & 21 deletions app/jobs/company_register_status_job.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
class CompanyRegisterStatusJob < ApplicationJob
queue_as :default

def perform(days_interval = 14, spam_time_delay=0.3)
registrants = Registrant.where(ident_type: 'org')
.where(
'(company_register_status IS NULL) OR
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?)) OR
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?))',
Contact::REGISTERED, days_interval.days.ago,
Contact::LIQUIDATED, 1.day.ago
)

registrants.find_in_batches(batch_size: 100) do |contacts|

def perform(days_interval = 14, spam_time_delay = 0.2, batch_size = 100)
sampling_registrant_contact(days_interval).find_in_batches(batch_size: batch_size) do |contacts|
contacts.each do |contact|

# avoid spamming company register
sleep spam_time_delay

company_status = contact.return_company_status
contact.company_register_status = company_status
contact.checked_company_at = Time.zone.now
contact.save!
contact.update!(company_register_status: company_status, checked_company_at: Time.zone.now)

next unless [Contact::BANKRUPT, Contact::DELETED].include? company_status

next unless company_status == Contact::BANKRUPT || company_status == Contact::DELETED

contact.domains.each do |domain|
domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: 'invalid_company', email: contact.email)
end
schedule_force_delete(contact)
end
end
end

private

def sampling_registrant_contact(days_interval)
Registrant.where(ident_type: 'org')
.where('(company_register_status IS NULL) OR
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?)) OR
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?))',
Contact::REGISTERED, days_interval.days.ago, Contact::LIQUIDATED, 1.day.ago)
end

def schedule_force_delete(contact)
contact.domains.each do |domain|
domain.schedule_force_delete(
type: :fast_track,
notify_by_email: true,
reason: 'invalid_company',
email: contact.email
)
end
end
end
12 changes: 6 additions & 6 deletions app/models/contact/company_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ module Contact::CompanyRegister
'l' => 'liquidated',
'n' => 'bankrupt',
'k' => 'deleted',
}.freeze
}.freeze

REGISTERED = 'registered'
LIQUIDATED = 'liquidated'
BANKRUPT = 'bankrupt'
DELETED = 'deleted'
REGISTERED = 'registered'.freeze
LIQUIDATED = 'liquidated'.freeze
BANKRUPT = 'bankrupt'.freeze
DELETED = 'deleted'.freeze

def company_is_relevant?
company_register_status == REGISTERED && company_register_status == LIQUIDATED
end

def return_company_status
return unless return_company_data.present?
return if return_company_data.blank?

status = return_company_data.first[:status].downcase
COMPANY_STATUSES[status]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<p>Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt</p>

<h1>THIS TEMPLATE FOR INVALID PHONE, BUT NEED TO CHANGE TEMAPLTE TO INVALID COMPANY!!!</h1>
<p>Eesti Interneti Sihtasutusele on saanud teatavaks, et juriidiline isik registrikoodiga <%= @domain.registrant.ident %> on äriregistrist kustutatud.</p>

<p>Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et domeeni <%= @domain.name %> kontakti(de) telefoni number või numbrid on puudulikud.</p>
<p>Kuna äriregistrist kustutatud juriidiline isik ei saa olla domeeni registreerijaks, algas domeeni <%= @domain.name %> suhtes 45 päevane kustutusmenetlus. Menetluse käigus on domeen 15 esimest päeva internetis kättesaadav.</p>

<p>Et see olukord on vastuolus .ee <a href='https://www.internet.ee/domains/ee-domain-regulation'>domeenireeglitega</a> algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.</p>

<p>Andmete parandamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole või isiklike ja oma ettevõtte andmete puhul <a href="https://registrant.internet.ee/">registreerija portaali</a>.</p>
<p>Domeeni suhtes õigust omaval isikul on võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus koos seda tõendava dokumendiga.</p>

<p>Kui kontaktandmed ei ole <%= @delete_period_length %> päeva jooksul parandatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile <a href="https://auction.internet.ee">.ee oksjonikeskkonda</a>. 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 <a href="https://www.internet.ee/domeenid/domeenide-oksjonikeskkonna-kasutajatingimused#3-oksjonikeskkonna-enampakkumisel-osalemise-tingimused">siit</a>.</p>

Expand All @@ -19,11 +17,11 @@

<p>Dear registrant/administrative contact of .ee domain,</p>

<p>Estonian Internet Foundation has learned that contact(s) phone number data of the domain <%= @domain.name %> are invalid.</p>
<p>Estonian Internet Foundation has learned that the legal person with registry code <%= @domain.registrant.ident %> has been deleted from the Business Registry.</p>

<p>Since this is a violation of <a href='https://www.internet.ee/domains/ee-domain-regulation'>Estonian domain regulations</a>, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.</p>
<p>As a terminated legal person cannot be the registrant of a domain, a 45-day deletion process has started for the <%= @domain.name %> domain. For the first 15 days the domain will remain available on the Internet during the deletion process.</p>

<p>Please, contact your registrar <%= @registrar.name %> with updated contact data, or in case of your personal or business data use <a href="https://registrant.internet.ee/">.ee portal for registrants</a></p>
<p>The registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> with legal documentation.</p>

<p>If the data is not fixed within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the <a href="https://auction.internet.ee">.ee auction environment</a>. 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 <a href="https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment">here</a>.</p>

Expand All @@ -35,11 +33,11 @@

<p>Уважаемый регистрант/административный контакт домена .ee</p>

<p>Целевому учреждению Eesti Internet (EIS) стало известно, что контактные данные домена <%= @domain.name %> неверны - телефонные номера.</p>
<p>Целевому учреждению Eesti Internet (EIS) стало известно, что юридическое лицо с регистрационным кодом <%= @domain.registrant.ident %> удалено из коммерческого реестра.</p>

<p>Так как это является нарушением <a href='https://www.internet.ee/domains/ee-domain-regulation'>Правил домена .ee</a>, <%= @delete_period_length %>-дневный процесс удаления начат для доменного имени <%= @domain.name %>. В течение первых <%= @expire_warning_period %> дней домен будет доступен в интернете.</p>
<p>Поскольку удаленное из коммерческого регистра юридическое лицо не может являться регистрантом домена, <%= Date.today.strftime('%d.%m.%y') %> начат 45-дневный процесс удаления домена <%= @domain.name %>. Домен доступен в интернете на протяжении 15 дней после начала процесса удаления.</p>

<p>Для уточнения контактных данных, пожалуйста, свяжитесь с регистратором <%= @registrar.name %>, либо воспользуйтесь <a href="https://registrant.internet.ee/">порталом для регистрантов</a></p>
<p>Лицо, обладающее правом на домен, может подать регистратору <%= @registrar.name %> домена <%= @domain.name %> ходатайство о передаче домена, представив вместе с ходатайством подтверждающие документы. Документы должны быть представлены регистратору в течение 45 дней.</p>

<p>Если контактные данные не будут исправлены в течение <%= @delete_period_length %> дней, домен <%= @domain.name %> отправится <%= @domain.force_delete_date %> на доменный аукцион в <a href="https://auction.internet.ee">аукционной среде.ee</a>. Если в течение 24 часов в отношении домена <%= @domain.name %> е поступит предложений, домен освободится и станет доступным для всех желающих по принципу «кто раньше». О других возможных результатах аукциона читайте <a href="https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment">здесь</a>.</p>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<p>Lugupeetud domeeni <%= @domain.name %> registreerija/halduskontakt</p>

<h1>THIS TEMPLATE FOR INVALID PHONE, BUT NEED TO CHANGE TEMAPLTE TO INVALID COMPANY!!!</h1>
<p>Eesti Interneti Sihtasutusele on saanud teatavaks, et juriidiline isik registrikoodiga <%= @domain.registrant.ident %> on äriregistrist kustutatud.</p>

<p>Eesti Interneti Sihtasutusele (EIS) on saanud teatavaks, et domeeni <%= @domain.name %> kontakti(de) telefoni number või numbrid on puudulikud.</p>
<p>Kuna äriregistrist kustutatud juriidiline isik ei saa olla domeeni registreerijaks, algas domeeni <%= @domain.name %> suhtes 45 päevane kustutusmenetlus. Menetluse käigus on domeen 15 esimest päeva internetis kättesaadav.</p>

<p>Et see olukord on vastuolus .ee <a href='https://www.internet.ee/domains/ee-domain-regulation'>domeenireeglitega</a> algatas EIS <%= @delete_period_length %> päeva pikkuse kustutusmenetluse. Menetluse käigus on domeen <%= @expire_warning_period %> esimest päeva internetis kättesaadav.</p>

<p>Andmete parandamiseks pöörduge palun oma registripidaja <%= @registrar.name %> poole või isiklike ja oma ettevõtte andmete puhul <a href="https://registrant.internet.ee/">registreerija portaali</a>.</p>
<p>Domeeni suhtes õigust omaval isikul on võimalus esitada domeeni <%= @domain.name %> registripidajale <%= @registrar.name %> domeeni üleandmise taotlus koos seda tõendava dokumendiga.</p>

<p>Kui kontaktandmed ei ole <%= @delete_period_length %> päeva jooksul parandatud, läheb domeen <%= @domain.name %> <%= @domain.force_delete_date %> domeenioksjonile <a href="https://auction.internet.ee">.ee oksjonikeskkonda</a>. 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 <a href="https://www.internet.ee/domeenid/domeenide-oksjonikeskkonna-kasutajatingimused#3-oksjonikeskkonna-enampakkumisel-osalemise-tingimused">siit</a>.</p>

Expand All @@ -20,10 +18,11 @@
<p>Dear registrant/administrative contact of .ee domain,</p>

<p>Estonian Internet Foundation has learned that contact(s) phone number data of the domain <%= @domain.name %> are invalid.</p>
<p>Estonian Internet Foundation has learned that the legal person with registry code <%= @domain.registrant.ident %> has been deleted from the Business Registry.</p>

<p>Since this is a violation of <a href='https://www.internet.ee/domains/ee-domain-regulation'>Estonian domain regulations</a>, <%= @delete_period_length %>-day deletion process has started for the <%= @domain.name %> domain. For the first <%= @expire_warning_period %> days the domain will remain available on the Internet during the deletion process.</p>
<p>As a terminated legal person cannot be the registrant of a domain, a 45-day deletion process has started for the <%= @domain.name %> domain. For the first 15 days the domain will remain available on the Internet during the deletion process.</p>

<p>Please, contact your registrar <%= @registrar.name %> with updated contact data, or in case of your personal or business data use <a href="https://registrant.internet.ee/">.ee portal for registrants</a></p>
<p>The registrant holding a right to the domain name <%= @domain.name %> can submit a domain name transfer application to the registrar <%= @registrar.name %> with legal documentation.</p>

<p>If the data is not fixed within <%= @delete_period_length %> days, the domain <%= @domain.name %> will go to domain auction on <%= @domain.force_delete_date %> in the <a href="https://auction.internet.ee">.ee auction environment</a>. 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 <a href="https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment">here</a>.</p>

Expand All @@ -35,11 +34,11 @@

<p>Уважаемый регистрант/административный контакт домена .ee</p>

<p>Целевому учреждению Eesti Internet (EIS) стало известно, что контактные данные домена <%= @domain.name %> неверны - телефонные номера.</p>
<p>Целевому учреждению Eesti Internet (EIS) стало известно, что юридическое лицо с регистрационным кодом <%= @domain.registrant.ident %> удалено из коммерческого реестра.</p>

<p>Так как это является нарушением <a href='https://www.internet.ee/domains/ee-domain-regulation'>Правил домена .ee</a>, <%= @delete_period_length %>-дневный процесс удаления начат для доменного имени <%= @domain.name %>. В течение первых <%= @expire_warning_period %> дней домен будет доступен в интернете.</p>
<p>Поскольку удаленное из коммерческого регистра юридическое лицо не может являться регистрантом домена, <%= Date.today.strftime('%d.%m.%y') %> начат 45-дневный процесс удаления домена <%= @domain.name %>. Домен доступен в интернете на протяжении 15 дней после начала процесса удаления.</p>

<p>Для уточнения контактных данных, пожалуйста, свяжитесь с регистратором <%= @registrar.name %>, либо воспользуйтесь <a href="https://registrant.internet.ee/">порталом для регистрантов</a></p>
<p>Лицо, обладающее правом на домен, может подать регистратору <%= @registrar.name %> домена <%= @domain.name %> ходатайство о передаче домена, представив вместе с ходатайством подтверждающие документы. Документы должны быть представлены регистратору в течение 45 дней.</p>

<p>Если контактные данные не будут исправлены в течение <%= @delete_period_length %> дней, домен <%= @domain.name %> отправится <%= @domain.force_delete_date %> на доменный аукцион в <a href="https://auction.internet.ee">аукционной среде.ee</a>. Если в течение 24 часов в отношении домена <%= @domain.name %> е поступит предложений, домен освободится и станет доступным для всех желающих по принципу «кто раньше». О других возможных результатах аукциона читайте <a href="https://www.internet.ee/domains/auction-environment-user-agreement#3-terms-and-conditions-for-participation-in-the-auction-of-the-auction-environment">здесь</a>.</p>

Expand Down
11 changes: 11 additions & 0 deletions test/models/contact/company_register_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ def setup
end

def test_return_company_status
original_new_method = CompanyRegister::Client.method(:new)
CompanyRegister::Client.define_singleton_method(:new) do
object = original_new_method.call
def object.company_details(registration_number:)
[Company.new('1234567', 'ACME Ltd', 'R')]
end
object
end

assert_equal 'registered', @acme_ltd.return_company_status

CompanyRegister::Client.define_singleton_method(:new, original_new_method)
end

def test_return_company_data
Expand Down

0 comments on commit b393eda

Please sign in to comment.