Skip to content

Commit

Permalink
Merge pull request #1902 from internetee/1900-removing-registry-lock-…
Browse files Browse the repository at this point in the history
…should-not-remove-statuses-set-prior-to-setting-it

implement domain statuses restore after domain locked, added test
  • Loading branch information
vohmar authored Apr 8, 2021
2 parents 26618a3 + 441a191 commit f6fcf15
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module Domains
module CancelForceDelete
class RemoveForceDeleteStatuses < Base
def execute
domain.statuses.delete(DomainStatus::FORCE_DELETE)
domain.statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED)
domain.statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED)
domain.statuses.delete(DomainStatus::CLIENT_HOLD)
domain_statuses = [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::CLIENT_HOLD]
rejected_statuses = domain.statuses.reject { |a| domain_statuses.include? a }
domain.statuses = rejected_statuses
domain.save(validate: false)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module Domains
module CancelForceDelete
class RestoreStatusesBeforeForceDelete < Base
def execute
domain.statuses = domain.statuses_before_force_delete
# domain.statuses = domain.statuses_before_force_delete
domain.statuses = domain.force_delete_domain_statuses_history || []
domain.statuses_before_force_delete = nil
domain.force_delete_domain_statuses_history = nil
domain.save(validate: false)
end
end
Expand Down
1 change: 1 addition & 0 deletions app/interactions/domains/force_delete/prepare_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class PrepareDomain < Base
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze

def execute
domain.force_delete_domain_statuses_history = domain.statuses
domain.statuses_before_force_delete = domain.statuses
domain.statuses |= STATUSES_TO_SET
domain.save(validate: false)
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/domain/force_delete.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Domain::ForceDelete # rubocop:disable Metrics/ModuleLength
extend ActiveSupport::Concern

FORCE_DELETE_STATUSES = [DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze

included do
store_accessor :force_delete_data,
:force_delete_type,
Expand Down Expand Up @@ -52,6 +56,7 @@ def schedule_force_delete(type: :fast_track, notify_by_email: false, reason: nil

def cancel_force_delete
Domains::CancelForceDelete::CancelForceDelete.run(domain: self)
# self.statuses = force_delete_domain_statuses_history
end

def outzone_date
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/domain/registry_lockable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def remove_registry_lock

transaction do
LOCK_STATUSES.each do |domain_status|
statuses.delete(domain_status)
statuses.delete([domain_status])
end
self.locked_by_registrant_at = nil
self.statuses = admin_store_statuses_history || []
alert_registrar_lock_changes!(lock: false)

save!
Expand Down
23 changes: 23 additions & 0 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ class Domain < ApplicationRecord
include Domain::Disputable
include Domain::BulkUpdatable

LOCK_STATUSES = [DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::SERVER_DELETE_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze

attr_accessor :roles

attr_accessor :legal_document_id

store_accessor :json_statuses_history,
:force_delete_domain_statuses_history,
:admin_store_statuses_history

alias_attribute :on_hold_time, :outzone_at
alias_attribute :outzone_time, :outzone_at
alias_attribute :auth_info, :transfer_code # Old attribute name; for PaperTrail
Expand Down Expand Up @@ -551,8 +559,23 @@ def delete_prohibited?
statuses.include?(DomainStatus::FORCE_DELETE)
end

def update_unless_locked_by_registrant(update)
update(admin_store_statuses_history: update) unless locked_by_registrant?
end

def update_not_by_locked_statuses(update)
return unless locked_by_registrant?

result = update.reject { |status| LOCK_STATUSES.include? status }
update(admin_store_statuses_history: result)
end

# special handling for admin changing status
def admin_status_update(update)
update_unless_locked_by_registrant(update)

update_not_by_locked_statuses(update)

# check for deleted status
statuses.each do |s|
unless update.include? s
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class TransferDomainStatusesBeforeForceDeleteToJsonHistory < ActiveRecord::Migration[6.0]
def up
domains = Domain.where.not(statuses_before_force_delete: nil)
domains.each do |domain|
domain.force_delete_domain_statuses_history = domain.statuses_before_force_delete
domain.save
end
end

def down
# raise ActiveRecord::IrreversibleMigration
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class TransferDataFromDomainStatusesToAdminStatusHistory < ActiveRecord::Migration[6.0]
def up
domains = Domain.all.select { |d| !d.locked_by_registrant?}
domains.each do |domain|
domain.admin_store_statuses_history = domain.statuses
domain.save
end
end

def down
# raise ActiveRecord::IrreversibleMigration
end
end
2 changes: 1 addition & 1 deletion db/data_schema.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# encoding: UTF-8
DataMigrate::Data.define(version: 20201007104651)
DataMigrate::Data.define(version: 20210407140317)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddJsonStatusesHistoryFieldToDomain < ActiveRecord::Migration[6.0]
def change
add_column :domains, :json_statuses_history, :jsonb
add_index :domains, :json_statuses_history, using: :gin
end
end
17 changes: 15 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ CREATE TABLE public.domains (
uuid uuid DEFAULT public.gen_random_uuid() NOT NULL,
locked_by_registrant_at timestamp without time zone,
force_delete_start timestamp without time zone,
force_delete_data public.hstore
force_delete_data public.hstore,
json_statuses_history jsonb
);


Expand Down Expand Up @@ -4124,6 +4125,17 @@ CREATE INDEX index_domain_transfers_on_domain_id ON public.domain_transfers USIN
CREATE INDEX index_domains_on_delete_date ON public.domains USING btree (delete_date);



-- Name: index_domains_on_json_statuses_history; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_domains_on_json_statuses_history ON public.domains USING gin (json_statuses_history);


--
-- Name: index_domains_on_name; Type: INDEX; Schema: public; Owner: -


--
-- Name: index_domains_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
Expand Down Expand Up @@ -5301,4 +5313,5 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200916125326'),
('20200917104213'),
('20210215101019'),
('20200921084356');
('20200921084356'),
('20210405100631');
23 changes: 23 additions & 0 deletions test/models/domain/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ class ForceDeleteTest < ActionMailer::TestCase
Truemail.configure.default_validation_type = @old_validation_type
end

def test_restore_domain_statuses_after_soft_force_delete
@domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED])
@domain.schedule_force_delete(type: :soft)

assert @domain.force_delete_scheduled?

assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED

@domain.cancel_force_delete
assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED
end

def test_clear_force_delete_domain_statuses_history
@domain.update(statuses: [DomainStatus::SERVER_RENEW_PROHIBITED])
@domain.schedule_force_delete(type: :soft)

assert @domain.force_delete_scheduled?
assert @domain.force_delete_domain_statuses_history.include? DomainStatus::SERVER_RENEW_PROHIBITED
@domain.cancel_force_delete

assert_nil @domain.force_delete_domain_statuses_history
end

def test_schedules_force_delete_fast_track
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
Expand Down
51 changes: 50 additions & 1 deletion test/models/domain/registry_lockable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class DomainRegistryLockableTest < ActiveSupport::TestCase
def setup
super

@domain = domains(:airport)
end

Expand Down Expand Up @@ -33,6 +32,56 @@ def test_lockable_domain_if_remove_some_prohibited_status
assert_not(@domain.locked_by_registrant?)
end

def test_remove_lockalable_statuses_after_admin_intervention
@domain.apply_registry_lock
assert @domain.locked_by_registrant?
assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort

deleted_status = @domain.statuses - [DomainStatus::SERVER_DELETE_PROHIBITED]
@domain.update(statuses: deleted_status)
assert_not @domain.locked_by_registrant?

@domain.apply_registry_lock
assert @domain.locked_by_registrant?
@domain.remove_registry_lock

assert_not @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED
end

def test_restore_domain_statuses_after_unlock
@domain.statuses = [DomainStatus::SERVER_UPDATE_PROHIBITED]
@domain.admin_store_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED]
@domain.save
assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED

@domain.apply_registry_lock
assert @domain.locked_by_registrant?
assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort

@domain.remove_registry_lock
assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED
end

def test_add_additinal_status_for_locked_domain
@domain.apply_registry_lock
assert @domain.locked_by_registrant?
assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort

@domain.statuses += [DomainStatus::SERVER_RENEW_PROHIBITED]
@domain.admin_store_statuses_history = [DomainStatus::SERVER_RENEW_PROHIBITED]
@domain.save

@domain.remove_registry_lock
assert @domain.statuses.include? DomainStatus::SERVER_RENEW_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED
end

def test_registry_lock_on_lockable_domain
refute(@domain.locked_by_registrant?)
@domain.apply_registry_lock
Expand Down
10 changes: 10 additions & 0 deletions test/models/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def test_invalid_fixture_is_invalid
assert domains(:invalid).invalid?
end

def test_valid_domain_statuses_history
@domain.force_delete_domain_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED, DomainStatus::SERVER_TRANSFER_PROHIBITED]
@domain.admin_store_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED]
assert @domain.valid?

assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverUpdateProhibited'
assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverTransferProhibited'
assert_equal @domain.json_statuses_history['admin_store_statuses_history'], ['serverUpdateProhibited']
end

# https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine
def test_validates_name_format
assert_equal dns_zones(:one).origin, 'test'
Expand Down

0 comments on commit f6fcf15

Please sign in to comment.