2013-02-06 03:16:51 +08:00
|
|
|
class UserSerializer < BasicUserSerializer
|
2013-02-07 23:45:24 +08:00
|
|
|
|
|
|
|
attributes :name,
|
|
|
|
:email,
|
|
|
|
:last_posted_at,
|
|
|
|
:last_seen_at,
|
2013-02-06 03:16:51 +08:00
|
|
|
:bio_raw,
|
2013-02-07 23:45:24 +08:00
|
|
|
:bio_cooked,
|
|
|
|
:created_at,
|
|
|
|
:website,
|
2014-03-01 04:12:51 +08:00
|
|
|
:profile_background,
|
2014-05-28 01:54:04 +08:00
|
|
|
:location,
|
2013-02-07 23:45:24 +08:00
|
|
|
:can_edit,
|
2013-08-13 02:54:52 +08:00
|
|
|
:can_edit_username,
|
2013-09-08 10:42:41 +08:00
|
|
|
:can_edit_email,
|
2014-03-14 04:26:40 +08:00
|
|
|
:can_edit_name,
|
2013-02-07 23:45:24 +08:00
|
|
|
:stats,
|
2013-02-06 03:16:51 +08:00
|
|
|
:can_send_private_message_to_user,
|
|
|
|
:bio_excerpt,
|
2013-05-02 15:40:44 +08:00
|
|
|
:trust_level,
|
|
|
|
:moderator,
|
2013-06-26 06:39:20 +08:00
|
|
|
:admin,
|
2013-11-08 05:34:18 +08:00
|
|
|
:title,
|
|
|
|
:suspend_reason,
|
2014-03-28 16:49:30 +08:00
|
|
|
:suspended_till,
|
2014-06-02 10:59:54 +08:00
|
|
|
:uploaded_avatar_id,
|
2014-03-28 16:49:30 +08:00
|
|
|
:badge_count
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-05-22 00:03:51 +08:00
|
|
|
has_one :invited_by, embed: :object, serializer: BasicUserSerializer
|
2014-02-07 06:34:48 +08:00
|
|
|
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
2014-03-28 16:49:30 +08:00
|
|
|
has_many :featured_user_badges, embed: :ids, serializer: UserBadgeSerializer, root: :user_badges
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def self.private_attributes(*attrs)
|
2013-12-30 10:02:12 +08:00
|
|
|
attributes(*attrs)
|
2013-02-06 03:16:51 +08:00
|
|
|
attrs.each do |attr|
|
2013-02-07 23:45:24 +08:00
|
|
|
define_method "include_#{attr}?" do
|
2013-02-06 03:16:51 +08:00
|
|
|
can_edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_excerpt
|
2013-06-05 00:05:36 +08: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-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-07 23:45:24 +08:00
|
|
|
private_attributes :email,
|
2014-02-08 11:24:10 +08:00
|
|
|
:locale,
|
2013-05-21 04:52:37 +08:00
|
|
|
:email_digests,
|
|
|
|
:email_private_messages,
|
|
|
|
:email_direct,
|
2013-10-01 15:04:02 +08:00
|
|
|
:email_always,
|
2013-05-21 04:52:37 +08:00
|
|
|
:digest_after_days,
|
2014-02-07 08:06:35 +08:00
|
|
|
:mailing_list_mode,
|
2013-05-21 04:52:37 +08:00
|
|
|
:auto_track_topics_after_msecs,
|
|
|
|
:new_topic_duration_minutes,
|
|
|
|
:external_links_in_new_tab,
|
2013-06-15 14:58:24 +08:00
|
|
|
:dynamic_favicon,
|
2013-08-25 23:26:44 +08:00
|
|
|
:enable_quoting,
|
2014-01-02 14:58:49 +08:00
|
|
|
:muted_category_ids,
|
2014-01-06 08:57:17 +08:00
|
|
|
:tracked_category_ids,
|
2014-05-03 04:36:52 +08:00
|
|
|
:watched_category_ids,
|
2014-05-27 04:39:03 +08:00
|
|
|
:private_messages_stats,
|
2014-05-22 15:37:02 +08:00
|
|
|
:disable_jump_reply,
|
|
|
|
:gravatar_avatar_upload_id,
|
2014-06-02 10:59:54 +08:00
|
|
|
:custom_avatar_upload_id
|
2013-05-21 04:52:37 +08:00
|
|
|
|
2014-05-22 15:37:02 +08:00
|
|
|
def gravatar_avatar_upload_id
|
|
|
|
object.user_avatar.try(:gravatar_upload_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def custom_avatar_upload_id
|
|
|
|
object.user_avatar.try(:custom_upload_id)
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def auto_track_topics_after_msecs
|
|
|
|
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-14 14:32:58 +08:00
|
|
|
def new_topic_duration_minutes
|
|
|
|
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
|
|
|
end
|
2013-02-06 03:16:51 +08: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-13 02:54:52 +08:00
|
|
|
def can_edit_username
|
|
|
|
scope.can_edit_username?(object)
|
|
|
|
end
|
|
|
|
|
2013-09-08 10:42:41 +08:00
|
|
|
def can_edit_email
|
|
|
|
scope.can_edit_email?(object)
|
|
|
|
end
|
|
|
|
|
2014-03-14 04:26:40 +08:00
|
|
|
def can_edit_name
|
|
|
|
scope.can_edit_name?(object)
|
|
|
|
end
|
|
|
|
|
2014-05-28 01:54:04 +08:00
|
|
|
def location
|
|
|
|
object.user_profile.try(:location)
|
|
|
|
end
|
|
|
|
def include_location?
|
|
|
|
location.present?
|
|
|
|
end
|
|
|
|
|
2013-05-22 23:20:16 +08:00
|
|
|
def stats
|
|
|
|
UserAction.stats(object.id, scope)
|
|
|
|
end
|
|
|
|
|
2013-11-08 05:34:18 +08:00
|
|
|
def include_suspended?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
def include_suspend_reason?
|
|
|
|
object.suspended?
|
|
|
|
end
|
2014-01-02 14:58:49 +08:00
|
|
|
|
2013-11-08 05:34:18 +08:00
|
|
|
def include_suspended_till?
|
|
|
|
object.suspended?
|
|
|
|
end
|
|
|
|
|
2014-01-02 14:58:49 +08:00
|
|
|
def muted_category_ids
|
|
|
|
CategoryUser.lookup(object, :muted).pluck(:category_id)
|
|
|
|
end
|
|
|
|
|
2014-01-06 08:57:17 +08:00
|
|
|
def tracked_category_ids
|
|
|
|
CategoryUser.lookup(object, :tracking).pluck(:category_id)
|
|
|
|
end
|
|
|
|
|
2014-01-02 14:58:49 +08:00
|
|
|
def watched_category_ids
|
|
|
|
CategoryUser.lookup(object, :watching).pluck(:category_id)
|
|
|
|
end
|
2014-03-28 16:49:30 +08:00
|
|
|
|
2014-05-03 04:36:52 +08:00
|
|
|
def private_messages_stats
|
|
|
|
UserAction.private_messages_stats(object.id, scope)
|
|
|
|
end
|
|
|
|
|
2014-04-25 04:13:24 +08:00
|
|
|
def bio_cooked
|
|
|
|
object.bio_processed
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|