Skip to content

Commit

Permalink
Add poll message on start of grace period for soft delete
Browse files Browse the repository at this point in the history
Add removing forceDelete on registrant change.
Restore email template choosing on safe force delete via admin
dashboard.

See #1428 (comment)
  • Loading branch information
yulgolem committed Jan 14, 2020
1 parent aedd0ca commit c714dc1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 52 deletions.
5 changes: 5 additions & 0 deletions app/models/concerns/domain/force_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def force_delete_scheduled?
statuses.include?(DomainStatus::FORCE_DELETE)
end

def should_notify_on_soft_force_delete?
force_delete_scheduled? && !statuses.include?(DomainStatus::CLIENT_HOLD) &&
force_delete_start.present? && force_delete_start.to_date == Time.zone.now.to_date
end

def client_holdable?
force_delete_scheduled? && !statuses.include?(DomainStatus::CLIENT_HOLD) &&
force_delete_start.present? && force_delete_lte_today && force_delete_lte_valid_date
Expand Down
31 changes: 31 additions & 0 deletions app/models/concerns/job/force_delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Concerns
module Job
module ForceDelete
extend ActiveSupport::Concern

class_methods do
def start_client_hold
log_prepare_client_hold

::PaperTrail.whodunnit = "cron - #{__method__}"

::Domain.force_delete_scheduled.each do |domain|
proceed_client_hold(domain: domain)
log_end_end_client_hold(domain)
end
end

def proceed_client_hold(domain:)
notify_on_grace_period(domain) if domain.should_notify_on_soft_force_delete?
return unless domain.client_holdable?

domain.statuses << DomainStatus::CLIENT_HOLD
log_start_client_hold(domain)

domain.save(validate: false)
notify_client_hold(domain)
end
end
end
end
end
41 changes: 41 additions & 0 deletions app/models/concerns/job/force_delete_messages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Concerns
module Job
module ForceDeleteMessages
extend ActiveSupport::Concern

class_methods do
def log_prepare_client_hold
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} - Setting client_hold to domains\n"
end

def log_start_client_hold(domain)
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} DomainCron.start_client_hold: ##{domain.id} "\
"(#{domain.name}) #{domain.changes}\n"
end

def log_end_end_client_hold(domain)
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} - Successfully set client_hold on (#{domain.name})"
end

def notify_client_hold(domain)
domain.registrar.notifications.create!(text: I18n.t('client_hold_set_on_domain',
domain_name: domain.name,
date: domain.force_delete_start))
end

def notify_on_grace_period(domain)
domain.registrar.notifications.create!(text: I18n.t('grace_period_started_domain',
domain_name: domain.name,
date: domain.force_delete_start))
end
end

end
end
end
2 changes: 2 additions & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ def manage_automatic_statuses
activate if nameservers.reject(&:marked_for_destruction?).size >= Setting.ns_min_count
end

cancel_force_delete if force_delete_scheduled? && pending_json['new_registrant_id']

if statuses.empty? && valid?
statuses << DomainStatus::OK
elsif (statuses.length > 1 && active?) || !valid?
Expand Down
50 changes: 2 additions & 48 deletions app/models/domain_cron.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class DomainCron
include Concerns::Job::ForceDelete
include Concerns::Job::ForceDeleteMessages

def self.clean_expired_pendings
STDOUT << "#{Time.zone.now.utc} - Clean expired domain pendings\n" unless Rails.env.test?
Expand Down Expand Up @@ -78,52 +80,4 @@ def self.start_redemption_grace_period
STDOUT << "#{Time.zone.now.utc} - Successfully set server_hold to #{marked} of #{real} domains\n" unless Rails.env.test?
marked
end

def self.start_client_hold
log_prepare_client_hold

::PaperTrail.whodunnit = "cron - #{__method__}"

marked = 0
real = 0

Domain.force_delete_scheduled.each do |domain|
next unless domain.client_holdable?

real += 1
domain.statuses << DomainStatus::CLIENT_HOLD
log_start_client_hold(domain)

domain.save(validate: false) and marked += 1 and notify_client_hold(domain)
end

log_end_end_client_hold(marked: marked, real: real)
marked
end

def self.log_prepare_client_hold
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} - Setting client_hold to domains\n"
end

def self.log_start_client_hold(domain)
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} DomainCron.start_client_hold: ##{domain.id} (#{domain.name})"\
"#{domain.changes}\n"
end

def self.log_end_end_client_hold(marked:, real:)
return if Rails.env.test?

STDOUT << "#{Time.zone.now.utc} - Successfully set client_hold to #{marked} of #{real} "\
"domains\n"
end

def self.notify_client_hold(domain)
domain.registrar.notifications.create!(text: I18n.t('soft_force_delete_set_on_domain',
domain_name: domain.name,
start_date: domain.force_delete_start))
end
end
3 changes: 1 addition & 2 deletions app/views/admin/domains/_force_delete_dialog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<div class="col-md-9">
<div class="checkbox">
<label>
<%= check_box_tag 'soft_delete', 1, true,
data: { dependent_content_toggle: true } %>
<%= check_box_tag 'soft_delete', 1, true %>
<%= t '.use_soft_delete' %>
</label>
</div>
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ en:
created_at_until: 'Created at until'
is_registrant: 'Is registrant'
force_delete_set_on_domain: 'Force delete set on domain %{domain_name}'
soft_force_delete_set_on_domain: 'clientHold status is set for domain %{domain_name}, ForceDelete is in effect from %{start_date}'
client_hold_set_on_domain: 'clientHold status is set for domain %{domain_name}, ForceDelete is in effect from %{date}'
grace_period_started_domain: 'For domain %{domain_name} started 45-days redemption grace period, ForceDelete will be in effect from %{date}'
force_delete_cancelled: 'Force delete is cancelled on domain %{domain_name}'
contact_is_not_valid: 'Contact %{value} is not valid, please fix the invalid contact'
next: 'Next'
Expand Down
2 changes: 1 addition & 1 deletion config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
runner 'DomainCron.start_redemption_grace_period'
end

every 1.hour do
every 1.day do
runner 'DomainCron.start_client_hold'
end

Expand Down

0 comments on commit c714dc1

Please sign in to comment.