From 08a4650f4a2db17a78c1b8ff2e074cbc2ab3d4b6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 1 Sep 2014 11:48:24 +0300 Subject: [PATCH] Add domain deleting support --- app/helpers/epp/domains_helper.rb | 15 +++++++++++++++ app/models/domain.rb | 10 ++++------ db/schema.rb | 5 ----- spec/epp/domain_spec.rb | 9 +++++++++ spec/epp/requests/domains/delete.xml | 12 ++++++++++++ 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 spec/epp/requests/domains/delete.xml diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 17b2b36f5..962b69b49 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -68,6 +68,15 @@ module Epp::DomainsHelper render '/epp/domains/transfer' end + def delete_domain + @domain = find_domain + + handle_errors(@domain) and return unless @domain + handle_errors(@domain) and return unless @domain.destroy + + render '/epp/domains/success' + end + ### HELPER METHODS ### private @@ -127,6 +136,12 @@ module Epp::DomainsHelper xml_attrs_present?(@ph, [['name']]) end + ## DELETE + def validate_domain_delete_request + @ph = params_hash['epp']['command']['delete']['delete'] + xml_attrs_present?(@ph, [['name']]) + end + ## SHARED def find_domain(secure = { secure: true }) domain = Domain.find_by(name: @ph[:name], registrar: current_epp_user.registrar) if secure[:secure] == true diff --git a/app/models/domain.rb b/app/models/domain.rb index df9058cbb..94abcafa8 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -13,7 +13,7 @@ class Domain < ActiveRecord::Base belongs_to :registrar belongs_to :owner_contact, class_name: 'Contact' - has_many :domain_contacts + has_many :domain_contacts, dependent: :delete_all has_many :tech_contacts, -> do where(domain_contacts: { contact_type: DomainContact::TECH }) @@ -23,14 +23,14 @@ class Domain < ActiveRecord::Base where(domain_contacts: { contact_type: DomainContact::ADMIN }) end, through: :domain_contacts, source: :contact - has_many :domain_nameservers + has_many :domain_nameservers, dependent: :delete_all has_many :nameservers, through: :domain_nameservers has_many :domain_statuses, -> { joins(:setting).where(settings: { setting_group_id: SettingGroup.domain_statuses.id }) - } + }, dependent: :delete_all - has_many :domain_transfers + has_many :domain_transfers, dependent: :delete_all delegate :code, to: :owner_contact, prefix: true delegate :name, to: :registrar, prefix: true @@ -39,8 +39,6 @@ class Domain < ActiveRecord::Base validates :period, numericality: { only_integer: true } validates :name, :owner_contact, presence: true - validates_associated :nameservers - validate :validate_period validate :validate_nameservers_count validate :validate_admin_contacts_count diff --git a/db/schema.rb b/db/schema.rb index d4ed1d865..e1198b421 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -119,11 +119,6 @@ ActiveRecord::Schema.define(version: 20140828133057) do t.string "period_unit", limit: 1 end - create_table "domains_nameservers", force: true do |t| - t.integer "domain_id" - t.integer "nameserver_id" - end - create_table "epp_sessions", force: true do |t| t.string "session_id" t.text "data" diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index d4006959c..b73b9fe9e 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -439,6 +439,15 @@ describe 'EPP Domain', epp: true do expect(d.owner_contact_code).to eq('mak21') expect(d.auth_info).to eq('2BARfoo') end + + it 'does not delete domain if there are relations' do + expect(DomainContact.count).to eq(1) + response = epp_request('domains/delete.xml') + expect(response[:result_code]).to eq('1000') + + expect(Domain.first).to eq(nil) + expect(DomainContact.count).to eq(0) + end end it 'checks a domain' do diff --git a/spec/epp/requests/domains/delete.xml b/spec/epp/requests/domains/delete.xml new file mode 100644 index 000000000..868b4b24f --- /dev/null +++ b/spec/epp/requests/domains/delete.xml @@ -0,0 +1,12 @@ + + + + + + example.ee + + + ABC-12345 + +