mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Merge pull request #2723 from internetee/company-validator-during-creation
feat: restore company validation for Estonian organizations
This commit is contained in:
commit
38dc5466e9
23 changed files with 183 additions and 94 deletions
|
@ -14,7 +14,7 @@ module Actions
|
|||
maybe_attach_legal_doc
|
||||
maybe_validate_ident
|
||||
maybe_change_email
|
||||
# maybe_company_is_relevant
|
||||
maybe_company_is_relevant
|
||||
commit
|
||||
maybe_validate_phone_number
|
||||
maybe_validate_contact
|
||||
|
@ -79,16 +79,17 @@ module Actions
|
|||
@error = true
|
||||
end
|
||||
|
||||
# def maybe_company_is_relevant
|
||||
# return true unless contact.org?
|
||||
def maybe_company_is_relevant
|
||||
return true unless contact.org?
|
||||
return true unless contact.ident_country_code == 'EE'
|
||||
|
||||
# company_status = contact.return_company_status
|
||||
company_status = contact.return_company_status
|
||||
|
||||
# return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
|
||||
# contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))
|
||||
return true if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
|
||||
contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))
|
||||
|
||||
# @error = true
|
||||
# end
|
||||
@error = true
|
||||
end
|
||||
|
||||
def maybe_attach_legal_doc
|
||||
::Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false)
|
||||
|
|
|
@ -6,6 +6,7 @@ module Domains
|
|||
domain.force_delete_date = nil
|
||||
domain.force_delete_start = nil
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE] = nil
|
||||
domain.skip_whois_record_update = false
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ module Domains
|
|||
domain.admin_store_statuses_history -= domain_statuses unless domain.admin_store_statuses_history.nil?
|
||||
rejected_statuses = domain.statuses.reject { |a| domain_statuses.include? a }
|
||||
domain.statuses = rejected_statuses
|
||||
domain.skip_whois_record_update = true
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ module Domains
|
|||
|
||||
domain.force_delete_domain_statuses_history = nil
|
||||
domain.admin_store_statuses_history = nil
|
||||
domain.skip_whois_record_update = true
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,9 @@ module Domains
|
|||
string :email,
|
||||
default: nil,
|
||||
description: 'Possible invalid email to notify on'
|
||||
string :notes,
|
||||
default: nil,
|
||||
description: 'Notes to add reason to the force delete'
|
||||
|
||||
validates :type, inclusion: { in: %i[fast_track soft] }
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ module Domains
|
|||
def execute
|
||||
return unless notify_by_email
|
||||
|
||||
domain.skip_whois_record_update = false
|
||||
if type == :fast_track
|
||||
send_email
|
||||
domain.update(contact_notification_sent_date: Time.zone.today)
|
||||
|
|
|
@ -11,7 +11,8 @@ module Domains
|
|||
ident: domain.registrant.ident,
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date)
|
||||
purge_date: domain.purge_date,
|
||||
notes: notes)
|
||||
else
|
||||
I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
|
@ -30,7 +31,8 @@ module Domains
|
|||
ident: domain.registrant.ident,
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date)
|
||||
purge_date: domain.purge_date,
|
||||
notes: notes)
|
||||
else
|
||||
I18n.t('force_delete_auto_email',
|
||||
domain_name: domain.name,
|
||||
|
|
|
@ -11,6 +11,7 @@ module Domains
|
|||
|
||||
# Allow deletion
|
||||
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
|
||||
domain.skip_whois_record_update = notify_by_email ? true : false
|
||||
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ module Domains
|
|||
def execute
|
||||
domain.force_delete_domain_statuses_history = domain.statuses
|
||||
domain.statuses |= STATUSES_TO_SET
|
||||
domain.skip_whois_record_update = true
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ module Domains
|
|||
def execute
|
||||
domain.force_delete_type = type
|
||||
type == :fast_track ? force_delete_fast_track : force_delete_soft
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE] = "Company no: #{domain.registrant.ident}" if reason == 'invalid_company'
|
||||
domain.skip_whois_record_update = true
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
||||
|
@ -12,8 +14,6 @@ module Domains
|
|||
expire_warning_period_days +
|
||||
redemption_grace_period_days
|
||||
domain.force_delete_start = Time.zone.today + 1.day
|
||||
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE] = "Company no: #{domain.registrant.ident}" if reason == 'invalid_company'
|
||||
end
|
||||
|
||||
def force_delete_soft
|
||||
|
|
|
@ -3,6 +3,13 @@ require 'zip'
|
|||
class CompanyRegisterStatusJob < ApplicationJob
|
||||
PAYMENT_STATEMENT_BUSINESS_REGISTRY_REASON = 'Kustutamiskanne dokumentide hoidjata'
|
||||
|
||||
REGISTRY_STATUSES = {
|
||||
Contact::REGISTERED => 'registered',
|
||||
Contact::LIQUIDATED => 'liquidated',
|
||||
Contact::BANKRUPT => 'bankrupt',
|
||||
Contact::DELETED => 'deleted'
|
||||
}
|
||||
|
||||
queue_as :default
|
||||
|
||||
def perform(days_interval = 14, spam_time_delay = 1, batch_size = 100)
|
||||
|
@ -22,43 +29,64 @@ class CompanyRegisterStatusJob < ApplicationJob
|
|||
sleep spam_time_delay
|
||||
|
||||
company_status = contact.return_company_status
|
||||
contact.update!(company_register_status: company_status, checked_company_at: Time.zone.now)
|
||||
|
||||
handle_company_statuses(contact, company_status)
|
||||
status = company_status.blank? ? Contact::DELETED : company_status
|
||||
|
||||
update_validation_company_status(contact:contact , status: status)
|
||||
end
|
||||
|
||||
def handle_company_statuses(contact, company_status)
|
||||
return if company_status == Contact::BANKRUPT
|
||||
|
||||
case company_status
|
||||
when Contact::REGISTERED
|
||||
lift_force_delete(contact) if check_for_force_delete(contact)
|
||||
when Contact::LIQUIDATED
|
||||
ContactInformMailer.company_liquidation(contact: contact).deliver_now
|
||||
send_email_for_liquidation(contact)
|
||||
else
|
||||
delete_process(contact)
|
||||
delete_process(contact, company_status)
|
||||
end
|
||||
end
|
||||
|
||||
status = company_status.blank? ? Contact::DELETED : company_status
|
||||
update_validation_company_status(contact:contact , status: status)
|
||||
def send_email_for_liquidation(contact)
|
||||
return if contact.company_register_status == Contact::LIQUIDATED
|
||||
|
||||
ContactInformMailer.company_liquidation(contact: contact).deliver_now
|
||||
end
|
||||
|
||||
def sampling_registrant_contact(days_interval)
|
||||
Registrant.where(ident_type: 'org', ident_country_code: 'EE').where(
|
||||
"(company_register_status IS NULL OR checked_company_at IS NULL) OR
|
||||
(company_register_status = ? AND checked_company_at < ?) OR
|
||||
company_register_status IN (?)",
|
||||
Contact::REGISTERED, days_interval.days.ago, [Contact::LIQUIDATED, Contact::BANKRUPT, Contact::DELETED]
|
||||
)
|
||||
Contact.joins(:registrant_domains)
|
||||
.where(ident_type: 'org', ident_country_code: 'EE')
|
||||
.where(
|
||||
"(company_register_status IS NULL OR checked_company_at IS NULL) OR
|
||||
(company_register_status = ? AND checked_company_at < ?) OR
|
||||
company_register_status IN (?)",
|
||||
Contact::REGISTERED, days_interval.days.ago, [Contact::LIQUIDATED, Contact::BANKRUPT, Contact::DELETED]
|
||||
)
|
||||
.distinct
|
||||
end
|
||||
|
||||
def update_validation_company_status(contact:, status:)
|
||||
contact.update(company_register_status: status, checked_company_at: Time.zone.now)
|
||||
end
|
||||
|
||||
def schedule_force_delete(contact)
|
||||
def schedule_force_delete(contact, company_status)
|
||||
contact.registrant_domains.each do |domain|
|
||||
next if domain.force_delete_scheduled?
|
||||
|
||||
company_status = if company_status.nil?
|
||||
'Contact not found in EE business registry'
|
||||
else
|
||||
"Contact has status #{REGISTRY_STATUSES[company_status]}"
|
||||
end
|
||||
|
||||
domain.schedule_force_delete(
|
||||
type: :fast_track,
|
||||
notify_by_email: true,
|
||||
reason: 'invalid_company',
|
||||
email: contact.email
|
||||
email: contact.email,
|
||||
notes: company_status
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -66,29 +94,42 @@ class CompanyRegisterStatusJob < ApplicationJob
|
|||
def check_for_force_delete(contact)
|
||||
contact.registrant_domains.any? do |domain|
|
||||
notes = domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
notes && notes.include?("Company no: #{contact.ident}")
|
||||
notes_check = notes && notes.include?("Company no: #{contact.ident}")
|
||||
|
||||
if !notes_check && domain.force_delete_data.present?
|
||||
domain.template_name == 'invalid_company'
|
||||
else
|
||||
notes_check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def lift_force_delete(contact)
|
||||
contact.registrant_domains.each(&:cancel_force_delete)
|
||||
contact.registrant_domains.each do |domain|
|
||||
next unless domain.force_delete_scheduled?
|
||||
|
||||
domain.cancel_force_delete
|
||||
end
|
||||
end
|
||||
|
||||
def delete_process(contact)
|
||||
def delete_process(contact, company_status)
|
||||
Rails.logger.info("Processing company details for contact #{contact.id} with ident: #{contact.ident} (#{contact.ident.class})")
|
||||
company_details_response = contact.return_company_details
|
||||
|
||||
if company_details_response.empty?
|
||||
schedule_force_delete(contact)
|
||||
Rails.logger.info("Empty company details response for contact #{contact.id}")
|
||||
schedule_force_delete(contact, company_status)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
kandeliik_tekstina = extract_kandeliik_tekstina(company_details_response)
|
||||
Rails.logger.info("Kandeliik tekstina for contact #{contact.id}: #{kandeliik_tekstina}")
|
||||
|
||||
if kandeliik_tekstina == PAYMENT_STATEMENT_BUSINESS_REGISTRY_REASON
|
||||
soft_delete_company(contact)
|
||||
soft_delete_company(contact, company_status)
|
||||
else
|
||||
schedule_force_delete(contact)
|
||||
schedule_force_delete(contact, company_status)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,9 +139,18 @@ class CompanyRegisterStatusJob < ApplicationJob
|
|||
company_details_response.first.kandeliik.last.last.kandeliik_tekstina
|
||||
end
|
||||
|
||||
def soft_delete_company(contact)
|
||||
def soft_delete_company(contact, company_status)
|
||||
contact.registrant_domains.reject { |domain| domain.force_delete_scheduled? }.each do |domain|
|
||||
domain.schedule_force_delete(type: :soft)
|
||||
next if domain.force_delete_scheduled?
|
||||
|
||||
company_status = company_status.nil? ? 'No information' : REGISTRY_STATUSES[company_status]
|
||||
|
||||
domain.schedule_force_delete(
|
||||
type: :soft,
|
||||
notify_by_email: true,
|
||||
reason: 'invalid_company',
|
||||
email: contact.email,
|
||||
notes: "Contact has status #{company_status}")
|
||||
end
|
||||
|
||||
puts "Soft delete process initiated for company: #{contact.name} with ID: #{contact.id}"
|
||||
|
|
|
@ -47,9 +47,9 @@ module Domain::ForceDelete
|
|||
statuses.include?(DomainStatus::FORCE_DELETE)
|
||||
end
|
||||
|
||||
def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil, email: nil)
|
||||
def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil, email: nil, notes: nil)
|
||||
Domains::ForceDelete::SetForceDelete.run(domain: self, type: type, reason: reason,
|
||||
notify_by_email: notify_by_email, email: email)
|
||||
notify_by_email: notify_by_email, email: email, notes: notes)
|
||||
end
|
||||
|
||||
def cancel_force_delete
|
||||
|
|
|
@ -87,6 +87,11 @@ class Contact < ApplicationRecord
|
|||
after_save :update_related_whois_records
|
||||
before_validation :clear_address_modifications, if: -> { !self.class.address_processing? }
|
||||
|
||||
# TODO: remove after testing
|
||||
after_save do
|
||||
Rails.logger.info "Contact saved or updated: #{id}"
|
||||
end
|
||||
|
||||
self.ignored_columns = %w[legacy_id legacy_history_id]
|
||||
|
||||
ORG = 'org'.freeze
|
||||
|
|
|
@ -26,8 +26,8 @@ module Contact::CompanyRegister
|
|||
|
||||
def return_company_details
|
||||
return unless org?
|
||||
|
||||
company_register.company_details(registration_number: ident)
|
||||
|
||||
company_register.company_details(registration_number: ident.to_s)
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
[]
|
||||
end
|
||||
|
|
|
@ -89,6 +89,8 @@ class Domain < ApplicationRecord
|
|||
has_many :registrant_verifications, dependent: :destroy
|
||||
has_one :csync_record, dependent: :destroy
|
||||
|
||||
attribute :skip_whois_record_update, :boolean, default: false
|
||||
|
||||
after_initialize do
|
||||
self.pending_json = {} if pending_json.blank?
|
||||
self.statuses = [] if statuses.nil?
|
||||
|
@ -721,6 +723,8 @@ class Domain < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_whois_record
|
||||
return if skip_whois_record_update
|
||||
|
||||
UpdateWhoisRecordJob.set(wait: 1.minute).perform_later name, 'domain'
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue