62 lines
1.4 KiB
Ruby
62 lines
1.4 KiB
Ruby
class RecruitProfile
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
include Slug
|
|
|
|
EMPLOYEE=1
|
|
EMPLOYER=2
|
|
|
|
field :pseudo_member_id
|
|
field :email
|
|
field :first_name, as: :slug_title
|
|
field :last_name
|
|
field :user_type, type: Integer, default: 1
|
|
field :enabled, type: Boolean, :default => true
|
|
|
|
scope :employers, ->{ where(user_type: self::EMPLOYER) }
|
|
scope :employees, ->{ where(user_type: self::EMPLOYEE) }
|
|
|
|
has_one :employee_profile, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :employee_profile, :allow_destroy => true
|
|
|
|
has_one :employer_profile, :autosave => true, :dependent => :destroy
|
|
accepts_nested_attributes_for :employer_profile, :allow_destroy => true
|
|
|
|
|
|
def disable_user
|
|
pu = PseudoUser.where(:user_name => self.pseudo_member_id).first
|
|
pu.enabled = false
|
|
self.enabled = false
|
|
pu.save
|
|
self.save
|
|
end
|
|
|
|
def enable_user
|
|
pu = PseudoUser.where(:user_name => self.pseudo_member_id).first
|
|
pu.enabled = true
|
|
self.enabled = true
|
|
pu.save
|
|
self.save
|
|
end
|
|
|
|
def name
|
|
self.first_name + " " + self.last_name rescue self.email
|
|
end
|
|
|
|
def profile
|
|
if self.is_employer?
|
|
self.employer_profile
|
|
elsif self.is_employee?
|
|
self.employee_profile
|
|
end
|
|
end
|
|
|
|
def is_employer?
|
|
self.user_type == RecruitProfile::EMPLOYER
|
|
end
|
|
|
|
def is_employee?
|
|
self.user_type == RecruitProfile::EMPLOYEE
|
|
end
|
|
|
|
end |