mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
Relation check for contact#delete
This commit is contained in:
parent
c166967467
commit
fdf9301d41
4 changed files with 35 additions and 14 deletions
|
@ -7,6 +7,7 @@ class Contact < ActiveRecord::Base
|
|||
EPP_CODE_MAP = {
|
||||
'2302' => ['Contact id already exists'],
|
||||
'2303' => [:not_found, :epp_obj_does_not_exist],
|
||||
'2305' => ['Object association prohibits operation'],
|
||||
'2005' => ['Phone nr is invalid', 'Email is invalid']
|
||||
}
|
||||
|
||||
|
@ -71,6 +72,12 @@ class Contact < ActiveRecord::Base
|
|||
return false
|
||||
end
|
||||
|
||||
#Find a way to use self.domains with contact
|
||||
def domains_owned
|
||||
Domain.find_by(owner_contact_id: id)
|
||||
end
|
||||
|
||||
#TODO Refactor the relation methods to something more sensible
|
||||
def get_relation( model = :domain_contacts )
|
||||
send(model)
|
||||
rescue NoMethodError => e
|
||||
|
@ -83,15 +90,15 @@ class Contact < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
|
||||
|
||||
#should use only in transaction
|
||||
def destroy_and_clean
|
||||
clean_up_address
|
||||
|
||||
if has_relation(:domain_contacts) || domains_owned.present?
|
||||
errors.add(:contact, msg: I18n.t('errors.messages.epp_obj_association_error'), value: { obj: 'contact', val: code })
|
||||
return false
|
||||
end
|
||||
destroy
|
||||
rescue
|
||||
errors.add(:contact, msg: I18n.t('errors.messages.epp_command_failed'), value: { obj: 'contact', val: code })
|
||||
false
|
||||
end
|
||||
|
||||
class << self
|
||||
|
|
|
@ -9,12 +9,11 @@ xml.epp_head do
|
|||
xml.tag!('contact:name', @contact.name)
|
||||
xml.tag!('contact:org', @contact.org_name)
|
||||
xml.tag!('contact:addr') do
|
||||
@contact.address do |address|
|
||||
xml.tag!('contact:street', address.street) if address.street
|
||||
xml.tag!('contact:street', address.street2) if address.street2
|
||||
xml.tag!('contact:street', address.street3) if address.street3
|
||||
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
|
||||
end
|
||||
address = @contact.address
|
||||
xml.tag!('contact:street', address.street) if address.street
|
||||
xml.tag!('contact:street', address.street2) if address.street2
|
||||
xml.tag!('contact:street', address.street3) if address.street3
|
||||
xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil?
|
||||
end
|
||||
xml.tag!('contact:voice', @contact.phone)
|
||||
xml.tag!('contact:fax', @contact.fax)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue