refactoring

This commit is contained in:
olegphenomenon 2021-09-22 11:14:12 +03:00
parent 81b476f37f
commit 4d64ee21a1
11 changed files with 49 additions and 42 deletions

View file

@ -8,9 +8,9 @@ module Api
before_action :authorized_to_manage_locks?
def create
extensionsProhibited = params[:extensionsProhibited]
extensions_prohibited = params[:extensionsProhibited]
if @domain.apply_registry_lock(extensionsProhibited: extensionsProhibited.to_s.downcase == "true")
if @domain.apply_registry_lock(extensions_prohibited: extensions_prohibited.to_s.downcase == 'true')
render json: serialized_domain(@domain)
else
render json: { errors: [{ base: ['Domain cannot be locked'] }] },

View file

@ -12,22 +12,25 @@ module Domain::RegistryLockable
end
EXTENSIONS_STATUS = [DomainStatus::SERVER_EXTENSION_UPDATE_PROHIBITED].freeze
def apply_registry_lock(extensionsProhibited:)
def apply_registry_lock(extensions_prohibited:)
return unless registry_lockable?
return if locked_by_registrant?
transaction do
self.statuses |= LOCK_STATUSES
self.statuses |= EXTENSIONS_STATUS if Feature.obj_and_extensions_statuses_enabled? and extensionsProhibited
self.locked_by_registrant_at = Time.zone.now
alert_registrar_lock_changes!(lock: true)
save!
apply_statuses_locked_statuses(extensions_prohibited: extensions_prohibited)
end
end
def apply_statuses_locked_statuses(extensions_prohibited:)
self.statuses |= LOCK_STATUSES
self.statuses |= EXTENSIONS_STATUS if Feature.obj_and_extensions_statuses_enabled? && extensions_prohibited
self.locked_by_registrant_at = Time.zone.now
alert_registrar_lock_changes!(lock: true)
save!
end
def registry_lockable?
(statuses & [DomainStatus::PENDING_DELETE_CONFIRMATION,
DomainStatus::PENDING_CREATE, DomainStatus::PENDING_UPDATE,
@ -45,20 +48,23 @@ module Domain::RegistryLockable
return unless locked_by_registrant?
transaction do
LOCK_STATUSES.each do |domain_status|
statuses.delete([domain_status])
end
statuses.delete([EXTENSIONS_STATUS]) if statuses.include? EXTENSIONS_STATUS
self.locked_by_registrant_at = nil
self.statuses = admin_store_statuses_history || []
alert_registrar_lock_changes!(lock: false)
save!
remove_statuses_from_locked_domain
end
end
def remove_statuses_from_locked_domain
LOCK_STATUSES.each do |domain_status|
statuses.delete([domain_status])
end
statuses.delete([EXTENSIONS_STATUS]) if statuses.include? EXTENSIONS_STATUS
self.locked_by_registrant_at = nil
self.statuses = admin_store_statuses_history || []
alert_registrar_lock_changes!(lock: false)
save!
end
def alert_registrar_lock_changes!(lock: true)
translation = lock ? 'locked' : 'unlocked'
registrar.notifications.create!(

View file

@ -23,7 +23,7 @@ class RegistrantUser < User
company_register.representation_rights(citizen_personal_code: ident,
citizen_country_code: country.alpha3)
end
def contacts(representable: true)
Contact.registrant_user_contacts(self, representable: representable)
end