mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Improved contact deleting
This commit is contained in:
parent
17f7a609cc
commit
ef90dfc70b
3 changed files with 61 additions and 6 deletions
|
@ -18,12 +18,13 @@ module Epp::ContactsHelper
|
|||
end
|
||||
|
||||
def delete_contact
|
||||
#no deleting, implement PaperTrail or something similar.
|
||||
#TODO check for relation before 'destroying'
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless @contact
|
||||
@contact.destroy
|
||||
render '/epp/contacts/delete'
|
||||
Contact.transaction do
|
||||
@contact = find_contact
|
||||
handle_errors(@contact) and return unless @contact
|
||||
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
||||
|
||||
render '/epp/contacts/delete'
|
||||
end
|
||||
end
|
||||
|
||||
def check_contact
|
||||
|
|
|
@ -71,8 +71,32 @@ class Contact < ActiveRecord::Base
|
|||
return false
|
||||
end
|
||||
|
||||
def get_relation( model = :domain_contacts )
|
||||
send(model)
|
||||
rescue NoMethodError => e
|
||||
nil
|
||||
end
|
||||
|
||||
def has_relation( model = :domain_contacts )
|
||||
relation = get_relation(model)
|
||||
return true unless relation.nil? || relation.blank?
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
|
||||
#should use only in transaction
|
||||
def destroy_and_clean
|
||||
clean_up_address
|
||||
destroy
|
||||
rescue
|
||||
errors.add(:contact, msg: I18n.t('errors.messages.epp_command_failed'), value: { obj: 'contact', val: code })
|
||||
false
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
|
||||
def extract_attributes ph, type=:create
|
||||
|
||||
contact_hash = {
|
||||
|
@ -107,4 +131,11 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_up_address
|
||||
address.destroy if address
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -39,6 +39,29 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
describe Contact, '#get_relation' do
|
||||
before(:each) { Fabricate(:contact) }
|
||||
it 'should return nil if no method' do
|
||||
expect(Contact.first.get_relation(:chewbacca)).to eq nil
|
||||
end
|
||||
|
||||
it 'should return domain_contacts by default' do
|
||||
expect(Contact.first.get_relation).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
describe Contact, '#has_relation' do
|
||||
before(:each) { Fabricate(:domain) }
|
||||
it 'should return false if no relation' do
|
||||
expect(Contact.last.has_relation(:chewbacca)).to eq false
|
||||
end
|
||||
|
||||
it 'should return true if relation' do
|
||||
expect(Contact.last.has_relation).to eq true
|
||||
expect(Contact.last.has_relation(:address)).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
describe Contact, '#crID' do
|
||||
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user)) }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue