diff --git a/app/assets/javascripts/discourse/app/components/about-page-users.js b/app/assets/javascripts/discourse/app/components/about-page-users.js index f0412f4f24e..1c1b109ae5d 100644 --- a/app/assets/javascripts/discourse/app/components/about-page-users.js +++ b/app/assets/javascripts/discourse/app/components/about-page-users.js @@ -1,7 +1,5 @@ import Component from "@ember/component"; import { computed } from "@ember/object"; -import { formatUsername } from "discourse/lib/utilities"; -import { normalize } from "discourse/components/user-info"; import { prioritizeNameInUx } from "discourse/lib/settings"; import { renderAvatar } from "discourse/helpers/user-avatar"; import { userPath } from "discourse/lib/url"; @@ -9,13 +7,7 @@ import { userPath } from "discourse/lib/url"; export default Component.extend({ usersTemplates: computed("users.[]", function () { return (this.users || []).map((user) => { - let name = user.name; - let username = user.username; - let prioritizeName = prioritizeNameInUx(name); - let hideName = false; - if (name && normalize(username) === normalize(name)) { - hideName = true; - } + const { name, username } = user; return { name, @@ -26,9 +18,7 @@ export default Component.extend({ siteSettings: this.siteSettings, }), title: user.title || "", - formatedUsername: formatUsername(username), - prioritizeName, - hideName, + prioritizeName: prioritizeNameInUx(name), }; }); }), diff --git a/app/assets/javascripts/discourse/app/components/user-info.js b/app/assets/javascripts/discourse/app/components/user-info.js index dc9cf2e86d7..9fdcf782c6a 100644 --- a/app/assets/javascripts/discourse/app/components/user-info.js +++ b/app/assets/javascripts/discourse/app/components/user-info.js @@ -4,10 +4,6 @@ import discourseComputed from "discourse-common/utils/decorators"; import { userPath } from "discourse/lib/url"; import { prioritizeNameInUx } from "discourse/lib/settings"; -export function normalize(name) { - return name.replace(/[\-\_ \.]/g, "").toLowerCase(); -} - export default Component.extend({ classNameBindings: [":user-info", "size"], attributeBindings: ["data-username"], @@ -21,13 +17,6 @@ export default Component.extend({ return userPath(username); }, - @discourseComputed("user.name", "user.username") - name(name, username) { - if (name && normalize(username) !== normalize(name)) { - return name; - } - }, - @discourseComputed("user.name") nameFirst(name) { return prioritizeNameInUx(name); diff --git a/app/assets/javascripts/discourse/app/templates/components/about-page-users.hbs b/app/assets/javascripts/discourse/app/templates/components/about-page-users.hbs index f27899f0e78..af378b33dfc 100644 --- a/app/assets/javascripts/discourse/app/templates/components/about-page-users.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/about-page-users.hbs @@ -15,9 +15,7 @@ - {{#unless userTemplate.hideName}} - {{#if userTemplate.prioritizeName}}{{userTemplate.username}}{{else}}{{userTemplate.name}}{{/if}} - {{/unless}} + {{#if userTemplate.prioritizeName}}{{userTemplate.username}}{{else}}{{userTemplate.name}}{{/if}}
{{userTemplate.title}}
diff --git a/app/assets/javascripts/discourse/app/templates/components/user-info.hbs b/app/assets/javascripts/discourse/app/templates/components/user-info.hbs index 023a937fcb0..f22d4c5c425 100644 --- a/app/assets/javascripts/discourse/app/templates/components/user-info.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/user-info.hbs @@ -12,19 +12,19 @@ {{#if includeLink}} - {{if nameFirst this.name (format-username @user.username)}} + {{if nameFirst @user.name (format-username @user.username)}} {{else}} - {{if nameFirst this.name (format-username @user.username)}} + {{if nameFirst @user.name (format-username @user.username)}} {{/if}} {{#if includeLink}} - {{if nameFirst (format-username @user.username) this.name}} + {{if nameFirst (format-username @user.username) @user.name}} {{else}} - {{if nameFirst (format-username @user.username) this.name}} + {{if nameFirst (format-username @user.username) @user.name}} {{/if}} {{plugin-outlet name="after-user-name" tagName="span" connectorTagName="span" args=(hash user=user)}} diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js index 0fc0ef05544..0203a64d98c 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/user-info-test.js @@ -2,11 +2,43 @@ import componentTest, { setupRenderingTest, } from "discourse/tests/helpers/component-test"; import hbs from "htmlbars-inline-precompile"; -import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers"; +import { + discourseModule, + exists, + query, +} from "discourse/tests/helpers/qunit-helpers"; discourseModule("Integration | Component | user-info", function (hooks) { setupRenderingTest(hooks); + componentTest("prioritized name", { + template: hbs`{{user-info user=currentUser}}`, + + beforeEach() { + this.siteSettings.prioritize_username_in_ux = false; + this.currentUser.name = "Evil Trout"; + }, + + async test(assert) { + assert.equal(query(".name.bold").innerText.trim(), "Evil Trout"); + assert.equal(query(".username.margin").innerText.trim(), "eviltrout"); + }, + }); + + componentTest("prioritized username", { + template: hbs`{{user-info user=currentUser}}`, + + beforeEach() { + this.siteSettings.prioritize_username_in_ux = true; + this.currentUser.name = "Evil Trout"; + }, + + async test(assert) { + assert.equal(query(".username.bold").innerText.trim(), "eviltrout"); + assert.equal(query(".name.margin").innerText.trim(), "Evil Trout"); + }, + }); + componentTest("includeLink", { template: hbs`{{user-info user=currentUser includeLink=includeLink}}`,