2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-19 22:11:52 -06:00
|
|
|
class UserSummarySerializer < ApplicationSerializer
|
2020-11-17 06:07:16 -06:00
|
|
|
class TopicSerializer < BasicTopicSerializer
|
|
|
|
attributes :category_id, :like_count, :created_at
|
2016-01-19 22:11:52 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
class ReplySerializer < ApplicationSerializer
|
|
|
|
attributes :post_number, :like_count, :created_at
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
end
|
|
|
|
|
2016-04-13 16:02:51 -05:00
|
|
|
class LinkSerializer < ApplicationSerializer
|
2016-04-20 15:58:30 -05:00
|
|
|
attributes :url, :title, :clicks, :post_number
|
|
|
|
has_one :topic, serializer: TopicSerializer
|
|
|
|
|
|
|
|
def post_number
|
|
|
|
object.post.post_number
|
|
|
|
end
|
2016-04-13 16:02:51 -05:00
|
|
|
end
|
|
|
|
|
2019-01-11 12:09:06 -06:00
|
|
|
class UserWithCountSerializer < ApplicationSerializer
|
2021-04-27 14:09:32 -05:00
|
|
|
attributes :id,
|
|
|
|
:username,
|
|
|
|
:name,
|
|
|
|
:count,
|
|
|
|
:avatar_template,
|
|
|
|
:admin,
|
|
|
|
:moderator,
|
|
|
|
:trust_level,
|
2021-07-08 02:46:21 -05:00
|
|
|
:flair_name,
|
|
|
|
:flair_url,
|
|
|
|
:flair_bg_color,
|
|
|
|
:flair_color,
|
2021-04-27 14:09:32 -05:00
|
|
|
:primary_group_name
|
2019-01-11 12:09:06 -06:00
|
|
|
|
2019-01-13 19:30:44 -06:00
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
2019-01-11 12:09:06 -06:00
|
|
|
def avatar_template
|
|
|
|
User.avatar_template(object[:username], object[:uploaded_avatar_id])
|
|
|
|
end
|
2021-04-27 14:09:32 -05:00
|
|
|
|
2021-07-08 02:46:21 -05:00
|
|
|
def flair_name
|
|
|
|
object.flair_group&.name
|
2021-04-27 14:09:32 -05:00
|
|
|
end
|
|
|
|
|
2021-07-08 02:46:21 -05:00
|
|
|
def flair_url
|
|
|
|
object.flair_group&.flair_url
|
2021-04-27 14:09:32 -05:00
|
|
|
end
|
|
|
|
|
2021-07-08 02:46:21 -05:00
|
|
|
def flair_bg_color
|
|
|
|
object.flair_group&.flair_bg_color
|
|
|
|
end
|
|
|
|
|
|
|
|
def flair_color
|
|
|
|
object.flair_group&.flair_color
|
2021-04-27 14:09:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def primary_group_name
|
|
|
|
object.primary_group&.name
|
|
|
|
end
|
2016-04-13 16:02:51 -05:00
|
|
|
end
|
|
|
|
|
2018-07-18 15:37:50 -05:00
|
|
|
class CategoryWithCountsSerializer < ApplicationSerializer
|
2023-01-09 06:20:10 -06:00
|
|
|
attributes :topic_count,
|
|
|
|
:post_count,
|
|
|
|
:id,
|
|
|
|
:name,
|
|
|
|
:color,
|
|
|
|
:text_color,
|
|
|
|
:slug,
|
|
|
|
:read_restricted,
|
|
|
|
:parent_category_id
|
2018-07-18 15:37:50 -05:00
|
|
|
end
|
|
|
|
|
2016-01-19 22:11:52 -06:00
|
|
|
has_many :topics, serializer: TopicSerializer
|
|
|
|
has_many :replies, serializer: ReplySerializer, embed: :object
|
2016-04-13 16:02:51 -05:00
|
|
|
has_many :links, serializer: LinkSerializer, embed: :object
|
2016-05-04 15:47:48 -05:00
|
|
|
has_many :most_liked_by_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_liked_users, serializer: UserWithCountSerializer, embed: :object
|
|
|
|
has_many :most_replied_to_users, serializer: UserWithCountSerializer, embed: :object
|
2016-04-20 15:58:30 -05:00
|
|
|
has_many :badges, serializer: UserBadgeSerializer, embed: :object
|
2018-07-18 15:37:50 -05:00
|
|
|
has_many :top_categories, serializer: CategoryWithCountsSerializer, embed: :object
|
2016-01-19 22:11:52 -06:00
|
|
|
|
2016-03-30 11:05:16 -05:00
|
|
|
attributes :likes_given,
|
|
|
|
:likes_received,
|
2017-11-17 16:53:22 -06:00
|
|
|
:topics_entered,
|
2016-03-30 11:05:16 -05:00
|
|
|
:posts_read_count,
|
|
|
|
:days_visited,
|
|
|
|
:topic_count,
|
|
|
|
:post_count,
|
2016-04-13 16:02:51 -05:00
|
|
|
:time_read,
|
2017-11-14 15:39:07 -06:00
|
|
|
:recent_time_read,
|
2020-05-14 11:57:35 -05:00
|
|
|
:bookmark_count,
|
2024-02-05 03:00:36 -06:00
|
|
|
:can_see_summary_stats,
|
|
|
|
:can_see_user_actions
|
2020-05-14 11:57:35 -05:00
|
|
|
|
|
|
|
def can_see_summary_stats
|
|
|
|
scope.can_see_summary_stats?(object.user)
|
|
|
|
end
|
2016-03-29 01:11:47 -05:00
|
|
|
|
2024-02-05 03:00:36 -06:00
|
|
|
def can_see_user_actions
|
|
|
|
scope.can_see_user_actions?(object.user, [])
|
|
|
|
end
|
|
|
|
|
2016-03-29 01:11:47 -05:00
|
|
|
def include_badges?
|
|
|
|
SiteSetting.enable_badges
|
|
|
|
end
|
2016-03-30 11:05:16 -05:00
|
|
|
|
2016-05-09 08:51:43 -05:00
|
|
|
def include_bookmark_count?
|
|
|
|
scope.authenticated? && object.user_id == scope.user.id
|
|
|
|
end
|
|
|
|
|
2016-03-30 11:05:16 -05:00
|
|
|
def time_read
|
2017-11-14 15:39:07 -06:00
|
|
|
object.time_read
|
|
|
|
end
|
|
|
|
|
|
|
|
def recent_time_read
|
|
|
|
object.recent_time_read
|
2016-03-30 11:05:16 -05:00
|
|
|
end
|
2020-05-14 11:57:35 -05:00
|
|
|
|
|
|
|
def include_likes_given?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_likes_received?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topics_entered?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_posts_read_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_days_visited?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topic_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_post_count?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_time_read?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_recent_time_read?
|
|
|
|
can_see_summary_stats
|
|
|
|
end
|
2016-01-19 22:11:52 -06:00
|
|
|
end
|