User form

This commit is contained in:
Martin Lensment 2014-09-30 12:28:16 +03:00
parent 14f9304c6d
commit 0e7e83134c
11 changed files with 252 additions and 6 deletions

View file

@ -51,7 +51,6 @@ class Domain < ActiveRecord::Base
validate :validate_domain_statuses_uniqueness, if: :new_record?
attr_accessor :owner_contact_typeahead
attr_accessor :registrar_typeahead
def name=(value)
value.strip!
@ -64,10 +63,6 @@ class Domain < ActiveRecord::Base
@owner_contact_typeahead || owner_contact.try(:name) || nil
end
def registrar_typeahead
@registrar_typeahead || registrar || nil
end
def pending_transfer
domain_transfers.find_by(status: DomainTransfer::PENDING)
end

View file

@ -8,4 +8,32 @@ class User < ActiveRecord::Base
belongs_to :role
belongs_to :registrar
validates :username, :password, presence: true
validates :identity_code, uniqueness: true, allow_blank: true
validate :registrar_presence
before_save :manage_registrar
attr_accessor :registrar_typeahead
def to_s
username
end
def registrar_typeahead
@registrar_typeahead || registrar || nil
end
private
def registrar_presence
if !admin && !registrar
errors.add(:registrar, :blank)
end
end
def manage_registrar
self.registrar = nil if admin?
end
end