diff --git a/app/assets/javascripts/discourse/helpers/user-avatar.js.es6 b/app/assets/javascripts/discourse/helpers/user-avatar.js.es6
index d665b0dc513..60e8137b085 100644
--- a/app/assets/javascripts/discourse/helpers/user-avatar.js.es6
+++ b/app/assets/javascripts/discourse/helpers/user-avatar.js.es6
@@ -30,6 +30,7 @@ function renderAvatar(user, options) {
options = options || {};
if (user) {
+ const name = Em.get(user, options.namePath || "name");
const username = Em.get(user, options.usernamePath || "username");
const avatarTemplate = Em.get(
user,
@@ -40,7 +41,7 @@ function renderAvatar(user, options) {
return "";
}
- let displayName = Ember.get(user, "name") || formatUsername(username);
+ let displayName = name || formatUsername(username);
let title = options.title;
if (!title && !options.ignoreTitle) {
diff --git a/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs b/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs
index 8a76f021914..6b1009f91c6 100644
--- a/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs
+++ b/app/assets/javascripts/discourse/templates/list/posters-column.raw.hbs
@@ -1,5 +1,5 @@
{{#each posters as |poster|}}
-
+
{{/each}}
|
diff --git a/app/serializers/basic_user_serializer.rb b/app/serializers/basic_user_serializer.rb
index d14877e6da6..c7eaa384829 100644
--- a/app/serializers/basic_user_serializer.rb
+++ b/app/serializers/basic_user_serializer.rb
@@ -1,5 +1,9 @@
class BasicUserSerializer < ApplicationSerializer
- attributes :id, :username, :avatar_template
+ attributes :id, :username, :name, :avatar_template
+
+ def name
+ Hash === user ? user[:name] : user.try(:name)
+ end
def include_name?
SiteSetting.enable_names?
@@ -16,5 +20,4 @@ class BasicUserSerializer < ApplicationSerializer
def user
object[:user] || object
end
-
end
diff --git a/lib/avatar_lookup.rb b/lib/avatar_lookup.rb
index f056e736968..8bfcd78fbe1 100644
--- a/lib/avatar_lookup.rb
+++ b/lib/avatar_lookup.rb
@@ -12,7 +12,7 @@ class AvatarLookup
private
def self.lookup_columns
- @lookup_columns ||= %i{id user_emails.email username uploaded_avatar_id}
+ @lookup_columns ||= %i{id user_emails.email username name uploaded_avatar_id}
end
def users
diff --git a/spec/components/avatar_lookup_spec.rb b/spec/components/avatar_lookup_spec.rb
index c744b6301dc..7cf86afd44e 100644
--- a/spec/components/avatar_lookup_spec.rb
+++ b/spec/components/avatar_lookup_spec.rb
@@ -4,7 +4,7 @@ require 'rails_helper'
require_dependency 'avatar_lookup'
describe AvatarLookup do
- let!(:user) { Fabricate(:user) }
+ let!(:user) { Fabricate(:user, username: "john_doe", name: "John Doe") }
describe '#[]' do
before do
@@ -20,7 +20,10 @@ describe AvatarLookup do
end
it 'returns user if user_id exists' do
- expect(@avatar_lookup[user.id]).to eq(user)
+ avatar_lookup_user = @avatar_lookup[user.id]
+ expect(avatar_lookup_user).to eq(user)
+ expect(avatar_lookup_user.username).to eq("john_doe")
+ expect(avatar_lookup_user.name).to eq("John Doe")
end
end
end
diff --git a/spec/serializers/basic_user_serializer_spec.rb b/spec/serializers/basic_user_serializer_spec.rb
new file mode 100644
index 00000000000..551df2c3aab
--- /dev/null
+++ b/spec/serializers/basic_user_serializer_spec.rb
@@ -0,0 +1,27 @@
+require 'rails_helper'
+require_dependency 'user'
+
+describe BasicUserSerializer do
+
+ context "name" do
+ let(:user) { Fabricate.build(:user) }
+ let(:serializer) { BasicUserSerializer.new(user, scope: Guardian.new(user), root: false) }
+ let(:json) { serializer.as_json }
+
+ it "returns the username" do
+ expect(json[:username]).to be_present
+ end
+
+ it "returns the name it when `enable_names` is true" do
+ SiteSetting.enable_names = true
+ expect(json[:name]).to be_present
+ end
+
+ it "doesn't return the name it when `enable_names` is false" do
+ SiteSetting.enable_names = false
+ expect(json[:name]).to be_blank
+ end
+
+ end
+
+end
diff --git a/test/javascripts/acceptance/topic-discovery-test.js.es6 b/test/javascripts/acceptance/topic-discovery-test.js.es6
index 7e105b3bd42..54e578b9a70 100644
--- a/test/javascripts/acceptance/topic-discovery-test.js.es6
+++ b/test/javascripts/acceptance/topic-discovery-test.js.es6
@@ -7,6 +7,12 @@ QUnit.test("Visit Discovery Pages", async assert => {
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
+ assert.equal(
+ find("a[data-user-card=eviltrout]:first img.avatar").attr("title"),
+ "Evil Trout - Most Posts",
+ "it shows user's full name in avatar title"
+ );
+
await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
diff --git a/test/javascripts/fixtures/discovery_fixtures.js.es6 b/test/javascripts/fixtures/discovery_fixtures.js.es6
index 3f1dc63adb4..37917b05200 100644
--- a/test/javascripts/fixtures/discovery_fixtures.js.es6
+++ b/test/javascripts/fixtures/discovery_fixtures.js.es6
@@ -11,7 +11,12 @@ export default {
username: "stellarhopper",
avatar_template: "/images/avatar.png"
},
- { id: 19, username: "eviltrout", avatar_template: "/images/avatar.png" },
+ {
+ id: 19,
+ username: "eviltrout",
+ name: "Evil Trout",
+ avatar_template: "/images/avatar.png"
+ },
{ id: 14, username: "clay", avatar_template: "/images/avatar.png" },
{
id: 32,