FIX: Onebox discourse user not respecting enable names (#7245)

FIX: Onebox discourse user not respecting enable names (#7245)

diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 72d697c..adb646a 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -234,11 +234,14 @@ module Oneboxer
     username = route[:username] || ""
 
     if user = User.find_by(username_lower: username.downcase)
+
+      name = user.name if SiteSetting.enable_names
+
       args = {
         user_id: user.id,
         username: user.username,
         avatar: PrettyText.avatar_img(user.avatar_template, "extra_large"),
-        name: user.name,
+        name: name,
         bio: user.user_profile.bio_excerpt(230),
         location: user.user_profile.location,
         joined: I18n.t('joined'),
diff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rb
index b9b4215..7e10d2a 100644
--- a/spec/components/oneboxer_spec.rb
+++ b/spec/components/oneboxer_spec.rb
@@ -94,6 +94,15 @@ describe Oneboxer do
       expect(preview("/u/#{user.username}")).to include(user.name)
     end
 
+    it "should respect enable_names site setting" do
+      user = Fabricate(:user)
+
+      SiteSetting.enable_names = true
+      expect(preview("/u/#{user.username}")).to include(user.name)
+      SiteSetting.enable_names = false
+      expect(preview("/u/#{user.username}")).not_to include(user.name)
+    end
+
     it "links to an upload" do
       path = "/uploads/default/original/3X/e/8/e8fcfa624e4fb6623eea57f54941a58ba797f14d"

GitHub sha: 5a9dd923

@venarius Is this bug fixed in v2.3.0.beta9 ?