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