A platform for community discussion. Free, open, simple.
FIX: DraftSerializer leaks real names of topic and post authors (#42197)
Isaac Janzen76ec74ee2633
diff --git a/app/serializers/draft_serializer.rb b/app/serializers/draft_serializer.rbindex 8ca8111ccfb..85d62818739 100644--- a/app/serializers/draft_serializer.rb+++ b/app/serializers/draft_serializer.rb@@ -47,6 +47,10 @@ class DraftSerializer < ApplicationSerializerobject.display_user&.nameend+ def include_name?+ SiteSetting.enable_names?+ end+def titleobject.topic&.titleenddiff --git a/spec/requests/drafts_controller_spec.rb b/spec/requests/drafts_controller_spec.rbindex 7187ec7ee7c..7966514c9bf 100644--- a/spec/requests/drafts_controller_spec.rb+++ b/spec/requests/drafts_controller_spec.rb@@ -50,6 +50,23 @@ RSpec.describe DraftsController doexpect(response.parsed_body["drafts"].first["title"]).to eq(nil)end+ it "omits display user names when names are disabled" do+ SiteSetting.enable_names = false+ topic_author = Fabricate(:user, name: "Hidden Full Name")+ topic = Fabricate(:topic, user: topic_author)+ Draft.set(user, "topic_#{topic.id}", 0, { reply: "draft reply" }.to_json)++ sign_in(user)+ get "/drafts.json"++ draft = response.parsed_body["drafts"].first++ expect(response.status).to eq(200)+ expect(draft).to include("username" => topic_author.username)+ expect(draft).not_to have_key("name")+ expect(response.body).not_to include(topic_author.name)+ end+it "returns categories when lazy load categories is enabled" doSiteSetting.lazy_load_categories_groups = "#{Group::AUTO_GROUPS[:everyone]}"category = Fabricate(:category)