2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-25 09:52:43 +08:00
|
|
|
class DetailedUserBadgeSerializer < BasicUserBadgeSerializer
|
2022-10-27 11:26:14 +08:00
|
|
|
include UserBadgePostAndTopicAttributesMixin
|
|
|
|
|
2018-08-14 06:11:14 +08:00
|
|
|
has_one :granted_by, serializer: UserBadgeSerializer::UserSerializer
|
2015-02-25 09:52:43 +08:00
|
|
|
|
2021-06-01 16:33:40 +08:00
|
|
|
attributes :post_number, :topic_id, :topic_title, :is_favorite, :can_favorite
|
2015-02-25 09:52:43 +08:00
|
|
|
|
2022-10-27 11:26:14 +08:00
|
|
|
def post_number
|
|
|
|
object.post.post_number
|
2015-02-25 09:52:43 +08:00
|
|
|
end
|
|
|
|
|
2022-10-27 11:26:14 +08:00
|
|
|
def include_post_number?
|
|
|
|
include_post_attributes?
|
2015-02-25 09:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def topic_id
|
2022-10-27 11:26:14 +08:00
|
|
|
object.post.topic_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topic_id?
|
|
|
|
include_topic_attributes?
|
2015-02-25 09:52:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def topic_title
|
2022-10-27 11:26:14 +08:00
|
|
|
object.post.topic.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_topic_title?
|
|
|
|
include_topic_id?
|
2015-02-25 09:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-06-01 16:33:40 +08:00
|
|
|
def can_favorite
|
2021-06-22 23:58:03 +08:00
|
|
|
SiteSetting.max_favorite_badges > 0 &&
|
2021-06-01 16:33:40 +08:00
|
|
|
(scope.current_user.present? && object.user_id == scope.current_user.id) &&
|
|
|
|
!(1..4).include?(object.badge_id)
|
|
|
|
end
|
2015-02-25 09:52:43 +08:00
|
|
|
end
|