mirror of
https://github.com/internetee/registry.git
synced 2025-05-30 09:30:03 +02:00
Prevent domain deleting if status prohibits it
This commit is contained in:
parent
0096968265
commit
b4602e701c
7 changed files with 48 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
class Admin::DomainsController < ApplicationController
|
class Admin::DomainsController < ApplicationController
|
||||||
before_action :set_domain, only: [:show, :edit, :update]
|
before_action :set_domain, only: [:show, :edit, :update, :destroy]
|
||||||
|
before_action :verify_deletion, only: [:destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@domain = Domain.new
|
@domain = Domain.new
|
||||||
|
@ -37,6 +38,16 @@ class Admin::DomainsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @domain.destroy
|
||||||
|
flash[:notice] = I18n.t('shared.domain_deleted')
|
||||||
|
redirect_to admin_domains_path
|
||||||
|
else
|
||||||
|
flash[:alert] = I18n.t('shared.failed_to_delete_domain')
|
||||||
|
redirect_to [:admin, @domain]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_domain
|
def set_domain
|
||||||
|
@ -46,5 +57,11 @@ class Admin::DomainsController < ApplicationController
|
||||||
def domain_params
|
def domain_params
|
||||||
params.require(:domain).permit(:name, :period, :period_unit, :registrar_id, :owner_contact_id)
|
params.require(:domain).permit(:name, :period, :period_unit, :registrar_id, :owner_contact_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verify_deletion
|
||||||
|
return if @domain.can_be_deleted?
|
||||||
|
flash[:alert] = I18n.t('shared.domain_status_prohibits_deleting')
|
||||||
|
redirect_to [:admin, @domain]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ module Epp::DomainsHelper
|
||||||
@domain = find_domain
|
@domain = find_domain
|
||||||
|
|
||||||
handle_errors(@domain) and return unless @domain
|
handle_errors(@domain) and return unless @domain
|
||||||
|
handle_errors(@domain) and return unless @domain.can_be_deleted?
|
||||||
handle_errors(@domain) and return unless @domain.destroy
|
handle_errors(@domain) and return unless @domain.destroy
|
||||||
|
|
||||||
render '/epp/domains/success'
|
render '/epp/domains/success'
|
||||||
|
|
|
@ -67,7 +67,6 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
def can_be_deleted?
|
def can_be_deleted?
|
||||||
(domain_statuses.pluck(:value) & %W(
|
(domain_statuses.pluck(:value) & %W(
|
||||||
#{DomainStatus::CLIENT_DELETE_PROHIBITED}
|
|
||||||
#{DomainStatus::SERVER_DELETE_PROHIBITED}
|
#{DomainStatus::SERVER_DELETE_PROHIBITED}
|
||||||
)).empty?
|
)).empty?
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,9 @@ class Epp::EppDomain < Domain
|
||||||
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
|
[:name_dirty, :taken, { value: { obj: 'name', val: name_dirty } }],
|
||||||
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }]
|
[:name_dirty, :reserved, { value: { obj: 'name', val: name_dirty } }]
|
||||||
],
|
],
|
||||||
|
'2304' => [
|
||||||
|
[:base, :domain_status_prohibits_operation]
|
||||||
|
],
|
||||||
'2306' => [ # Parameter policy error
|
'2306' => [ # Parameter policy error
|
||||||
[:owner_contact, :blank],
|
[:owner_contact, :blank],
|
||||||
[:admin_contacts, :out_of_range]
|
[:admin_contacts, :out_of_range]
|
||||||
|
@ -237,6 +240,18 @@ class Epp::EppDomain < Domain
|
||||||
add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match'))
|
add_epp_error('2306', 'curExpDate', cur_exp_date, I18n.t('errors.messages.epp_exp_dates_do_not_match'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
### ABILITIES ###
|
||||||
|
def can_be_deleted?
|
||||||
|
begin
|
||||||
|
errors.add(:base, :domain_status_prohibits_operation)
|
||||||
|
return false
|
||||||
|
end if (domain_statuses.pluck(:value) & %W(
|
||||||
|
#{DomainStatus::CLIENT_DELETE_PROHIBITED}
|
||||||
|
)).any?
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
## SHARED
|
## SHARED
|
||||||
|
|
||||||
# For domain transfer
|
# For domain transfer
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
.col-sm-6
|
.col-sm-6
|
||||||
%h2.text-right.text-center-xs
|
%h2.text-right.text-center-xs
|
||||||
= link_to(t('shared.edit'), edit_admin_domain_path(@domain), class: 'btn btn-primary')
|
= link_to(t('shared.edit'), edit_admin_domain_path(@domain), class: 'btn btn-primary')
|
||||||
= link_to(t('shared.delete'), root_path, method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger')
|
= link_to(t('shared.delete'), admin_domain_path(@domain), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-danger')
|
||||||
|
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
|
|
|
@ -71,6 +71,8 @@ en:
|
||||||
|
|
||||||
epp_domain: &epp_domain_ar_attributes
|
epp_domain: &epp_domain_ar_attributes
|
||||||
attributes:
|
attributes:
|
||||||
|
base:
|
||||||
|
domain_status_prohibits_operation: 'Domain status prohibits operation'
|
||||||
name_dirty:
|
name_dirty:
|
||||||
invalid: 'Domain name is invalid'
|
invalid: 'Domain name is invalid'
|
||||||
reserved: 'Domain name is reserved or restricted'
|
reserved: 'Domain name is reserved or restricted'
|
||||||
|
@ -238,3 +240,6 @@ en:
|
||||||
failed_to_delete_status: 'Failed to delete status!'
|
failed_to_delete_status: 'Failed to delete status!'
|
||||||
tech_contact: 'Tech contact'
|
tech_contact: 'Tech contact'
|
||||||
new_domain_contact: 'New contact'
|
new_domain_contact: 'New contact'
|
||||||
|
domain_status_prohibits_deleting: 'Domain status prohibits deleting'
|
||||||
|
domain_deleted: 'Domain deleted!'
|
||||||
|
failed_to_delete_domain: 'Failed to delete domain!'
|
||||||
|
|
|
@ -567,6 +567,14 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(Domain.first).to eq(nil)
|
expect(Domain.first).to eq(nil)
|
||||||
expect(DomainContact.count).to eq(0)
|
expect(DomainContact.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not delete domain with specific status' do
|
||||||
|
d = Domain.first
|
||||||
|
d.domain_statuses.create(value: DomainStatus::CLIENT_DELETE_PROHIBITED)
|
||||||
|
response = epp_request(domain_delete_xml, :xml)
|
||||||
|
expect(response[:result_code]).to eq('2304')
|
||||||
|
expect(response[:msg]).to eq('Domain status prohibits operation')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'checks a domain' do
|
it 'checks a domain' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue