mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Move interactor from Interactor gem to ActiveInteraction
This commit is contained in:
parent
3c7fa88463
commit
bce39e3404
17 changed files with 70 additions and 65 deletions
3
Gemfile
3
Gemfile
|
@ -1,9 +1,8 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
# core
|
# core
|
||||||
|
gem 'active_interaction', '~> 3.8'
|
||||||
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'
|
||||||
|
|
|
@ -112,6 +112,8 @@ GEM
|
||||||
erubi (~> 1.4)
|
erubi (~> 1.4)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
||||||
|
active_interaction (3.8.3)
|
||||||
|
activemodel (>= 4, < 7)
|
||||||
activejob (6.0.3.3)
|
activejob (6.0.3.3)
|
||||||
activesupport (= 6.0.3.3)
|
activesupport (= 6.0.3.3)
|
||||||
globalid (>= 0.3.6)
|
globalid (>= 0.3.6)
|
||||||
|
@ -251,10 +253,6 @@ 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)
|
||||||
|
@ -525,6 +523,7 @@ PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
active_interaction (~> 3.8)
|
||||||
activerecord-import
|
activerecord-import
|
||||||
airbrake
|
airbrake
|
||||||
bootsnap (>= 1.1.0)
|
bootsnap (>= 1.1.0)
|
||||||
|
@ -548,8 +547,6 @@ 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
|
||||||
|
|
|
@ -4,11 +4,15 @@ module Admin
|
||||||
def create
|
def create
|
||||||
authorize! :manage, domain
|
authorize! :manage, domain
|
||||||
|
|
||||||
|
notice = t('.scheduled')
|
||||||
|
|
||||||
domain.transaction do
|
domain.transaction do
|
||||||
domain.schedule_force_delete(type: force_delete_type, notify_by_email: notify_by_email?)
|
result = domain.schedule_force_delete(type: force_delete_type,
|
||||||
|
notify_by_email: notify_by_email?)
|
||||||
|
notice = result.errors.messages[:domain].first unless result.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to edit_admin_domain_url(domain), notice: t('.scheduled')
|
redirect_to edit_admin_domain_url(domain), notice: notice
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
17
app/interactions/domain/force_delete_interaction/base.rb
Normal file
17
app/interactions/domain/force_delete_interaction/base.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
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
|
|
@ -1,11 +1,11 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class CheckDiscarded < Base
|
class CheckDiscarded < Base
|
||||||
def call
|
def execute
|
||||||
return unless domain.discarded?
|
return true unless domain.discarded?
|
||||||
|
|
||||||
message = 'Force delete procedure cannot be scheduled while a domain is discarded'
|
message = 'Force delete procedure cannot be scheduled while a domain is discarded'
|
||||||
context.fail!(message: message)
|
errors.add(:domain, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,14 +1,14 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class NotifyByEmail < Base
|
class NotifyByEmail < Base
|
||||||
def call
|
def execute
|
||||||
return unless context.notify_by_email
|
return unless notify_by_email
|
||||||
|
|
||||||
if context.type == :fast_track
|
if type == :fast_track
|
||||||
send_email
|
send_email
|
||||||
domain.update(contact_notification_sent_date: Time.zone.today)
|
domain.update(contact_notification_sent_date: Time.zone.today)
|
||||||
else
|
else
|
||||||
domain.update(template_name: context.domain.notification_template)
|
domain.update(template_name: domain.notification_template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class NotifyRegistrar < Base
|
class NotifyRegistrar < Base
|
||||||
def call
|
def execute
|
||||||
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
domain.registrar.notifications.create!(text: I18n.t('force_delete_set_on_domain',
|
||||||
domain_name: domain.name,
|
domain_name: domain.name,
|
||||||
outzone_date: domain.outzone_date,
|
outzone_date: domain.outzone_date,
|
|
@ -1,7 +1,7 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class PostSetProcess < Base
|
class PostSetProcess < Base
|
||||||
def call
|
def execute
|
||||||
statuses = domain.statuses
|
statuses = domain.statuses
|
||||||
# Stop all pending actions
|
# Stop all pending actions
|
||||||
statuses.delete(DomainStatus::PENDING_UPDATE)
|
statuses.delete(DomainStatus::PENDING_UPDATE)
|
|
@ -1,11 +1,11 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class PrepareDomain < Base
|
class PrepareDomain < Base
|
||||||
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
|
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
|
||||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||||
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
|
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
|
||||||
|
|
||||||
def call
|
def execute
|
||||||
domain.statuses_before_force_delete = domain.statuses
|
domain.statuses_before_force_delete = domain.statuses
|
||||||
domain.statuses |= STATUSES_TO_SET
|
domain.statuses |= STATUSES_TO_SET
|
||||||
domain.save(validate: false)
|
domain.save(validate: false)
|
|
@ -0,0 +1,14 @@
|
||||||
|
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
|
|
@ -1,9 +1,9 @@
|
||||||
class Domain
|
class Domain
|
||||||
module ForceDeleteInteractor
|
module ForceDeleteInteraction
|
||||||
class SetStatus < Base
|
class SetStatus < Base
|
||||||
def call
|
def execute
|
||||||
domain.force_delete_type = context.type
|
domain.force_delete_type = type
|
||||||
context.type == :fast_track ? force_delete_fast_track : force_delete_soft
|
type == :fast_track ? force_delete_fast_track : force_delete_soft
|
||||||
domain.save(validate: false)
|
domain.save(validate: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ class Domain
|
||||||
soft_forcedelete_dates(years) if years.positive?
|
soft_forcedelete_dates(years) if years.positive?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def soft_forcedelete_dates(years)
|
def soft_forcedelete_dates(years)
|
||||||
domain.force_delete_start = domain.valid_to - years.years
|
domain.force_delete_start = domain.valid_to - years.years
|
||||||
domain.force_delete_date = domain.force_delete_start +
|
domain.force_delete_date = domain.force_delete_start +
|
||||||
|
@ -26,8 +28,6 @@ class Domain
|
||||||
Setting.redemption_grace_period.days
|
Setting.redemption_grace_period.days
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def redemption_grace_period_days
|
def redemption_grace_period_days
|
||||||
Setting.redemption_grace_period.days + 1.day
|
Setting.redemption_grace_period.days + 1.day
|
||||||
end
|
end
|
|
@ -1,13 +0,0 @@
|
||||||
class Domain
|
|
||||||
module ForceDeleteInteractor
|
|
||||||
class Base
|
|
||||||
include Interactor
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def domain
|
|
||||||
@domain ||= context.domain
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,16 +0,0 @@
|
||||||
class Domain
|
|
||||||
module ForceDeleteInteractor
|
|
||||||
class SetForceDelete
|
|
||||||
include Interactor::Organizer
|
|
||||||
|
|
||||||
# As per https://github.com/collectiveidea/interactor#organizers
|
|
||||||
|
|
||||||
organize Domain::ForceDeleteInteractor::CheckDiscarded,
|
|
||||||
Domain::ForceDeleteInteractor::PrepareDomain,
|
|
||||||
Domain::ForceDeleteInteractor::SetStatus,
|
|
||||||
Domain::ForceDeleteInteractor::PostSetProcess,
|
|
||||||
Domain::ForceDeleteInteractor::NotifyRegistrar,
|
|
||||||
Domain::ForceDeleteInteractor::NotifyByEmail
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -53,7 +53,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
|
||||||
end
|
end
|
||||||
|
|
||||||
def schedule_force_delete(type: :fast_track, notify_by_email: false)
|
def schedule_force_delete(type: :fast_track, notify_by_email: false)
|
||||||
Domain::ForceDeleteInteractor::SetForceDelete.call(domain: self,
|
Domain::ForceDeleteInteraction::SetForceDelete.run(domain: self,
|
||||||
type: type,
|
type: type,
|
||||||
notify_by_email: notify_by_email)
|
notify_by_email: notify_by_email)
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,7 @@ module DomainNameRegistry
|
||||||
|
|
||||||
# Autoload all model subdirs
|
# Autoload all model subdirs
|
||||||
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
|
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
|
||||||
|
config.autoload_paths += Dir[Rails.root.join('app', 'interactions', '**/')]
|
||||||
config.eager_load_paths << config.root.join('lib', 'validators')
|
config.eager_load_paths << config.root.join('lib', 'validators')
|
||||||
config.watchable_dirs['lib'] = %i[rb]
|
config.watchable_dirs['lib'] = %i[rb]
|
||||||
|
|
||||||
|
|
|
@ -111,10 +111,12 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
|
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
|
||||||
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
|
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
|
||||||
context = Domain::ForceDeleteInteractor::SetForceDelete.call(domain: @domain, type: :fast_track)
|
result = Domain::ForceDeleteInteraction::SetForceDelete.run(domain: @domain, type: :fast_track)
|
||||||
|
|
||||||
assert_not context.success?
|
assert_not result.valid?
|
||||||
assert_equal 'Force delete procedure cannot be scheduled while a domain is discarded', context.message
|
assert_not @domain.force_delete_scheduled?
|
||||||
|
message = ["Force delete procedure cannot be scheduled while a domain is discarded"]
|
||||||
|
assert_equal message, result.errors.messages[:domain]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cancels_force_delete
|
def test_cancels_force_delete
|
||||||
|
|
|
@ -414,7 +414,7 @@ class DomainTest < ActiveSupport::TestCase
|
||||||
force_delete_date: nil)
|
force_delete_date: nil)
|
||||||
@domain.update(template_name: 'legal_person')
|
@domain.update(template_name: 'legal_person')
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
Domain::ForceDeleteInteractor::SetForceDelete.call(domain: @domain, type: :fast_track)
|
Domain::ForceDeleteInteraction::SetForceDelete.run!(domain: @domain, type: :fast_track)
|
||||||
assert(@domain.force_delete_scheduled?)
|
assert(@domain.force_delete_scheduled?)
|
||||||
other_registrant = Registrant.find_by(code: 'jane-001')
|
other_registrant = Registrant.find_by(code: 'jane-001')
|
||||||
@domain.pending_json['new_registrant_id'] = other_registrant.id
|
@domain.pending_json['new_registrant_id'] = other_registrant.id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue