mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 03:30:33 +02:00
Add basic interactor/organizer support
This commit is contained in:
parent
0570e4352f
commit
4b980a07f5
8 changed files with 113 additions and 0 deletions
16
app/interactors/domain/force_delete/base.rb
Normal file
16
app/interactors/domain/force_delete/base.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class Domain
|
||||
module ForceDelete
|
||||
class Base
|
||||
include Interactor::Organizer
|
||||
|
||||
# As per https://github.com/collectiveidea/interactor#organizers
|
||||
|
||||
organize Domain::ForceDelete::CheckDiscarded,
|
||||
Domain::ForceDelete::PrepareDomain,
|
||||
Domain::ForceDelete::SetStatus,
|
||||
Domain::ForceDelete::PostSetProcess,
|
||||
Domain::ForceDelete::NotifyRegistrar,
|
||||
Domain::ForceDelete::NotifyByEmail
|
||||
end
|
||||
end
|
||||
end
|
14
app/interactors/domain/force_delete/check_discarded.rb
Normal file
14
app/interactors/domain/force_delete/check_discarded.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class Domain
|
||||
module ForceDelete
|
||||
class CheckDiscarded
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
return unless context.domain.discarded?
|
||||
|
||||
raise StandardError,
|
||||
'Force delete procedure cannot be scheduled while a domain is discarded'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
21
app/interactors/domain/force_delete/post_set_process.rb
Normal file
21
app/interactors/domain/force_delete/post_set_process.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Domain
|
||||
module ForceDelete
|
||||
class PostSetProcess
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
statuses = context.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)
|
||||
context.domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
app/interactors/domain/force_delete/prepare_domain.rb
Normal file
14
app/interactors/domain/force_delete/prepare_domain.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class Domain
|
||||
module ForceDelete
|
||||
class PrepareDomain
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
domain = context.domain
|
||||
domain.statuses_before_force_delete = domain.statuses
|
||||
domain.statuses |= domain.class.STATUSES_TO_SET
|
||||
domain.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
app/interactors/domain/force_delete/set_status.rb
Normal file
36
app/interactors/domain/force_delete/set_status.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
class Domain
|
||||
module ForceDelete
|
||||
class SetStatus
|
||||
include Interactor
|
||||
|
||||
def call
|
||||
domain.force_delete_type = context.type
|
||||
context.type == :fast_track ? force_delete_fast_track : force_delete_soft
|
||||
domain.save(validate: false)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain
|
||||
@domain |= context.domain
|
||||
end
|
||||
|
||||
def force_delete_fast_track
|
||||
domain.force_delete_date = force_delete_fast_track_start_date + 1.day
|
||||
domain.force_delete_start = Time.zone.today + 1.day
|
||||
end
|
||||
|
||||
def force_delete_soft
|
||||
years = (valid_to.to_date - Time.zone.today).to_i / 365
|
||||
soft_forcedelete_dates(years)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,6 +7,10 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
|||
:contact_notification_sent_date,
|
||||
:template_name
|
||||
|
||||
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
|
||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
|
||||
|
||||
scope :notification_not_sent,
|
||||
lambda {
|
||||
where("(force_delete_data->>'contact_notification_sent_date') is null")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue