Add actions to set force delete #2624

This commit is contained in:
Martin Lensment 2015-06-10 19:15:40 +03:00
parent 9bd832278c
commit ba5be7b4f4
9 changed files with 101 additions and 24 deletions

View file

@ -28,6 +28,24 @@ class Admin::DomainsController < AdminController
end
end
def set_force_delete
if @domain.set_force_delete
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
redirect_to [:admin, @domain]
end
def unset_force_delete
if @domain.unset_force_delete
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
redirect_to [:admin, @domain]
end
private
def set_domain

View file

@ -198,6 +198,11 @@ class Domain < ActiveRecord::Base
c += 1
end
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
x.destroy
c += 1
end
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test?
end
end
@ -306,6 +311,10 @@ class Domain < ActiveRecord::Base
true
end
def force_deletable?
domain_statuses.where(value: DomainStatus::FORCE_DELETE).empty?
end
def registrant_verification_asked?
registrant_verification_asked_at.present? && registrant_verification_token.present?
end
@ -407,17 +416,34 @@ class Domain < ActiveRecord::Base
self.delete_at = outzone_at + Setting.redemption_grace_period.days
end
def set_force_delete
domain_statuses.where(value: DomainStatus::FORCE_DELETE).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).first_or_create
domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).first_or_create
domain_statuses.where(value: DomainStatus::PENDING_DELETE).first_or_create
domain_statuses.where(value: DomainStatus::CLIENT_DELETE_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).destroy_all
domain_statuses.reload
self.force_delete_at = Time.zone.now + Setting.redemption_grace_period unless self.force_delete_at
save(validate: false)
end
def unset_force_delete
domain_statuses.where(value: DomainStatus::FORCE_DELETE).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).destroy_all
domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).destroy_all
domain_statuses.where(value: DomainStatus::PENDING_DELETE).destroy_all
domain_statuses.reload
self.force_delete_at = nil
save(validate: false)
end
def manage_automatic_statuses
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if delete_candidateable?
# if domain_statuses.exists?(value: DomainStatus::FORCE_DELETE)
# domain_statuses.where(value: DomainStatus::SERVER_RENEW_PROHIBITED).first_or_create
# domain_statuses.where(value: DomainStatus::SERVER_TRANSFER_PROHIBITED).first_or_create
# domain_statuses.where(value: DomainStatus::SERVER_UPDATE_PROHIBITED).first_or_create
# domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).first_or_create
# domain_statuses.where(value: DomainStatus::PENDING_DELETE).first_or_create
# end
if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK)
elsif domain_statuses.length > 1 || !valid?

View file

@ -1,6 +1,11 @@
- content_for :actions do
= link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary')
= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary')
- if @domain.force_deletable?
= link_to(t(:set_force_delete), set_force_delete_admin_domain_path(@domain), method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning')
- else
= link_to(t(:unset_force_delete), unset_force_delete_admin_domain_path(@domain), method: :post, data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning')
= render 'shared/title', name: @domain.name
.row

View file

@ -818,3 +818,5 @@ en:
valid: Valid
category: Zone
object_is_not_eligible_for_renewal: 'Object is not eligible for renewal'
set_force_delete: 'Set force delete'
unset_force_delete: 'Unset force delete'

View file

@ -175,6 +175,10 @@ Rails.application.routes.draw do
resources :domains do
resources :domain_versions
member do
post 'set_force_delete'
post 'unset_force_delete'
end
end
resources :settings

View file

@ -0,0 +1,5 @@
class AddForceDeleteAtToDomain < ActiveRecord::Migration
def change
add_column :domains, :force_delete_at, :datetime
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150610112238) do
ActiveRecord::Schema.define(version: 20150610144547) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -306,6 +306,7 @@ ActiveRecord::Schema.define(version: 20150610112238) do
t.datetime "registrant_verification_asked_at"
t.string "registrant_verification_token"
t.json "pending_json"
t.datetime "force_delete_at"
end
add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree

View file

@ -143,16 +143,32 @@ describe Domain do
end
it 'should destroy delete candidates' do
Fabricate(:domain)
Domain.count.should == 2
d = Fabricate(:domain)
d.force_delete_at = Time.zone.now
d.save
@domain.delete_at = Time.zone.now
@domain.save
Domain.count.should == 2
Domain.start_delete_period
Domain.destroy_delete_candidates
Domain.count.should == 1
Domain.count.should == 0
end
it 'should set force delete time' do
@domain.set_force_delete
@domain.domain_statuses.count.should == 6
fda = Time.zone.now + Setting.redemption_grace_period
@domain.force_delete_at.should be_within(20).of(fda)
@domain.unset_force_delete
@domain.domain_statuses.count.should == 1
@domain.force_delete_at.should be_nil
end
context 'about registrant update confirm' do