Add ability for admin to remove registry lock

This commit is contained in:
Maciej Szlosarczyk 2018-08-08 15:43:29 +03:00
parent 4743b1e2a5
commit dffe865d89
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
10 changed files with 174 additions and 29 deletions

View file

@ -0,0 +1,22 @@
module Admin
module Domains
class RegistryLockController < BaseController
def destroy
set_domain
authorize! :manage, @domain
if @domain.remove_registry_lock
redirect_to edit_admin_domain_url(@domain), notice: t('admin.domains.registry_lock_delete.success')
else
redirect_to edit_admin_domain_url(@domain), alert: t('admin.domains.registry_lock_delete.error')
end
end
private
def set_domain
@domain = Domain.find(params[:domain_id])
end
end
end
end

View file

@ -5,26 +5,30 @@ module Concerns::Domain::Lockable
return unless registry_lockable? return unless registry_lockable?
return if locked_by_registrant? return if locked_by_registrant?
statuses << DomainStatus::SERVER_UPDATE_PROHIBITED transaction do
statuses << DomainStatus::SERVER_DELETE_PROHIBITED statuses << DomainStatus::SERVER_UPDATE_PROHIBITED
statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED statuses << DomainStatus::SERVER_DELETE_PROHIBITED
statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
save self.locked_by_registrant_at = Time.zone.now
save
end
end end
def registry_lockable? def registry_lockable?
(statuses & [ (statuses & [
DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::PENDING_DELETE_CONFIRMATION,
DomainStatus::PENDING_CREATE, DomainStatus::PENDING_CREATE,
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_DELETE, DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_RENEW, DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER, DomainStatus::PENDING_TRANSFER,
DomainStatus::FORCE_DELETE, DomainStatus::FORCE_DELETE,
]).empty? ]).empty?
end end
def locked_by_registrant? def locked_by_registrant?
return false unless locked_by_registrant_at
lock_statuses = [ lock_statuses = [
DomainStatus::SERVER_UPDATE_PROHIBITED, DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::SERVER_DELETE_PROHIBITED, DomainStatus::SERVER_DELETE_PROHIBITED,
@ -37,10 +41,13 @@ module Concerns::Domain::Lockable
def remove_registry_lock def remove_registry_lock
return unless locked_by_registrant? return unless locked_by_registrant?
statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED) transaction do
statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED) statuses.delete(DomainStatus::SERVER_UPDATE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED) statuses.delete(DomainStatus::SERVER_DELETE_PROHIBITED)
statuses.delete(DomainStatus::SERVER_TRANSFER_PROHIBITED)
self.locked_by_registrant_at = nil
save save
end
end end
end end

View file

@ -52,18 +52,29 @@ class DomainPresenter
def force_delete_toggle_btn def force_delete_toggle_btn
if !domain.force_delete_scheduled? if !domain.force_delete_scheduled?
view.content_tag(:a, view.t('admin.domains.force_delete_toggle_btn.schedule'), view.content_tag(:a, view.t('admin.domains.force_delete_toggle_btn.schedule'),
class: 'btn btn-default',
data: { data: {
toggle: 'modal', toggle: 'modal',
target: '.domain-edit-force-delete-dialog', target: '.domain-edit-force-delete-dialog',
} },
class: 'dropdown-item'
) )
else else
view.link_to(view.t('admin.domains.force_delete_toggle_btn.cancel'), view.link_to(view.t('admin.domains.force_delete_toggle_btn.cancel'),
view.admin_domain_force_delete_path(domain), view.admin_domain_force_delete_path(domain),
method: :delete, method: :delete,
data: { confirm: view.t('admin.domains.force_delete_toggle_btn.cancel_confirm') }, data: { confirm: view.t('admin.domains.force_delete_toggle_btn.cancel_confirm') },
class: 'btn btn-primary') class: 'dropdown-item')
end
end
def remove_registry_lock_btn
if domain.locked_by_registrant?
view.link_to(view.t('admin.domains.registry_lock_delete.btn'),
view.admin_domain_registry_lock_path(domain),
method: :delete,
data: { confirm: view.t('admin.domains.registry_lock_delete.confirm') },
class: 'dropdown-item')
end end
end end

View file

@ -6,12 +6,22 @@
Edit: <%= domain.name %> Edit: <%= domain.name %>
</h1> </h1>
</div> </div>
<div class="col-sm-7"> <div class="col-sm-7 text-right">
<h1 class="text-right text-center-xs"> <div class="btn-group">
<%= link_to t('.add_new_status_btn'), '#', class: 'btn btn-primary js-add-status' %>
<%= domain.force_delete_toggle_btn %>
<%= link_to t('.back_btn'), [:admin, @domain], class: 'btn btn-default' %> <%= link_to t('.back_btn'), [:admin, @domain], class: 'btn btn-default' %>
</h1> </div>
<div class="btn-group">
<button class="btn btn-primary" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><%= domain.force_delete_toggle_btn %></li>
<li><%= domain.remove_registry_lock_btn %></li>
<div class="divider"></div>
<li><%= link_to t('.add_new_status_btn'), '#', class: 'js-add-status' %></li>
</ul>
</div>
</div> </div>
</div> </div>
<hr> <hr>

View file

@ -33,6 +33,9 @@
<dt><%= t('.force_delete_time') %></dt> <dt><%= t('.force_delete_time') %></dt>
<dd><%= l(@domain.force_delete_at) %></dd> <dd><%= l(@domain.force_delete_at) %></dd>
<dt><%= t('.locked_by_registrant_at') %></dt>
<dd><%= l(@domain.locked_by_registrant_at) %></dd>
</dl> </dl>
</div> </div>
</div> </div>

