Merge pull request #2164 from internetee/possibility-of-adding-extension-prohibited

Possibility of adding extension prohibited
This commit is contained in:
Timo Võhmar 2021-09-23 16:35:34 +03:00 committed by GitHub
commit a904fda198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 36 deletions

1
.gitignore vendored
View file

@ -9,6 +9,7 @@
/config/application.yml /config/application.yml
/config/environments/development.rb /config/environments/development.rb
/config/deploy.rb /config/deploy.rb
/.idea
# Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide. # Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide.
.rubocop.yml .rubocop.yml

View file

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

View file

@ -11,20 +11,26 @@ module Domain::RegistryLockable
DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze DomainStatus::SERVER_TRANSFER_PROHIBITED].freeze
end end
def apply_registry_lock EXTENSIONS_STATUS = [DomainStatus::SERVER_EXTENSION_UPDATE_PROHIBITED].freeze
# binding.pry
def apply_registry_lock(extensions_prohibited:)
return unless registry_lockable? return unless registry_lockable?
return if locked_by_registrant? return if locked_by_registrant?
transaction do transaction do
self.statuses |= LOCK_STATUSES apply_statuses_locked_statuses(extensions_prohibited: extensions_prohibited)
self.locked_by_registrant_at = Time.zone.now
alert_registrar_lock_changes!(lock: true)
save!
end end
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? def registry_lockable?
(statuses & [DomainStatus::PENDING_DELETE_CONFIRMATION, (statuses & [DomainStatus::PENDING_DELETE_CONFIRMATION,
DomainStatus::PENDING_CREATE, DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_CREATE, DomainStatus::PENDING_UPDATE,
@ -42,17 +48,23 @@ module Domain::RegistryLockable
return unless locked_by_registrant? return unless locked_by_registrant?
transaction do transaction do
LOCK_STATUSES.each do |domain_status| remove_statuses_from_locked_domain
statuses.delete([domain_status])
end
self.locked_by_registrant_at = nil
self.statuses = admin_store_statuses_history || []
alert_registrar_lock_changes!(lock: false)
save!
end end
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) def alert_registrar_lock_changes!(lock: true)
translation = lock ? 'locked' : 'unlocked' translation = lock ? 'locked' : 'unlocked'
registrar.notifications.create!( registrar.notifications.create!(

View file

@ -47,7 +47,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
end end
def test_cannot_lock_an_already_locked_domain def test_cannot_lock_an_already_locked_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock', post '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
@ -59,7 +59,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest
end end
def test_can_unlock_a_locked_domain def test_can_unlock_a_locked_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
delete '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock', delete '/api/v1/registrant/domains/2df2c1a1-8f6a-490a-81be-8bdf29866880/registry_lock',
headers: @auth_headers headers: @auth_headers

View file

@ -22,14 +22,14 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
def test_registrant_locked_domain def test_registrant_locked_domain
refute @domain.locked_by_registrant? refute @domain.locked_by_registrant?
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert @domain.locked_by_registrant? assert @domain.locked_by_registrant?
assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been locked by registrant") assert_equal(@domain.registrar.notifications.last.text, "Domain #{@domain.name} has been locked by registrant")
end end
def test_registrant_unlocked_domain def test_registrant_unlocked_domain
refute @domain.locked_by_registrant? refute @domain.locked_by_registrant?
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert @domain.locked_by_registrant? assert @domain.locked_by_registrant?
@domain.remove_registry_lock @domain.remove_registry_lock
refute @domain.locked_by_registrant? refute @domain.locked_by_registrant?

View file

@ -16,7 +16,7 @@ class SerializersRegistrantApiDomainTest < ActiveSupport::TestCase
assert_not(@json[:locked_by_registrant_at]) assert_not(@json[:locked_by_registrant_at])
travel_to Time.zone.parse('2010-07-05 10:30') travel_to Time.zone.parse('2010-07-05 10:30')
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
serializer_for_locked_domain = Serializers::RegistrantApi::Domain.new(@domain.reload) serializer_for_locked_domain = Serializers::RegistrantApi::Domain.new(@domain.reload)
new_json = serializer_for_locked_domain.to_json new_json = serializer_for_locked_domain.to_json

View file

@ -31,7 +31,7 @@ class DomainVersionTest < ActiveSupport::TestCase
PaperTrail.request.whodunnit = @user.id_role_username PaperTrail.request.whodunnit = @user.id_role_username
assert_difference '@domain.versions.count', 1 do assert_difference '@domain.versions.count', 1 do
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
end end
assert_equal(@domain.updator, @user) assert_equal(@domain.updator, @user)

View file

@ -11,14 +11,14 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
@domain.update(statuses: [DomainStatus::SERVER_TRANSFER_PROHIBITED]) @domain.update(statuses: [DomainStatus::SERVER_TRANSFER_PROHIBITED])
@domain.apply_registry_lock # Raise validation error @domain.apply_registry_lock(extensions_prohibited: false) # Raise validation error
check_statuses_lockable_domain check_statuses_lockable_domain
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
end end
def test_remove_lockalable_statuses_after_admin_intervention def test_remove_lockalable_statuses_after_admin_intervention
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
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
@ -26,7 +26,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
@domain.update(statuses: deleted_status) @domain.update(statuses: deleted_status)
assert_not @domain.locked_by_registrant? assert_not @domain.locked_by_registrant?
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert @domain.locked_by_registrant? assert @domain.locked_by_registrant?
@domain.remove_registry_lock @domain.remove_registry_lock
@ -41,7 +41,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
@domain.save @domain.save
assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED assert @domain.admin_store_statuses_history.include? DomainStatus::SERVER_UPDATE_PROHIBITED
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
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
@ -52,7 +52,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
end end
def test_add_additinal_status_for_locked_domain def test_add_additinal_status_for_locked_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
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
@ -69,7 +69,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
def test_lockable_domain_if_remove_some_prohibited_status def test_lockable_domain_if_remove_some_prohibited_status
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
check_statuses_lockable_domain check_statuses_lockable_domain
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
@ -85,7 +85,7 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
def test_registry_lock_on_lockable_domain def test_registry_lock_on_lockable_domain
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert_equal( assert_equal(
[DomainStatus::SERVER_UPDATE_PROHIBITED, [DomainStatus::SERVER_UPDATE_PROHIBITED,
@ -99,21 +99,21 @@ class DomainRegistryLockableTest < ActiveSupport::TestCase
end end
def test_registry_lock_cannot_be_applied_twice def test_registry_lock_cannot_be_applied_twice
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
refute(@domain.apply_registry_lock) refute(@domain.apply_registry_lock(extensions_prohibited: false))
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
assert(@domain.locked_by_registrant_at) assert(@domain.locked_by_registrant_at)
end end
def test_registry_lock_cannot_be_applied_on_pending_statuses def test_registry_lock_cannot_be_applied_on_pending_statuses
@domain.statuses << DomainStatus::PENDING_RENEW @domain.statuses << DomainStatus::PENDING_RENEW
refute(@domain.apply_registry_lock) refute(@domain.apply_registry_lock(extensions_prohibited: false))
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
refute(@domain.locked_by_registrant_at) refute(@domain.locked_by_registrant_at)
end end
def test_remove_registry_lock_on_locked_domain def test_remove_registry_lock_on_locked_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
assert_equal( assert_equal(
[DomainStatus::SERVER_UPDATE_PROHIBITED, [DomainStatus::SERVER_UPDATE_PROHIBITED,

View file

@ -17,7 +17,7 @@ class AdminAreaRegistryLockTest < JavaScriptApplicationSystemTestCase
end end
def test_can_remove_registry_lock_from_a_domain def test_can_remove_registry_lock_from_a_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
visit edit_admin_domain_path(@domain) visit edit_admin_domain_path(@domain)
click_link_or_button('Actions') click_link_or_button('Actions')
@ -34,7 +34,7 @@ class AdminAreaRegistryLockTest < JavaScriptApplicationSystemTestCase
end end
def test_cannot_remove_registry_lock_from_not_locked_domain def test_cannot_remove_registry_lock_from_not_locked_domain
@domain.apply_registry_lock @domain.apply_registry_lock(extensions_prohibited: false)
visit edit_admin_domain_path(@domain) visit edit_admin_domain_path(@domain)
@domain.remove_registry_lock @domain.remove_registry_lock

View file

@ -20,7 +20,7 @@ class AdminDomainsTestTest < ApplicationSystemTestCase
refute_text 'Registry lock time 2010-07-05 00:30' refute_text 'Registry lock time 2010-07-05 00:30'
lockable_domain = domains(:airport) lockable_domain = domains(:airport)
lockable_domain.apply_registry_lock lockable_domain.apply_registry_lock(extensions_prohibited: false)
visit admin_domain_path(lockable_domain) visit admin_domain_path(lockable_domain)
assert_text 'Registry lock time 2010-07-05 00:30' assert_text 'Registry lock time 2010-07-05 00:30'