FIX: Use `username_lower` in user menu router lookup (#20115)

For a user whose username has an uppercase character, the new user menu
dropdown was not defaulting to "Inbox" because the Ember router uses
lowercased usernames which were not matching with the `username`
property. Switching to `username_lower` fixes the issue.
This commit is contained in:
Penar Musaraj 2023-02-02 09:14:16 -05:00 committed by GitHub
parent 6bbf832400
commit a32e6b5771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 3 deletions

View File

@ -59,7 +59,10 @@ export default class extends Controller {
get messagesDropdownContent() {
const content = [
{
id: this.router.urlFor("userPrivateMessages.user", this.model.username),
id: this.router.urlFor(
"userPrivateMessages.user",
this.model.username_lower
),
name: I18n.t("user.messages.inbox"),
},
];
@ -78,7 +81,10 @@ export default class extends Controller {
if (this.pmTaggingEnabled) {
content.push({
id: this.router.urlFor("userPrivateMessages.tags", this.model.username),
id: this.router.urlFor(
"userPrivateMessages.tags",
this.model.username_lower
),
name: I18n.t("user.messages.tags"),
icon: "tags",
});
@ -86,7 +92,7 @@ export default class extends Controller {
customUserNavMessagesDropdownRows.forEach((row) => {
content.push({
id: this.router.urlFor(row.routeName, this.model.username),
id: this.router.urlFor(row.routeName, this.model.username_lower),
name: row.name,
icon: row.icon,
});

View File

@ -19,6 +19,7 @@ import {
} from "discourse/lib/topic-list-tracker";
import { withPluginApi } from "discourse/lib/plugin-api";
import { resetCustomUserNavMessagesDropdownRows } from "discourse/controllers/user-private-messages";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
acceptance(
"User Private Messages - user with no group messages",
@ -1046,3 +1047,28 @@ acceptance(
});
}
);
acceptance(
"User Private Messages - user with uppercase username",
function (needs) {
needs.user({
redesigned_user_page_nav_enabled: true,
});
needs.pretender((server, helper) => {
const response = cloneJSON(userFixtures["/u/charlie.json"]);
response.user.username = "chArLIe";
server.get("/u/charlie.json", () => helper.response(response));
});
test("viewing inbox", async function (assert) {
await visit("/u/charlie/messages");
assert.strictEqual(
query(".user-nav-messages-dropdown .selected-name").textContent.trim(),
"Inbox",
"menu defaults to Inbox"
);
});
}
);