mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:20:43 +08:00
101ec21bc9
Before this commit, we did not have guardian checks in place to determine if a topic's title associated with a user badge should be displayed or not. This means that the topic title of topics with restricted access could be leaked to anon and users without access if certain conditions are met. While we will not specify the conditions required, we have internally assessed that the odds of meeting such conditions are low. With this commit, we will now apply a guardian check to ensure that the current user is able to see a topic before the topic's title is included in the serialized object of a `UserBadge`.
43 lines
890 B
Ruby
43 lines
890 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UserBadgeSerializer < ApplicationSerializer
|
|
include UserBadgePostAndTopicAttributesMixin
|
|
|
|
class UserSerializer < BasicUserSerializer
|
|
include UserPrimaryGroupMixin
|
|
|
|
attributes :name,
|
|
:moderator,
|
|
:admin
|
|
end
|
|
|
|
attributes :id, :granted_at, :created_at, :count, :post_id, :post_number
|
|
|
|
has_one :badge
|
|
has_one :user, serializer: UserSerializer, root: :users
|
|
has_one :granted_by, serializer: UserSerializer, root: :users
|
|
has_one :topic, serializer: BasicTopicSerializer
|
|
|
|
def include_count?
|
|
object.respond_to? :count
|
|
end
|
|
|
|
def include_post_id?
|
|
include_post_attributes?
|
|
end
|
|
|
|
alias :include_post_number? :include_post_id?
|
|
|
|
def post_number
|
|
object.post && object.post.post_number
|
|
end
|
|
|
|
def topic
|
|
object.post.topic
|
|
end
|
|
|
|
def include_topic?
|
|
include_topic_attributes?
|
|
end
|
|
end
|