Remove domain namespace

This commit is contained in:
Alex Sherman 2020-11-11 21:16:27 +05:00
parent bce39e3404
commit e62f0a077a
19 changed files with 143 additions and 157 deletions

View file

@ -1,17 +0,0 @@
class Domain
module ForceDeleteInteraction
class Base < ActiveInteraction::Base
object :domain,
class: Domain,
description: 'Domain to set ForceDelete on'
symbol :type,
default: :fast_track,
description: 'Force delete type, might be :fast_track or :soft'
boolean :notify_by_email,
default: false,
description: 'Do we need to send email notification'
validates :type, inclusion: { in: %i[fast_track soft] }
end
end
end

View file

@ -1,12 +0,0 @@
class Domain
module ForceDeleteInteraction
class CheckDiscarded < Base
def execute
return true unless domain.discarded?
message = 'Force delete procedure cannot be scheduled while a domain is discarded'
errors.add(:domain, message)
end
end
end
end

View file

@ -1,23 +0,0 @@
class Domain
module ForceDeleteInteraction
class NotifyByEmail < Base
def execute
return unless notify_by_email
if type == :fast_track
send_email
domain.update(contact_notification_sent_date: Time.zone.today)
else
domain.update(template_name: domain.notification_template)
end
end
def send_email
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant,
template_name: domain.notification_template).deliver_now
end
end
end
end

View file

@ -1,12 +0,0 @@
class Domain
module ForceDeleteInteraction
class NotifyRegistrar < Base
def execute
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
end
end
end

View file

@ -1,19 +0,0 @@
class Domain
module ForceDeleteInteraction
class PostSetProcess < Base
def execute
statuses = domain.statuses
# Stop all pending actions
statuses.delete(DomainStatus::PENDING_UPDATE)
statuses.delete(DomainStatus::PENDING_TRANSFER)
statuses.delete(DomainStatus::PENDING_RENEW)
statuses.delete(DomainStatus::PENDING_CREATE)
# Allow deletion
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
domain.save(validate: false)
end
end
end
end

View file

@ -1,15 +0,0 @@
class Domain
module ForceDeleteInteraction
class PrepareDomain < Base
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
def execute
domain.statuses_before_force_delete = domain.statuses
domain.statuses |= STATUSES_TO_SET
domain.save(validate: false)
end
end
end
end

View file

@ -1,14 +0,0 @@
class Domain
module ForceDeleteInteraction
class SetForceDelete < Base
def execute
compose(CheckDiscarded, inputs)
compose(PrepareDomain, inputs)
compose(SetStatus, inputs)
compose(PostSetProcess, inputs)
compose(NotifyRegistrar, inputs)
compose(NotifyByEmail, inputs)
end
end
end
end

View file

@ -1,40 +0,0 @@
class Domain
module ForceDeleteInteraction
class SetStatus < Base
def execute
domain.force_delete_type = type
type == :fast_track ? force_delete_fast_track : force_delete_soft
domain.save(validate: false)
end
def force_delete_fast_track
domain.force_delete_date = Time.zone.today +
expire_warning_period_days +
redemption_grace_period_days
domain.force_delete_start = Time.zone.today + 1.day
end
def force_delete_soft
years = (domain.valid_to.to_date - Time.zone.today).to_i / 365
soft_forcedelete_dates(years) if years.positive?
end
private
def soft_forcedelete_dates(years)
domain.force_delete_start = domain.valid_to - years.years
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
def expire_warning_period_days
Setting.expire_warning_period.days
end
end
end
end

View file

@ -0,0 +1,16 @@
module ForceDeleteInteraction
class Base < ActiveInteraction::Base
object :domain,
class: Domain,
description: 'Domain to set ForceDelete on'
symbol :type,
default: :fast_track,
description: 'Force delete type, might be :fast_track or :soft'
boolean :notify_by_email,
default: false,
description: 'Do we need to send email notification'
validates :type, inclusion: { in: %i[fast_track soft] }
end
end

