Skip to content

A platform for community discussion. Free, open, simple.

FIX: Full names are exposed when name display is disabled (#39838)

Sama7c0f5dd0eea
diff --git a/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb b/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
index 90a5944c065..9dc6bd47236 100644
--- a/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
+++ b/plugins/discourse-post-voting/app/serializers/post_voting_comment_serializer.rb
@@ -15,6 +15,10 @@ class PostVotingCommentSerializer < ApplicationSerializer
attr_accessor :comments_user_voted
+ def include_name?
+ SiteSetting.enable_names?
+ end
+
def name
object.user&.name
end
diff --git a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
index e129acddb0c..9c0b3935ba3 100644
--- a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
+++ b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb
@@ -55,6 +55,17 @@ RSpec.describe PostVoting::CommentsController do
expect(comment["id"]).to eq(comment_3.id)
end
+
+ it "does not expose names when names are disabled" do
+ SiteSetting.enable_names = false
+ comment_2.user.update!(name: "Secret Name")
+
+ get "/post_voting/comments.json", params: { post_id: answer.id, last_comment_id: comment.id }
+
+ expect(response.status).to eq(200)
+ expect(response.body).not_to include("Secret Name")
+ expect(response.parsed_body["comments"].any? { |comment| comment.key?("name") }).to eq(false)
+ end
end
describe "#create" do