mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 22:24:47 +02:00
Move interactor to namespace
This commit is contained in:
parent
a40116e05e
commit
8ff8aa78c8
8 changed files with 102 additions and 96 deletions
|
@ -1,8 +0,0 @@
|
|||
module ClientHoldInteraction
|
||||
class Base < ActiveInteraction::Base
|
||||
def to_stdout(message)
|
||||
time = Time.zone.now.utc
|
||||
STDOUT << "#{time} - #{message}\n" unless Rails.env.test?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,67 +0,0 @@
|
|||
module ClientHoldInteraction
|
||||
class ProcessClientHold < Base
|
||||
object :domain,
|
||||
class: Domain,
|
||||
description: 'Domain to set ClientHold on'
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def execute
|
||||
notify_on_grace_period if should_notify_on_soft_force_delete?
|
||||
|
||||
return unless client_holdable?
|
||||
|
||||
domain.statuses << DomainStatus::CLIENT_HOLD
|
||||
to_stdout("DomainCron.start_client_hold: #{domain.id} (#{domain.name}) #{domain.changes}\n")
|
||||
|
||||
domain.save(validate: false)
|
||||
notify_client_hold
|
||||
|
||||
to_stdout("Successfully set client_hold on (#{domain.name})")
|
||||
end
|
||||
|
||||
def notify_on_grace_period
|
||||
domain.registrar.notifications.create!(text: I18n.t('grace_period_started_domain',
|
||||
domain_name: domain.name,
|
||||
date: domain.force_delete_start))
|
||||
send_mail if domain.template_name.present?
|
||||
domain.update(contact_notification_sent_date: Time.zone.today)
|
||||
end
|
||||
|
||||
def notify_client_hold
|
||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date))
|
||||
end
|
||||
|
||||
def send_mail
|
||||
DomainDeleteMailer.forced(domain: domain,
|
||||
registrar: domain.registrar,
|
||||
registrant: domain.registrant,
|
||||
template_name: domain.template_name).deliver_now
|
||||
end
|
||||
|
||||
def should_notify_on_soft_force_delete?
|
||||
domain.force_delete_scheduled? && domain.contact_notification_sent_date.blank? &&
|
||||
domain.force_delete_start.to_date <= Time.zone.now.to_date &&
|
||||
domain.force_delete_type.to_sym == :soft &&
|
||||
!domain.statuses.include?(DomainStatus::CLIENT_HOLD)
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def client_holdable?
|
||||
domain.force_delete_scheduled? &&
|
||||
!domain.statuses.include?(DomainStatus::CLIENT_HOLD) &&
|
||||
domain.force_delete_start.present? &&
|
||||
force_delete_lte_today && force_delete_lte_valid_date
|
||||
end
|
||||
|
||||
def force_delete_lte_today
|
||||
domain.force_delete_start + Setting.expire_warning_period.days <= Time.zone.now
|
||||
end
|
||||
|
||||
def force_delete_lte_valid_date
|
||||
domain.force_delete_start + Setting.expire_warning_period.days <= domain.valid_to
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +0,0 @@
|
|||
module ClientHoldInteraction
|
||||
class SetClientHold < Base
|
||||
def execute
|
||||
to_stdout('Setting client_hold to domains\n')
|
||||
|
||||
::PaperTrail.request.whodunnit = "cron - #{self.class.name}"
|
||||
|
||||
::Domain.force_delete_scheduled.each do |domain|
|
||||
ClientHoldInteraction::ProcessClientHold.run(domain: domain)
|
||||
end
|
||||
|
||||
to_stdout('All client_hold setting are done\n')
|
||||
end
|
||||
end
|
||||
end
|
10
app/interactions/domains/client_hold/base.rb
Normal file
10
app/interactions/domains/client_hold/base.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Domains
|
||||
module ClientHold
|
||||
class Base < ActiveInteraction::Base
|
||||
def to_stdout(message)
|
||||
time = Time.zone.now.utc
|
||||
STDOUT << "#{time} - #{message}\n" unless Rails.env.test?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
69
app/interactions/domains/client_hold/process_client_hold.rb
Normal file
69
app/interactions/domains/client_hold/process_client_hold.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
module Domains
|
||||
module ClientHold
|
||||
class ProcessClientHold < Base
|
||||
object :domain,
|
||||
class: Domain,
|
||||
description: 'Domain to set ClientHold on'
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def execute
|
||||
notify_on_grace_period if should_notify_on_soft_force_delete?
|
||||
|
||||
return unless client_holdable?
|
||||
|
||||
domain.statuses << DomainStatus::CLIENT_HOLD
|
||||
to_stdout("DomainCron.start_client_hold: #{domain.id} (#{domain.name}) #{domain.changes}\n")
|
||||
|
||||
domain.save(validate: false)
|
||||
notify_client_hold
|
||||
|
||||
to_stdout("Successfully set client_hold on (#{domain.name})")
|
||||
end
|
||||
|
||||
def notify_on_grace_period
|
||||
domain.registrar.notifications.create!(text: I18n.t('grace_period_started_domain',
|
||||
domain_name: domain.name,
|
||||
date: domain.force_delete_start))
|
||||
send_mail if domain.template_name.present?
|
||||
domain.update(contact_notification_sent_date: Time.zone.today)
|
||||
end
|
||||
|
||||
def notify_client_hold
|
||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||
domain_name: domain.name,
|
||||
outzone_date: domain.outzone_date,
|
||||
purge_date: domain.purge_date))
|
||||
end
|
||||
|
||||
def send_mail
|
||||
DomainDeleteMailer.forced(domain: domain,
|
||||
registrar: domain.registrar,
|
||||
registrant: domain.registrant,
|
||||
template_name: domain.template_name).deliver_now
|
||||
end
|
||||
|
||||
def should_notify_on_soft_force_delete?
|
||||
domain.force_delete_scheduled? && domain.contact_notification_sent_date.blank? &&
|
||||
domain.force_delete_start.to_date <= Time.zone.now.to_date &&
|
||||
domain.force_delete_type.to_sym == :soft &&
|
||||
!domain.statuses.include?(DomainStatus::CLIENT_HOLD)
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def client_holdable?
|
||||
domain.force_delete_scheduled? &&
|
||||
!domain.statuses.include?(DomainStatus::CLIENT_HOLD) &&
|
||||
domain.force_delete_start.present? &&
|
||||
force_delete_lte_today && force_delete_lte_valid_date
|
||||
end
|
||||
|
||||
def force_delete_lte_today
|
||||
domain.force_delete_start + Setting.expire_warning_period.days <= Time.zone.now
|
||||
end
|
||||
|
||||
def force_delete_lte_valid_date
|
||||
domain.force_delete_start + Setting.expire_warning_period.days <= domain.valid_to
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
17
app/interactions/domains/client_hold/set_client_hold.rb
Normal file
17
app/interactions/domains/client_hold/set_client_hold.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Domains
|
||||
module ClientHold
|
||||
class SetClientHold < Base
|
||||
def execute
|
||||
to_stdout('Setting client_hold to domains\n')
|
||||
|
||||
::PaperTrail.request.whodunnit = "cron - #{self.class.name}"
|
||||
|
||||
::Domain.force_delete_scheduled.each do |domain|
|
||||
Domains::ClientHold::ProcessClientHold.run(domain: domain)
|
||||
end
|
||||
|
||||
to_stdout('All client_hold setting are done\n')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -79,6 +79,6 @@ class DomainCron
|
|||
end
|
||||
|
||||
def self.start_client_hold
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -206,7 +206,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
@domain.schedule_force_delete(type: :soft)
|
||||
|
||||
travel_to Time.zone.parse('2010-08-21')
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
@domain.reload
|
||||
|
||||
assert_emails 1
|
||||
|
@ -227,7 +227,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
@domain.schedule_force_delete(type: :soft)
|
||||
|
||||
travel_to Time.zone.parse('2010-08-21')
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
@domain.reload
|
||||
|
||||
assert_emails 1
|
||||
|
@ -244,7 +244,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
@domain.schedule_force_delete(type: :soft)
|
||||
|
||||
travel_to Time.zone.parse('2010-07-06')
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
@domain.reload
|
||||
|
||||
assert_not_includes(@domain.statuses, asserted_status)
|
||||
|
@ -259,7 +259,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
|
||||
@domain.schedule_force_delete(type: :fast_track)
|
||||
travel_to Time.zone.parse('2010-07-25')
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
@domain.reload
|
||||
|
||||
assert_includes(@domain.statuses, asserted_status)
|
||||
|
@ -275,7 +275,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
|
||||
@domain.schedule_force_delete(type: :fast_track)
|
||||
travel_to Time.zone.parse('2010-07-06')
|
||||
ClientHoldInteraction::SetClientHold.run!
|
||||
Domains::ClientHold::SetClientHold.run!
|
||||
@domain.reload
|
||||
|
||||
assert_not_includes(@domain.statuses, asserted_status)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue