mirror of
https://github.com/internetee/registry.git
synced 2025-06-12 07:34:45 +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
2
Gemfile
2
Gemfile
|
@ -2,6 +2,8 @@ source 'https://rubygems.org'
|
||||||
|
|
||||||
# core
|
# core
|
||||||
gem 'bootsnap', '>= 1.1.0', require: false
|
gem 'bootsnap', '>= 1.1.0', require: false
|
||||||
|
gem 'interactor', '~> 3.0'
|
||||||
|
gem 'interactor-rails', '~> 2.0'
|
||||||
gem 'iso8601', '0.12.1' # for dates and times
|
gem 'iso8601', '0.12.1' # for dates and times
|
||||||
gem 'rails', '~> 6.0'
|
gem 'rails', '~> 6.0'
|
||||||
gem 'rest-client'
|
gem 'rest-client'
|
||||||
|
|
|
@ -251,6 +251,10 @@ GEM
|
||||||
i18n (1.8.5)
|
i18n (1.8.5)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
i18n_data (0.10.0)
|
i18n_data (0.10.0)
|
||||||
|
interactor (3.1.2)
|
||||||
|
interactor-rails (2.2.1)
|
||||||
|
interactor (~> 3.0)
|
||||||
|
rails (>= 4.2)
|
||||||
isikukood (0.1.2)
|
isikukood (0.1.2)
|
||||||
iso8601 (0.12.1)
|
iso8601 (0.12.1)
|
||||||
jquery-rails (4.4.0)
|
jquery-rails (4.4.0)
|
||||||
|
@ -544,6 +548,8 @@ DEPENDENCIES
|
||||||
figaro (= 1.1.1)
|
figaro (= 1.1.1)
|
||||||
grape
|
grape
|
||||||
haml (~> 5.0)
|
haml (~> 5.0)
|
||||||
|
interactor (~> 3.0)
|
||||||
|
interactor-rails (~> 2.0)
|
||||||
isikukood
|
isikukood
|
||||||
iso8601 (= 0.12.1)
|
iso8601 (= 0.12.1)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
|
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,
|
:contact_notification_sent_date,
|
||||||
:template_name
|
:template_name
|
||||||
|
|
||||||
|
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
|
||||||
|
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||||
|
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
|
||||||
|
|
||||||
scope :notification_not_sent,
|
scope :notification_not_sent,
|
||||||
lambda {
|
lambda {
|
||||||
where("(force_delete_data->>'contact_notification_sent_date') is null")
|
where("(force_delete_data->>'contact_notification_sent_date') is null")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue