Complete creation of interactors

This commit is contained in:
Alex Sherman 2020-11-10 13:50:38 +05:00
parent 4b980a07f5
commit 03754b542b
7 changed files with 78 additions and 17 deletions

View file

@ -5,19 +5,21 @@ module Admin
authorize! :manage, domain
domain.transaction do
domain.schedule_force_delete(type: force_delete_type)
domain.registrar.notifications.create!(text: t('force_delete_set_on_domain',
domain_name: domain.name,
outzone_date: domain.outzone_date,
purge_date: domain.purge_date))
notify_by_email if notify_by_email?
# domain.schedule_force_delete(type: force_delete_type)
# domain.registrar.notifications.create!(text: t('force_delete_set_on_domain',
# domain_name: domain.name,
# outzone_date: domain.outzone_date,
# purge_date: domain.purge_date)) # added to interactor
#
# notify_by_email if notify_by_email? # added to interactor
Domain::ForceDelete::Base.call(domain: domain, type: force_delete_type)
end
redirect_to edit_admin_domain_url(domain), notice: t('.scheduled')
end
def notify_by_email
# added to interactor
if force_delete_type == :fast_track
send_email
domain.update(contact_notification_sent_date: Time.zone.today)
@ -39,10 +41,12 @@ module Admin
end
def notify_by_email?
# added to interactor
ActiveRecord::Type::Boolean.new.cast(params[:notify_by_email])
end
def send_email
# added to interactor
DomainDeleteMailer.forced(domain: domain,
registrar: domain.registrar,
registrant: domain.registrant,

View file

@ -6,8 +6,8 @@ class Domain
def call
return unless context.domain.discarded?
raise StandardError,
'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 )
end
end
end

View file

@ -0,0 +1,31 @@
class Domain
module ForceDelete
class NotifyByEmail
include Interactor
def call
return unless notify_by_email?
if context.type == :fast_track
send_email
context.domain.update(contact_notification_sent_date: Time.zone.today)
else
context.domain.update(template_name: context.domain.notification_template)
end
end
private
def notify_by_email?
ActiveRecord::Type::Boolean.new.cast(params[:notify_by_email])
end
def send_email
DomainDeleteMailer.forced(domain: context.domain,
registrar: context.domain.registrar,
registrant: context.domain.registrant,
template_name: context.domain.notification_template).deliver_now
end
end
end
end

View file

@ -0,0 +1,16 @@
class Domain
module ForceDelete
class NotifyRegistrar
include Interactor
def call
domain = context.domain
domain.registrar.notifications.create!(text: 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

@ -3,10 +3,14 @@ class Domain
class PrepareDomain
include Interactor
STATUSES_TO_SET = [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
def call
domain = context.domain
domain.statuses_before_force_delete = domain.statuses
domain.statuses |= domain.class.STATUSES_TO_SET
domain.statuses |= STATUSES_TO_SET
domain.save(validate: false)
end
end

View file

@ -16,7 +16,10 @@ class Domain
end
def force_delete_fast_track
domain.force_delete_date = force_delete_fast_track_start_date + 1.day
domain.force_delete_date = Time.zone.today +
Setting.expire_warning_period.days +
Setting.redemption_grace_period.days +
1.day
domain.force_delete_start = Time.zone.today + 1.day
end

View file

@ -7,10 +7,6 @@ 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")
@ -57,6 +53,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def schedule_force_delete(type: :fast_track)
# added to interactor
if discarded?
raise StandardError, 'Force delete procedure cannot be scheduled while a domain is discarded'
end
@ -72,8 +69,8 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
preserve_current_statuses_for_force_delete
add_force_delete_statuses
add_force_delete_type(:fast)
self.force_delete_date = force_delete_fast_track_start_date + 1.day
self.force_delete_start = Time.zone.today + 1.day
self.force_delete_date = force_delete_fast_track_start_date + 1.day # added to interactor
self.force_delete_start = Time.zone.today + 1.day # added to interactor
stop_all_pending_actions
allow_deletion
save(validate: false)
@ -120,12 +117,14 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def soft_delete_dates(years)
# added to interactor
self.force_delete_start = valid_to - years.years
self.force_delete_date = force_delete_start + Setting.expire_warning_period.days +
Setting.redemption_grace_period.days
end
def stop_all_pending_actions
# added to interactor
statuses.delete(DomainStatus::PENDING_UPDATE)
statuses.delete(DomainStatus::PENDING_TRANSFER)
statuses.delete(DomainStatus::PENDING_RENEW)
@ -133,6 +132,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def preserve_current_statuses_for_force_delete
# added to interactor
update(statuses_before_force_delete: statuses)
end
@ -142,6 +142,7 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def add_force_delete_statuses
# added to interactor
self.statuses |= [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED]
@ -155,11 +156,13 @@ module Concerns::Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
end
def allow_deletion
# added to interactor
statuses.delete(DomainStatus::CLIENT_DELETE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
end
def force_delete_fast_track_start_date
# added to interactor
Time.zone.today + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
end
end