Skip to content

Commit

Permalink
Add :fast_track & :soft versions of ForceDelete
Browse files Browse the repository at this point in the history
See #1428
  • Loading branch information
yulgolem committed Jan 14, 2020
1 parent 550d020 commit bbc89e5
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions app/models/concerns/domain/force_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,66 @@ def force_delete_scheduled?
statuses.include?(DomainStatus::FORCE_DELETE)
end

def schedule_force_delete
def schedule_force_delete(type: :fast_track)
if discarded?
raise StandardError, 'Force delete procedure cannot be scheduled while a domain is discarded'
raise StandardError 'Force delete procedure cannot be scheduled while a domain is discarded'
end

case type
when :fast_track
force_delete_fast_track
when :soft
force_delete_soft
else
raise StandardError, 'Wrong type for force delete'
end
end

def force_delete_fast_track
preserve_current_statuses_for_force_delete
add_force_delete_statuses
self.force_delete_date = Time.zone.today + Setting.redemption_grace_period.days + 1.day
self.force_delete_date = Time.zone.today + Setting.redemption_grace_period.days
self.force_delete_start = Time.zone.today
stop_all_pending_actions
allow_deletion
save(validate: false)
end

def force_delete_soft
preserve_current_statuses_for_force_delete
add_force_delete_statuses
calculate_soft_delete_date
stop_all_pending_actions
check_hold
allow_deletion
save(validate: false)
end

def cancel_force_delete
restore_statuses_before_force_delete
remove_force_delete_statuses
self.force_delete_date = nil
self.force_delete_start = nil
save(validate: false)
end

private

def check_hold
if force_delete_start < valid_to && (force_delete_date + DAYS_TO_START_HOLD) > Time.zone.today
if force_delete_start.present? &&
force_delete_start < valid_to &&
(force_delete_date + DAYS_TO_START_HOLD) > Time.zone.today
statuses << DomainStatus::CLIENT_HOLD
end
end

private
def calculate_soft_delete_date
years = (self.valid_to.to_date - Time.zone.today).to_i / 365
if years.positive?
self.force_delete_start = self.valid_to - years.years
self.force_delete_date = self.force_delete_start + Setting.redemption_grace_period.days
end
end

def stop_all_pending_actions
statuses.delete(DomainStatus::PENDING_UPDATE)
Expand All @@ -55,12 +88,6 @@ def add_force_delete_statuses
statuses << DomainStatus::FORCE_DELETE
statuses << DomainStatus::SERVER_RENEW_PROHIBITED
statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
statuses << DomainStatus::SERVER_UPDATE_PROHIBITED
statuses << DomainStatus::PENDING_DELETE

if (statuses & [DomainStatus::SERVER_HOLD, DomainStatus::CLIENT_HOLD]).empty?
statuses << DomainStatus::SERVER_MANUAL_INZONE
end
end

def remove_force_delete_statuses
Expand Down

0 comments on commit bbc89e5

Please sign in to comment.