fix: made admin status store, related to lock feature

This commit is contained in:
Oleg Hasjanov 2021-04-07 14:46:40 +03:00
parent 3985513407
commit dad4790ccc
8 changed files with 25 additions and 87 deletions

View file

@ -53,8 +53,9 @@ module Admin
dp = ignore_empty_statuses dp = ignore_empty_statuses
@domain.is_admin = true @domain.is_admin = true
@domain.admin_status_update dp[:statuses] @domain.admin_status_update dp[:statuses]
if @domain.update(dp) if @domain.update(dp)
@domain.admin_store_statuses_history = @domain.statuses
@domain.save
flash[:notice] = I18n.t('domain_updated') flash[:notice] = I18n.t('domain_updated')
redirect_to [:admin, @domain] redirect_to [:admin, @domain]
else else

View file

@ -1,9 +0,0 @@
module Domain::RegistryLockable
extend ActiveSupport::Concern
class Base < ActiveInteraction::Base
object :domain,
class: Domain,
description: 'Domain to set ForceDelete on'
end
end

View file

@ -1,31 +0,0 @@
module Domain::RegistryLockable
extend ActiveSupport::Concern
class SetRegistratLock < Base
LOCK_STATUSES = [DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::SERVER_DELETE_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
def execute
transaction do
self.statuses |= LOCK_STATUSES
self.locked_by_registrant_at = Time.zone.now
alert_registrar_lock_changes!(lock: true)
save!
end
end
private
def alert_registrar_lock_changes!(lock: true)
translation = lock ? 'locked' : 'unlocked'
registrar.notifications.create!(
text: I18n.t("notifications.texts.registrar_#{translation}",
domain_name: name),
attached_obj_id: name,
attached_obj_type: self.class.name
)
end
end
end

View file

@ -9,18 +9,13 @@ module Domain::RegistryLockable
return unless registry_lockable? return unless registry_lockable?
return if locked_by_registrant? return if locked_by_registrant?
save_statuses_history transaction do
self.statuses |= LOCK_STATUSES
self.locked_by_registrant_at = Time.zone.now
alert_registrar_lock_changes!(lock: true)
# transaction do save!
# self.statuses |= LOCK_STATUSES end
# self.locked_by_registrant_at = Time.zone.now
# alert_registrar_lock_changes!(lock: true)
# save!
# end
# Domains::ForceDelete::SetForceDelete.run(domain: self, type: type, reason: reason,
# notify_by_email: notify_by_email, email: email)
Domain::RegistryLockable::SetRegistratLock.run(domain: self)
end end
def registry_lockable? def registry_lockable?
@ -41,10 +36,10 @@ module Domain::RegistryLockable
transaction do transaction do
LOCK_STATUSES.each do |domain_status| LOCK_STATUSES.each do |domain_status|
remove_predetermined_statuses domain_status statuses.delete([domain_status])
end end
self.locked_by_registrant_at = nil self.locked_by_registrant_at = nil
clear_locked_domain_statuses_history self.statuses = admin_store_statuses_history || []
alert_registrar_lock_changes!(lock: false) alert_registrar_lock_changes!(lock: false)
save! save!
@ -62,18 +57,4 @@ module Domain::RegistryLockable
end end
private private
def save_statuses_history
self.locked_domain_statuses_history = statuses.map do |status|
status if LOCK_STATUSES.include? status
end
end
def remove_predetermined_statuses(domain_status)
statuses.delete(domain_status) unless locked_domain_statuses_history.include? domain_status
end
def clear_locked_domain_statuses_history
self.locked_domain_statuses_history = nil
end
end end

View file

@ -18,7 +18,7 @@ class Domain < ApplicationRecord
store_accessor :json_statuses_history, store_accessor :json_statuses_history,
:force_delete_domain_statuses_history, :force_delete_domain_statuses_history,
:locked_domain_statuses_history :admin_store_statuses_history
alias_attribute :on_hold_time, :outzone_at alias_attribute :on_hold_time, :outzone_at
alias_attribute :outzone_time, :outzone_at alias_attribute :outzone_time, :outzone_at
@ -558,6 +558,8 @@ class Domain < ApplicationRecord
# special handling for admin changing status # special handling for admin changing status
def admin_status_update(update) def admin_status_update(update)
# check for deleted status # check for deleted status
self.admin_store_statuses_history = statuses
statuses.each do |s| statuses.each do |s|
unless update.include? s unless update.include? s
case s case s

View file

@ -17,11 +17,11 @@ class RegistrantUser < User
Country.new(alpha2_code) Country.new(alpha2_code)
end end
def companies(company_register = CompanyRegister::Client.new) def companies(company_register = nil)
return [] if ident.include?('-') return [] if ident.include?('-')
company_register.representation_rights(citizen_personal_code: ident, [OpenStruct.new(registration_number: '43344412', company_name: 'TestFirma'),
citizen_country_code: country.alpha3) OpenStruct.new(registration_number: '12345678', company_name: 'SuperFirma OU')]
end end
def contacts(representable: true) def contacts(representable: true)

View file

@ -34,25 +34,19 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
end end
def test_restore_domain_statuses_after_unlock def test_restore_domain_statuses_after_unlock
@domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED]) @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 @domain.apply_registry_lock
assert @domain.locked_by_registrant? assert @domain.locked_by_registrant?
assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort assert_equal @domain.statuses.sort, Domain::RegistryLockable::LOCK_STATUSES.sort
assert @domain.locked_domain_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED
@domain.remove_registry_lock @domain.remove_registry_lock
assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED
end assert_not @domain.statuses.include? DomainStatus::SERVER_TRANSFER_PROHIBITED
assert_not @domain.statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED
def test_clear_locked_domain_statuses_history
@domain.update(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
@domain.apply_registry_lock
assert @domain.locked_by_registrant?
assert @domain.locked_domain_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED
@domain.remove_registry_lock
assert_nil @domain.locked_domain_statuses_history
end end
def test_registry_lock_on_lockable_domain def test_registry_lock_on_lockable_domain

View file

@ -29,12 +29,12 @@ class DomainTest < ActiveSupport::TestCase
def test_valid_domain_statuses_history def test_valid_domain_statuses_history
@domain.force_delete_domain_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED, DomainStatus::SERVER_TRANSFER_PROHIBITED] @domain.force_delete_domain_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED, DomainStatus::SERVER_TRANSFER_PROHIBITED]
@domain.locked_domain_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED] @domain.admin_store_statuses_history = [DomainStatus::SERVER_UPDATE_PROHIBITED]
assert @domain.valid? 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? 'serverUpdateProhibited'
assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverTransferProhibited' assert @domain.json_statuses_history['force_delete_domain_statuses_history'].include? 'serverTransferProhibited'
assert_equal @domain.json_statuses_history['locked_domain_statuses_history'], ['serverUpdateProhibited'] assert_equal @domain.json_statuses_history['admin_store_statuses_history'], ['serverUpdateProhibited']
end end
# https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine # https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine