mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 13:36:15 +02:00
Add validation event check force delete to a job
This commit is contained in:
parent
1ee0b85f28
commit
626edbd4c3
3 changed files with 106 additions and 100 deletions
13
app/jobs/validation_event_check_force_delete_job.rb
Normal file
13
app/jobs/validation_event_check_force_delete_job.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
class ValidationEventCheckForceDeleteJob < ApplicationJob
|
||||||
|
def perform(event_id, contact_id)
|
||||||
|
event = ValidationEvent.find(event_id)
|
||||||
|
contact = Contact.find(contact_id)
|
||||||
|
|
||||||
|
if contact.need_to_start_force_delete?
|
||||||
|
event.start_force_delete
|
||||||
|
elsif contact.need_to_lift_force_delete?
|
||||||
|
event.refresh_status_notes
|
||||||
|
event.lift_force_delete
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -35,7 +35,7 @@ class ValidationEvent < ApplicationRecord
|
||||||
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
|
scope :smtp, -> { where('event_data @> ?', { 'check_level': 'smtp' }.to_json) }
|
||||||
scope :by_object, ->(object) { where(validation_eventable: object) }
|
scope :by_object, ->(object) { where(validation_eventable: object) }
|
||||||
|
|
||||||
# after_create :check_for_force_delete
|
after_create :check_for_force_delete
|
||||||
|
|
||||||
def self.validated_ids_by(klass)
|
def self.validated_ids_by(klass)
|
||||||
recent.successful.where('validation_eventable_type = ?', klass)
|
recent.successful.where('validation_eventable_type = ?', klass)
|
||||||
|
@ -59,12 +59,7 @@ class ValidationEvent < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_force_delete
|
def check_for_force_delete
|
||||||
if object.need_to_start_force_delete?
|
ValidationEventCheckForceDeleteJob.perform_later(id, object.id)
|
||||||
start_force_delete
|
|
||||||
elsif object.need_to_lift_force_delete?
|
|
||||||
refresh_status_notes
|
|
||||||
lift_force_delete
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_force_delete
|
def start_force_delete
|
||||||
|
@ -99,14 +94,12 @@ class ValidationEvent < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def lift_force_delete
|
def lift_force_delete
|
||||||
# domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
||||||
# registrant_ids = Registrant.where(email: email).pluck(:id)
|
registrant_domains = Domain.where(registrant_id: Registrant.where(email: email).pluck(:id))
|
||||||
#
|
domains = domain_contacts.map(&:domain).flatten + registrant_domains
|
||||||
# domains = domain_contacts.map(&:domain).flatten +
|
|
||||||
# Domain.where(registrant_id: registrant_ids)
|
domains.each do |domain|
|
||||||
#
|
Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||||
# domains.each do |domain|
|
end
|
||||||
# Domains::ForceDeleteLift::Base.run(domain: domain)
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -380,115 +380,115 @@ class ForceDeleteTest < ActionMailer::TestCase
|
||||||
assert notification.text.include? asserted_text
|
assert notification.text.include? asserted_text
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_schedules_force_delete_invalid_contact
|
def test_schedules_force_delete_invalid_contact
|
||||||
# @domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||||
# assert_not @domain.force_delete_scheduled?
|
assert_not @domain.force_delete_scheduled?
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email = '`@internet.ee'
|
email = '`@internet.ee'
|
||||||
# asserted_text = "Invalid email: #{email}"
|
asserted_text = "Invalid email: #{email}"
|
||||||
|
|
||||||
# Truemail.configure.default_validation_type = :regex
|
Truemail.configure.default_validation_type = :regex
|
||||||
|
|
||||||
# contact = @domain.admin_contacts.first
|
contact = @domain.admin_contacts.first
|
||||||
# contact.update_attribute(:email, email)
|
contact.update_attribute(:email, email)
|
||||||
|
|
||||||
# ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
||||||
# contact.verify_email
|
contact.verify_email
|
||||||
# end
|
end
|
||||||
|
|
||||||
# @domain.reload
|
@domain.reload
|
||||||
|
|
||||||
# assert @domain.force_delete_scheduled?
|
assert @domain.force_delete_scheduled?
|
||||||
# assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
||||||
# assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
||||||
# assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email
|
assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email
|
||||||
# notification = @domain.registrar.notifications.last
|
notification = @domain.registrar.notifications.last
|
||||||
# assert notification.text.include? asserted_text
|
assert notification.text.include? asserted_text
|
||||||
# end
|
end
|
||||||
|
|
||||||
# def test_add_invalid_email_to_domain_status_notes
|
def test_add_invalid_email_to_domain_status_notes
|
||||||
# domain = domains(:airport)
|
domain = domains(:airport)
|
||||||
# domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
||||||
# statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
||||||
# force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
||||||
# status_notes: { "serverForceDelete": '`@internet2.ee' })
|
status_notes: { "serverForceDelete": '`@internet2.ee' })
|
||||||
|
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email = '`@internet.ee'
|
email = '`@internet.ee'
|
||||||
# invalid_emails = '`@internet2.ee `@internet.ee'
|
invalid_emails = '`@internet2.ee `@internet.ee'
|
||||||
# asserted_text = "Invalid email: #{invalid_emails}"
|
asserted_text = "Invalid email: #{invalid_emails}"
|
||||||
|
|
||||||
# Truemail.configure.default_validation_type = :regex
|
Truemail.configure.default_validation_type = :regex
|
||||||
|
|
||||||
# contact_first = domain.admin_contacts.first
|
contact_first = domain.admin_contacts.first
|
||||||
# contact_first.update_attribute(:email_history, 'john@inbox.test')
|
contact_first.update_attribute(:email_history, 'john@inbox.test')
|
||||||
# contact_first.update_attribute(:email, email)
|
contact_first.update_attribute(:email, email)
|
||||||
|
|
||||||
# ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
||||||
# contact_first.verify_email
|
contact_first.verify_email
|
||||||
# end
|
end
|
||||||
|
|
||||||
# domain.reload
|
domain.reload
|
||||||
|
|
||||||
# assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
|
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
|
||||||
# notification = domain.registrar.notifications.last
|
notification = domain.registrar.notifications.last
|
||||||
# assert_not notification.text.include? asserted_text
|
assert_not notification.text.include? asserted_text
|
||||||
# end
|
end
|
||||||
|
|
||||||
# def test_remove_invalid_email_from_domain_status_notes
|
def test_remove_invalid_email_from_domain_status_notes
|
||||||
# domain = domains(:airport)
|
domain = domains(:airport)
|
||||||
# domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
||||||
# statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
||||||
# force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
||||||
# status_notes: { "serverForceDelete": '`@internet2.ee `@internet.ee' })
|
status_notes: { "serverForceDelete": '`@internet2.ee `@internet.ee' })
|
||||||
|
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email = '`@internet2.ee'
|
email = '`@internet2.ee'
|
||||||
# invalid_email = '`@internet.ee'
|
invalid_email = '`@internet.ee'
|
||||||
# asserted_text = "Invalid email: #{invalid_email}"
|
asserted_text = "Invalid email: #{invalid_email}"
|
||||||
|
|
||||||
# Truemail.configure.default_validation_type = :regex
|
Truemail.configure.default_validation_type = :regex
|
||||||
|
|
||||||
# contact_first = domain.admin_contacts.first
|
contact_first = domain.admin_contacts.first
|
||||||
# contact_first.update_attribute(:email_history, email)
|
contact_first.update_attribute(:email_history, email)
|
||||||
# contact_first.update_attribute(:email, 'john@inbox.test')
|
contact_first.update_attribute(:email, 'john@inbox.test')
|
||||||
|
|
||||||
# travel_to Time.zone.parse('2010-07-05 0:00:03')
|
travel_to Time.zone.parse('2010-07-05 0:00:03')
|
||||||
# contact_first.verify_email
|
contact_first.verify_email
|
||||||
# domain.reload
|
domain.reload
|
||||||
|
|
||||||
# assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
|
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
|
||||||
# notification = domain.registrar.notifications.last
|
notification = domain.registrar.notifications.last
|
||||||
# assert notification.text.include? asserted_text
|
assert notification.text.include? asserted_text
|
||||||
# end
|
end
|
||||||
|
|
||||||
# def test_domain_should_have_several_bounced_emails
|
def test_domain_should_have_several_bounced_emails
|
||||||
# @domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||||
# assert_not @domain.force_delete_scheduled?
|
assert_not @domain.force_delete_scheduled?
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email_one = '`@internet.ee'
|
email_one = '`@internet.ee'
|
||||||
# email_two = '@@internet.ee'
|
email_two = '@@internet.ee'
|
||||||
|
|
||||||
# contact_one = @domain.admin_contacts.first
|
contact_one = @domain.admin_contacts.first
|
||||||
# contact_one.update_attribute(:email, email_one)
|
contact_one.update_attribute(:email, email_one)
|
||||||
# contact_one.verify_email
|
contact_one.verify_email
|
||||||
|
|
||||||
# assert contact_one.need_to_start_force_delete?
|
assert contact_one.need_to_start_force_delete?
|
||||||
|
|
||||||
# contact_two = @domain.admin_contacts.first
|
contact_two = @domain.admin_contacts.first
|
||||||
# contact_two.update_attribute(:email, email_two)
|
contact_two.update_attribute(:email, email_two)
|
||||||
# contact_two.verify_email
|
contact_two.verify_email
|
||||||
|
|
||||||
# assert contact_two.need_to_start_force_delete?
|
assert contact_two.need_to_start_force_delete?
|
||||||
|
|
||||||
# @domain.reload
|
@domain.reload
|
||||||
|
|
||||||
# assert @domain.force_delete_scheduled?
|
assert @domain.force_delete_scheduled?
|
||||||
# assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
||||||
# assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
||||||
# assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one
|
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one
|
||||||
# assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two
|
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two
|
||||||
# end
|
end
|
||||||
|
|
||||||
def test_lifts_force_delete_after_bounce_changes
|
def test_lifts_force_delete_after_bounce_changes
|
||||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue