2013-02-05 14:16:51 -05:00
|
|
|
class UserSerializer < BasicUserSerializer
|
2013-02-07 10:45:24 -05:00
|
|
|
|
|
|
|
attributes :name,
|
|
|
|
:email,
|
|
|
|
:last_posted_at,
|
|
|
|
:last_seen_at,
|
2013-02-05 14:16:51 -05:00
|
|
|
:bio_raw,
|
2013-02-07 10:45:24 -05:00
|
|
|
:bio_cooked,
|
|
|
|
:created_at,
|
|
|
|
:website,
|
|
|
|
:can_edit,
|
2013-08-12 14:54:52 -04:00
|
|
|
:can_edit_username,
|
2013-09-07 22:42:41 -04:00
|
|
|
:can_edit_email,
|
2013-02-07 10:45:24 -05:00
|
|
|
:stats,
|
2013-02-05 14:16:51 -05:00
|
|
|
:can_send_private_message_to_user,
|
|
|
|
:bio_excerpt,
|
2013-05-02 03:40:44 -04:00
|
|
|
:trust_level,
|
|
|
|
:moderator,
|
2013-06-25 18:39:20 -04:00
|
|
|
:admin,
|
2013-11-07 16:34:18 -05:00
|
|
|
:title,
|
|
|
|
:suspend_reason,
|
|
|
|
:suspended_till
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-05-21 12:03:51 -04:00
|
|
|
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def self.private_attributes(*attrs)
|
|
|
|
attributes *attrs
|
|
|
|
attrs.each do |attr|
|
2013-02-07 10:45:24 -05:00
|
|
|
define_method "include_#{attr}?" do
|
2013-02-05 14:16:51 -05:00
|
|
|
can_edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_excerpt
|
2013-06-04 12:05:36 -04:00
|
|
|
# If they have a bio return it
|
|
|
|
excerpt = object.bio_excerpt
|
|
|
|
return excerpt if excerpt.present?
|
|
|
|
|
|
|
|
# Without a bio, determine what message to show
|
|
|
|
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)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-07 10:45:24 -05:00
|
|
|
private_attributes :email,
|
2013-05-20 16:52:37 -04:00
|
|
|
:email_digests,
|
|
|
|
:email_private_messages,
|
|
|
|
:email_direct,
|
2013-10-01 03:04:02 -04:00
|
|
|
:email_always,
|
2013-05-20 16:52:37 -04:00
|
|
|
:digest_after_days,
|
|
|
|
:auto_track_topics_after_msecs,
|
|
|
|
:new_topic_duration_minutes,
|
|
|
|
:external_links_in_new_tab,
|
2013-06-15 02:58:24 -04:00
|
|
|
:dynamic_favicon,
|
2013-08-25 11:26:44 -04:00
|
|
|
:enable_quoting,
|
|
|
|
:use_uploaded_avatar,
|
|
|
|
:has_uploaded_avatar,
|
|
|
|
:gravatar_template,
|
|
|
|
:uploaded_avatar_template
|
2013-05-20 16:52:37 -04:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def auto_track_topics_after_msecs
|
|
|
|
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-14 01:32:58 -05:00
|
|
|
def new_topic_duration_minutes
|
|
|
|
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def can_send_private_message_to_user
|
|
|
|
scope.can_send_private_message?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_edit
|
|
|
|
scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2013-08-12 14:54:52 -04:00
|
|
|
def can_edit_username
|
|
|
|
scope.can_edit_username?(object)
|
|
|
|
end
|
|
|
|
|
2013-09-07 22:42:41 -04:00
|
|
|
def can_edit_email
|
|
|
|
scope.can_edit_email?(object)
|
|
|
|
end
|
|
|
|
|
2013-05-22 11:20:16 -04:00
|
|
|
def stats
|
|
|
|
UserAction.stats(object.id, scope)
|
|
|
|
end
|
|
|
|
|
2013-08-25 11:26:44 -04:00
|
|
|
def gravatar_template
|
|
|
|
User.gravatar_template(object.email)
|
|
|
|
end
|
|
|
|
|
2013-11-07 16:34:18 -05:00
|
|
|
def include_suspended?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
def include_suspend_reason?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
def include_suspended_till?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|