diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb new file mode 100644 index 000000000..c3ec073b6 --- /dev/null +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -0,0 +1,37 @@ +module Api + module V1 + module Registrant + class RegistryLocksController < BaseController + before_action :set_domain + + def create + if @domain.apply_registry_lock + render json: @domain + else + render json: { errors: [{ base: 'Domain cannot be locked' }] }, + status: :unprocessable_entity + end + end + + def delete + if @domain.remove_registry_lock + render json: @domain + else + render json: { errors: [{ base: 'Domain cannot be unlocked' }] }, + status: :unprocessable_entity + end + end + + private + + def set_domain + @domain = Domain.find_by(uuid: params[:domain_uuid]) + + return if @domain + render json: { errors: [{ base: ['Domain not found'] }] }, + status: :not_found and return + end + end + end + end +end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 4a41a06a3..5ae622353 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -14,6 +14,11 @@ class DomainPresenter html += " #{label}" end + if domain.locked_by_registrant? + label = view.content_tag(:span, 'registryLock', class: 'label label-danger') + html += " #{label}" + end + html.html_safe end diff --git a/app/views/admin/domains/edit.html.erb b/app/views/admin/domains/edit.html.erb index 335d3b574..19c093f78 100644 --- a/app/views/admin/domains/edit.html.erb +++ b/app/views/admin/domains/edit.html.erb @@ -1,12 +1,12 @@ <% domain = DomainPresenter.new(domain: @domain, view: self) %>
-
+

- Edit: <%= domain.name %> + Edit: <%= domain.name_with_status %>

-
+
<%= link_to t('.back_btn'), [:admin, @domain], class: 'btn btn-default' %>
diff --git a/app/views/admin/domains/show.html.erb b/app/views/admin/domains/show.html.erb index 1501b35bb..f712a8b15 100644 --- a/app/views/admin/domains/show.html.erb +++ b/app/views/admin/domains/show.html.erb @@ -13,7 +13,7 @@
<%= link_to t('.edit_btn'), edit_admin_domain_path(@domain), class: 'btn btn-primary' %> <%= link_to t('.history_btn'), admin_domain_domain_versions_path(@domain), - class: 'btn btn-primary' %> + class: 'btn btn-primary' %>
diff --git a/config/locales/admin/domains.en.yml b/config/locales/admin/domains.en.yml index bbe23e990..bb157fe9c 100644 --- a/config/locales/admin/domains.en.yml +++ b/config/locales/admin/domains.en.yml @@ -25,7 +25,8 @@ en: registry_lock_delete: btn: Remove registry lock - confirm: Are you sure you want to remove registry lock that was set by registrant? + banner: Domain has a registry lock set by registrant. + confirm: Are you sure you want to remove the registry lock? success: Registry lock removed error: Registry lock could not be removed diff --git a/config/routes.rb b/config/routes.rb index c79822f28..63f71a344 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,7 +23,9 @@ Rails.application.routes.draw do namespace :registrant do post 'auth/eid', to: 'auth#eid' - resources :domains, only: [:index] + resources :domains, only: [:index], param: :uuid do + resource :registry_lock, only: [:create, :destroy] + end end end end diff --git a/test/integration/api/registrant/registrant_api_domain_registry_lock_test.rb b/test/integration/api/registrant/registrant_api_domain_registry_lock_test.rb new file mode 100644 index 000000000..d05dec3d5 --- /dev/null +++ b/test/integration/api/registrant/registrant_api_domain_registry_lock_test.rb @@ -0,0 +1,28 @@ +require 'test_helper' +require 'auth_token/auth_token_creator' + +class RegistrantApiDomainRegistryLockTest < ApplicationIntegrationTest + def setup + super + + @user = users(:registrant) + @domain = domains(:airport) + @auth_headers = { 'HTTP_AUTHORIZATION' => auth_token } + end + + def test_can_lock_a_not_locked_domain + assert(@domain.locked_by_registrant?) + end + + def test_cannot_lock_an_already_locked_domain + assert(@domain.locked_by_registrant?) + end + + private + + def auth_token + token_creator = AuthTokenCreator.create_with_defaults(@user) + hash = token_creator.token_in_hash + "Bearer #{hash[:access_token]}" + end +end diff --git a/test/system/admin_area/domains/registry_lock_test.rb b/test/system/admin_area/domains/registry_lock_test.rb index 6c741ba60..3fc053f6a 100644 --- a/test/system/admin_area/domains/registry_lock_test.rb +++ b/test/system/admin_area/domains/registry_lock_test.rb @@ -26,7 +26,7 @@ class RegistryLockTest < JavaScriptApplicationSystemTestCase 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 + accept_confirm('Are you sure you want to remove registry lock?') do click_link_or_button('Remove registry lock') end