diff --git a/app/controllers/epp/commands_controller.rb b/app/controllers/epp/commands_controller.rb index fe2b0d054..4622c0b8c 100644 --- a/app/controllers/epp/commands_controller.rb +++ b/app/controllers/epp/commands_controller.rb @@ -11,4 +11,8 @@ class Epp::CommandsController < ApplicationController def check send("check_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") end + + def delete + send("delete_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}") + end end diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 8c0bbff50..29fce5d49 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -22,4 +22,22 @@ module Epp::ContactsHelper @contact.save render '/epp/contacts/create' end + + def delete_contact + ph = params_hash['epp']['command']['delete']['delete'] + + begin + @contact = Contact.where(code: ph[:id]).first + @contact.destroy + render '/epp/contacts/delete' + rescue NoMethodError => e + @code = '2303' + @msg = "Object does not exist" + render '/epp/error' + rescue + @code = '2400' + @msg = "Command failed" + render '/epp/error' + end + end end diff --git a/app/models/contact.rb b/app/models/contact.rb index b77f5309f..5d024f2cb 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -1,6 +1,7 @@ class Contact < ActiveRecord::Base #TODO Foreign contact will get email with activation link/username/temp password #TODO Phone number validation, in first phase very minimam in order to support current registries + has_many :addresses validate :ident_must_be_valid diff --git a/app/views/epp/contacts/delete.xml.builder b/app/views/epp/contacts/delete.xml.builder new file mode 100644 index 000000000..4490335a9 --- /dev/null +++ b/app/views/epp/contacts/delete.xml.builder @@ -0,0 +1,9 @@ +xml.epp_head do + xml.response do + xml.result('code' => '1000') do + xml.msg 'Command completed successfully' + end + + xml << render('/epp/shared/trID') + end +end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index ceba5d98b..c7ddf1dd7 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -17,15 +17,34 @@ describe 'EPP Contact', epp: true do end it 'updates a contact with same ident' do + Fabricate(:contact) response = epp_request('contacts/create.xml') expect(response[:result_code]).to eq('1000') expect(response[:msg]).to eq('Command completed successfully') expect(response[:clTRID]).to eq('ABC-12345') + expect(Contact.first.name).to eq("John Doe") + expect(Contact.count).to eq(1) end - #TODO tests for missing/invalid/etc ident + + it 'deletes contact' do + Fabricate(:contact) + response = epp_request('contacts/delete.xml') + expect(response[:result_code]).to eq('1000') + expect(response[:msg]).to eq('Command completed successfully') + expect(response[:clTRID]).to eq('ABC-12345') + + expect(Contact.count).to eq(0) + end + + it 'deletes an nil object' do + response = epp_request('contacts/delete.xml') + expect(response[:result_code]).to eq('2303') + expect(response[:msg]).to eq('Object does not exist') + end + end end diff --git a/spec/epp/requests/contacts/delete.xml b/spec/epp/requests/contacts/delete.xml new file mode 100644 index 000000000..023ebf76a --- /dev/null +++ b/spec/epp/requests/contacts/delete.xml @@ -0,0 +1,12 @@ + + + + + + sh8913 + + + ABC-12345 + + diff --git a/spec/fabricators/contact_fabricator.rb b/spec/fabricators/contact_fabricator.rb index 31715f979..61b40ae45 100644 --- a/spec/fabricators/contact_fabricator.rb +++ b/spec/fabricators/contact_fabricator.rb @@ -3,4 +3,5 @@ Fabricator(:contact) do phone '+372.12345678' email Faker::Internet.email ident '37605030299' + code 'sh8913' end