This commit is contained in:
Martin Lensment 2014-09-16 17:58:51 +03:00
parent 168e6d2a01
commit 660eef414e
8 changed files with 55 additions and 18 deletions

View file

@ -6,8 +6,6 @@ class Domain < ActiveRecord::Base
has_many :domain_contacts, dependent: :delete_all, autosave: true
accepts_nested_attributes_for :domain_contacts, allow_destroy: true
has_many :tech_contacts, -> do
where(domain_contacts: { contact_type: DomainContact::TECH })
end, through: :domain_contacts, source: :contact
@ -50,6 +48,9 @@ class Domain < ActiveRecord::Base
attr_accessor :deleting_nameserver
validate :validate_nameserver_min_count, if: :deleting_nameserver
attr_accessor :adding_tech_contact
validate :validate_tech_contacts_max_count, if: :adding_tech_contact
def name=(value)
value.strip!
write_attribute(:name, SimpleIDN.to_unicode(value))

View file

@ -6,6 +6,17 @@ class DomainContact < ActiveRecord::Base
ADMIN = 'admin'
TYPES = [TECH, ADMIN]
# TODO: Fix EPP problems
validates :contact, uniqueness: { scope: [:domain_id, :contact_type] }
scope :admin, -> { where(contact_type: ADMIN) }
scope :tech, -> { where(contact_type: TECH) }
def admin?
contact_type == ADMIN
end
def tech?
contact_type == TECH
end
end