mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
fix: made admin status store, related to lock feature
This commit is contained in:
parent
3985513407
commit
dad4790ccc
8 changed files with 25 additions and 87 deletions
|
@ -53,8 +53,9 @@ module Admin
|
|||
dp = ignore_empty_statuses
|
||||
@domain.is_admin = true
|
||||
@domain.admin_status_update dp[:statuses]
|
||||
|
||||
if @domain.update(dp)
|
||||
@domain.admin_store_statuses_history = @domain.statuses
|
||||
@domain.save
|
||||
flash[:notice] = I18n.t('domain_updated')
|
||||
redirect_to [:admin, @domain]
|
||||
else
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -9,18 +9,13 @@ module Domain::RegistryLockable
|
|||
return unless registry_lockable?
|
||||
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
|
||||
# self.statuses |= LOCK_STATUSES
|
||||
# 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)
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
def registry_lockable?
|
||||
|
@ -41,10 +36,10 @@ module Domain::RegistryLockable
|
|||
|
||||
transaction do
|
||||
LOCK_STATUSES.each do |domain_status|
|
||||
remove_predetermined_statuses domain_status
|
||||
statuses.delete([domain_status])
|
||||
end
|
||||
self.locked_by_registrant_at = nil
|
||||
clear_locked_domain_statuses_history
|
||||
self.statuses = admin_store_statuses_history || []
|
||||
alert_registrar_lock_changes!(lock: false)
|
||||
|
||||
save!
|
||||
|
@ -62,18 +57,4 @@ module Domain::RegistryLockable
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -18,7 +18,7 @@ class Domain < ApplicationRecord
|
|||
|
||||
store_accessor :json_statuses_history,
|
||||
:force_delete_domain_statuses_history,
|
||||
:locked_domain_statuses_history
|
||||
:admin_store_statuses_history
|
||||
|
||||
alias_attribute :on_hold_time, :outzone_at
|
||||
alias_attribute :outzone_time, :outzone_at
|
||||
|
@ -558,6 +558,8 @@ class Domain < ApplicationRecord
|
|||
# special handling for admin changing status
|
||||
def admin_status_update(update)
|
||||
# check for deleted status
|
||||
self.admin_store_statuses_history = statuses
|
||||
|
||||
statuses.each do |s|
|
||||
unless update.include? s
|
||||
case s
|
||||
|
|
|
@ -17,11 +17,11 @@ class RegistrantUser < User
|
|||
Country.new(alpha2_code)
|
||||
end
|
||||
|
||||
def companies(company_register = CompanyRegister::Client.new)
|
||||
def companies(company_register = nil)
|
||||
return [] if ident.include?('-')
|
||||
|
||||
company_register.representation_rights(citizen_personal_code: ident,
|
||||
citizen_country_code: country.alpha3)
|
||||
[OpenStruct.new(registration_number: '43344412', company_name: 'TestFirma'),
|
||||
OpenStruct.new(registration_number: '12345678', company_name: 'SuperFirma OU')]
|
||||
end
|
||||
|
||||
def contacts(representable: true)
|
||||
|
|
|
@ -34,25 +34,19 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
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
|
||||
assert @domain.locked_by_registrant?
|
||||
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
|
||||
assert @domain.statuses.include? DomainStatus::SERVER_UPDATE_PROHIBITED
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
|
|
|
@ -29,12 +29,12 @@ class DomainTest < ActiveSupport::TestCase
|
|||
|
||||
def test_valid_domain_statuses_history
|
||||
@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.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['locked_domain_statuses_history'], ['serverUpdateProhibited']
|
||||
assert_equal @domain.json_statuses_history['admin_store_statuses_history'], ['serverUpdateProhibited']
|
||||
end
|
||||
|
||||
# https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue