Add domain deleting support

This commit is contained in:
Martin Lensment 2014-09-01 11:48:24 +03:00
parent a9df2c82b1
commit 08a4650f4a
5 changed files with 40 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<delete>
<domain:delete
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
</domain:delete>
</delete>
<clTRID>ABC-12345</clTRID>
</command>
</epp>