View file

@ -23,6 +23,12 @@ en:
close_btn: Close dialog close_btn: Close dialog
submit_btn: Force delete domain submit_btn: Force delete domain
registry_lock_delete:
btn: Remove registry lock
confirm: Are you sure you want to remove registry lock that was set by registrant?
success: Registry lock removed
error: Registry lock could not be removed
versions: versions:
time: Time time: Time
registrant: Registrant registrant: Registrant
@ -34,6 +40,7 @@ en:
outzone_time: Outzone time outzone_time: Outzone time
delete_time: Delete time delete_time: Delete time
force_delete_time: Force delete time force_delete_time: Force delete time
locked_by_registrant_at: Registry lock time
admin_contacts: admin_contacts:
title: Admin. contacts title: Admin. contacts

View file

@ -182,6 +182,7 @@ Rails.application.routes.draw do
resources :pending_updates resources :pending_updates
resources :pending_deletes resources :pending_deletes
resource :force_delete, controller: 'domains/force_delete', only: %i[create destroy] resource :force_delete, controller: 'domains/force_delete', only: %i[create destroy]
resource :registry_lock, controller: 'domains/registry_lock', only: :destroy
end end
resources :domain_versions do resources :domain_versions do

View file

@ -4,7 +4,7 @@ class DomainLockableTest < ActiveSupport::TestCase
def setup def setup
super super
@domain = domains(:shop) @domain = domains(:airport)
end end
def test_registry_lock_on_lockable_domain def test_registry_lock_on_lockable_domain
@ -19,18 +19,21 @@ class DomainLockableTest < ActiveSupport::TestCase
) )
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
assert(@domain.locked_by_registrant_at)
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
refute(@domain.apply_registry_lock) refute(@domain.apply_registry_lock)
assert(@domain.locked_by_registrant?) assert(@domain.locked_by_registrant?)
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)
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
refute(@domain.locked_by_registrant_at)
end end
def test_remove_registry_lock_on_locked_domain def test_remove_registry_lock_on_locked_domain
@ -47,6 +50,7 @@ class DomainLockableTest < ActiveSupport::TestCase
assert_equal(["ok"], @domain.statuses) assert_equal(["ok"], @domain.statuses)
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
refute(@domain.locked_by_registrant_at)
end end
def test_remove_registry_lock_on_non_locked_domain def test_remove_registry_lock_on_non_locked_domain
@ -55,5 +59,14 @@ class DomainLockableTest < ActiveSupport::TestCase
assert_equal([], @domain.statuses) assert_equal([], @domain.statuses)
refute(@domain.locked_by_registrant?) refute(@domain.locked_by_registrant?)
refute(@domain.locked_by_registrant_at)
end
def test_registry_lock_cannot_be_removed_if_statuses_were_set_by_admin
@domain.statuses << DomainStatus::SERVER_UPDATE_PROHIBITED
@domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED
@domain.statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
refute(@domain.remove_registry_lock)
end end
end end

View file

@ -0,0 +1,55 @@
require 'test_helper'
class RegistryLockTest < JavaScriptApplicationSystemTestCase
def setup
super
WebMock.allow_net_connect!
sign_in users(:admin)
travel_to Time.zone.parse('2010-07-05 00:30:00')
@domain = domains(:airport)
end
def teardown
travel_back
end
def test_does_not_have_link_when_domain_is_not_locked
visit edit_admin_domain_path(@domain)
refute(page.has_link?('Remove registry lock'))
end
def test_can_remove_registry_lock_from_a_domain
@domain.apply_registry_lock
visit edit_admin_domain_path(@domain)
click_link_or_button('Actions')
assert(page.has_link?('Remove registry lock'))
accept_confirm('Are you sure you want to remove registry lock that was set by registrant?') do
click_link_or_button('Remove registry lock')
end
assert_text('Registry lock removed')
@domain.reload
refute @domain.locked_by_registrant?
end
def test_cannot_remove_registry_lock_from_not_locked_domain
@domain.apply_registry_lock
visit edit_admin_domain_path(@domain)
@domain.remove_registry_lock
refute @domain.locked_by_registrant?
click_link_or_button('Actions')
assert(page.has_link?('Remove registry lock'))
accept_confirm('Are you sure you want to remove registry lock that was set by registrant?') do
click_link_or_button('Remove registry lock')
end
assert_text('Registry lock could not be removed')
end
end

View file

@ -3,11 +3,27 @@ require 'test_helper'
class AdminDomainsTestTest < ApplicationSystemTestCase class AdminDomainsTestTest < ApplicationSystemTestCase
setup do setup do
sign_in users(:admin) sign_in users(:admin)
travel_to Time.zone.parse('2010-07-05 00:30:00')
@domain = domains(:shop)
end
teardown do
travel_back
end end
def test_shows_details def test_shows_details
domain = domains(:shop) visit admin_domain_path(@domain)
visit admin_domain_path(domain) assert_field nil, with: @domain.transfer_code
assert_field nil, with: domain.transfer_code end
def test_admin_registry_lock_date
visit admin_domain_path(@domain)
refute_text 'Registry lock time 2010-07-05 00:30'
lockable_domain = domains(:airport)
lockable_domain.apply_registry_lock
visit admin_domain_path(lockable_domain)
assert_text 'Registry lock time 2010-07-05 00:30'
end end
end end