2014-05-28 01:54:04 +08:00
|
|
|
class UserProfile < ActiveRecord::Base
|
2014-06-10 13:19:08 +08:00
|
|
|
belongs_to :user, inverse_of: :user_profile
|
|
|
|
|
|
|
|
validates :user, presence: true
|
|
|
|
before_save :cook
|
2014-07-03 15:29:44 +08:00
|
|
|
after_save :assign_autobiographer
|
2014-06-10 13:19:08 +08:00
|
|
|
|
|
|
|
def bio_excerpt
|
|
|
|
excerpt = PrettyText.excerpt(bio_cooked, 350)
|
|
|
|
return excerpt if excerpt.blank? || user.has_trust_level?(:basic)
|
|
|
|
PrettyText.strip_links(excerpt)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_processed
|
|
|
|
return bio_cooked if bio_cooked.blank? || user.has_trust_level?(:basic)
|
|
|
|
PrettyText.strip_links(bio_cooked)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_summary
|
|
|
|
return nil unless bio_cooked.present?
|
|
|
|
Summarize.new(bio_cooked).summary
|
|
|
|
end
|
|
|
|
|
|
|
|
def recook_bio
|
|
|
|
self.bio_raw_will_change!
|
|
|
|
cook
|
|
|
|
end
|
|
|
|
|
2014-06-12 09:52:50 +08:00
|
|
|
def upload_profile_background(upload)
|
|
|
|
self.profile_background = upload.url
|
|
|
|
self.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_profile_background
|
|
|
|
self.profile_background = ""
|
|
|
|
self.save!
|
|
|
|
end
|
|
|
|
|
2014-07-03 15:29:44 +08:00
|
|
|
protected
|
|
|
|
|
|
|
|
def assign_autobiographer
|
|
|
|
if bio_raw_changed?
|
|
|
|
user.grant_autobiographer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-10 13:19:08 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def cook
|
|
|
|
if self.bio_raw.present?
|
|
|
|
self.bio_cooked = PrettyText.cook(self.bio_raw, omit_nofollow: user.has_trust_level?(:leader)) if bio_raw_changed?
|
|
|
|
else
|
|
|
|
self.bio_cooked = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-28 01:54:04 +08:00
|
|
|
end
|
2014-05-29 12:59:14 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: user_profiles
|
|
|
|
#
|
2014-07-03 15:29:44 +08:00
|
|
|
# user_id :integer not null, primary key
|
|
|
|
# location :string(255)
|
|
|
|
# website :string(255)
|
|
|
|
# bio_raw :text
|
|
|
|
# bio_cooked :text
|
|
|
|
# dismissed_banner_key :integer
|
|
|
|
# profile_background :string(255)
|
2014-05-29 12:59:14 +08:00
|
|
|
#
|