View file

@ -0,0 +1,11 @@
module ForceDeleteInteraction
class CheckDiscarded < Base
def execute
return true unless domain.discarded?
message = 'Force delete procedure cannot be scheduled while a domain is discarded'
errors.add(:domain, message)
end
end
end

View file

@ -0,0 +1,21 @@
module ForceDeleteInteraction
class NotifyByEmail < Base
def execute
return unless notify_by_email
if type == :fast_track
send_email
domain.update(contact_notification_sent_date: Time.zone.today)
else
domain.update(template_name: domain.notification_template)
end
end
def send_email
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant,
template_name: domain.notification_template).deliver_now
end
end
end

View file

@ -0,0 +1,10 @@
module ForceDeleteInteraction
class NotifyRegistrar < Base
def execute
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
end
end

View file

@ -0,0 +1,17 @@
module ForceDeleteInteraction
class PostSetProcess < Base
def execute
statuses = domain.statuses
# Stop all pending actions
statuses.delete(DomainStatus::PENDING_UPDATE)
statuses.delete(DomainStatus::PENDING_TRANSFER)
statuses.delete(DomainStatus::PENDING_RENEW)
statuses.delete(DomainStatus::PENDING_CREATE)
# Allow deletion
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
domain.save(validate: false)
end
end
end

View file

@ -0,0 +1,13 @@
module ForceDeleteInteraction
class PrepareDomain < Base
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
def execute
domain.statuses_before_force_delete = domain.statuses
domain.statuses |= STATUSES_TO_SET
domain.save(validate: false)
end
end
end

View file

@ -0,0 +1,12 @@
module ForceDeleteInteraction
class SetForceDelete < Base
def execute
compose(CheckDiscarded, inputs)
compose(PrepareDomain, inputs)
compose(SetStatus, inputs)
compose(PostSetProcess, inputs)
compose(NotifyRegistrar, inputs)
compose(NotifyByEmail, inputs)
end
end
end

View file

@ -0,0 +1,38 @@
module ForceDeleteInteraction
class SetStatus < Base
def execute
domain.force_delete_type = type
type == :fast_track ? force_delete_fast_track : force_delete_soft
domain.save(validate: false)
end
def force_delete_fast_track
domain.force_delete_date = Time.zone.today +
expire_warning_period_days +
redemption_grace_period_days
domain.force_delete_start = Time.zone.today + 1.day
end
def force_delete_soft
years = (domain.valid_to.to_date - Time.zone.today).to_i / 365
soft_forcedelete_dates(years) if years.positive?
end
private
def soft_forcedelete_dates(years)
domain.force_delete_start = domain.valid_to - years.years
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
def expire_warning_period_days
Setting.expire_warning_period.days
end
end
end

View file

@ -53,9 +53,9 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def schedule_force_delete(type: :fast_track, notify_by_email: false)
Domain::ForceDeleteInteraction::SetForceDelete.run(domain: self,
type: type,
notify_by_email: notify_by_email)
ForceDeleteInteraction::SetForceDelete.run(domain: self,
type: type,
notify_by_email: notify_by_email)
end
def clear_force_delete_data

View file

@ -111,7 +111,7 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
result = Domain::ForceDeleteInteraction::SetForceDelete.run(domain: @domain, type: :fast_track)
result = ForceDeleteInteraction::SetForceDelete.run(domain: @domain, type: :fast_track)
assert_not result.valid?
assert_not @domain.force_delete_scheduled?

View file

@ -414,7 +414,7 @@ class DomainTest < ActiveSupport::TestCase
force_delete_date: nil)
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
Domain::ForceDeleteInteraction::SetForceDelete.run!(domain: @domain, type: :fast_track)
ForceDeleteInteraction::SetForceDelete.run!(domain: @domain, type: :fast_track)
assert(@domain.force_delete_scheduled?)
other_registrant = Registrant.find_by(code: 'jane-001')
@domain.pending_json['new_registrant_id'] = other_registrant.id