mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +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
|
end
|
||||||
|
|
||||||
def delete_contact
|
def delete_contact
|
||||||
#no deleting, implement PaperTrail or something similar.
|
Contact.transaction do
|
||||||
#TODO check for relation before 'destroying'
|
@contact = find_contact
|
||||||
@contact = find_contact
|
handle_errors(@contact) and return unless @contact
|
||||||
handle_errors(@contact) and return unless @contact
|
handle_errors(@contact) and return unless @contact.destroy_and_clean
|
||||||
@contact.destroy
|
|
||||||
render '/epp/contacts/delete'
|
render '/epp/contacts/delete'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_contact
|
def check_contact
|
||||||
|
|
|
@ -71,8 +71,32 @@ class Contact < ActiveRecord::Base
|
||||||
return false
|
return false
|
||||||
end
|
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
|
class << self
|
||||||
|
|
||||||
|
|
||||||
def extract_attributes ph, type=:create
|
def extract_attributes ph, type=:create
|
||||||
|
|
||||||
contact_hash = {
|
contact_hash = {
|
||||||
|
@ -107,4 +131,11 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def clean_up_address
|
||||||
|
address.destroy if address
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,6 +39,29 @@ describe Contact do
|
||||||
end
|
end
|
||||||
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
|
describe Contact, '#crID' do
|
||||||
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user)) }
|
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user)) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue