2013-02-05 13:16:51 -06:00
|
|
|
class UserSerializer < BasicUserSerializer
|
2013-02-07 09:45:24 -06:00
|
|
|
|
|
|
|
attributes :name,
|
|
|
|
:email,
|
|
|
|
:last_posted_at,
|
|
|
|
:last_seen_at,
|
2013-02-05 13:16:51 -06:00
|
|
|
:bio_raw,
|
2013-02-07 09:45:24 -06:00
|
|
|
:bio_cooked,
|
|
|
|
:created_at,
|
|
|
|
:website,
|
|
|
|
:can_edit,
|
|
|
|
:stream,
|
|
|
|
:stats,
|
2013-02-05 13:16:51 -06:00
|
|
|
:can_send_private_message_to_user,
|
|
|
|
:bio_excerpt,
|
|
|
|
:invited_by,
|
|
|
|
:trust_level
|
|
|
|
|
|
|
|
|
|
|
|
def self.private_attributes(*attrs)
|
|
|
|
attributes *attrs
|
|
|
|
attrs.each do |attr|
|
2013-02-07 09:45:24 -06:00
|
|
|
define_method "include_#{attr}?" do
|
2013-02-05 13:16:51 -06:00
|
|
|
can_edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_excerpt
|
|
|
|
e = object.bio_excerpt
|
2013-02-07 09:45:24 -06:00
|
|
|
unless e && e.length > 0
|
2013-02-05 13:16:51 -06:00
|
|
|
e = if scope.user && scope.user.id == object.id
|
|
|
|
I18n.t('user_profile.no_info_me', username_lower: object.username_lower)
|
|
|
|
else
|
|
|
|
I18n.t('user_profile.no_info_other', name: object.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
e
|
|
|
|
end
|
|
|
|
|
2013-02-07 09:45:24 -06:00
|
|
|
private_attributes :email,
|
|
|
|
:email_digests,
|
|
|
|
:email_private_messages,
|
2013-02-05 13:16:51 -06:00
|
|
|
:email_direct,
|
|
|
|
:digest_after_days,
|
2013-02-14 00:32:58 -06:00
|
|
|
:auto_track_topics_after_msecs,
|
2013-03-12 22:06:58 -05:00
|
|
|
:new_topic_duration_minutes,
|
|
|
|
:external_links_in_new_tab,
|
|
|
|
:enable_quoting
|
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
def auto_track_topics_after_msecs
|
|
|
|
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
|
|
|
end
|
2013-02-25 10:42:20 -06:00
|
|
|
|
2013-02-14 00:32:58 -06:00
|
|
|
def new_topic_duration_minutes
|
|
|
|
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
def can_send_private_message_to_user
|
|
|
|
scope.can_send_private_message?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stats
|
|
|
|
UserAction.stats(object.id, scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stream
|
2013-04-12 02:55:45 -05:00
|
|
|
UserAction.stream(user_id: object.id, offset: 0, limit: 60,
|
|
|
|
guardian: scope, ignore_private_messages: true)
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit
|
|
|
|
scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|