FIX: Broken group messages inboxes when group name is mixed case (#22183)

This is a follow up to 1cbc65ba79 where
visiting a group with a mixed case name would result in an error.
This commit is contained in:
Alan Guo Xiang Tan 2023-06-19 17:36:04 +08:00 committed by GitHub
parent 8837ee4b39
commit 57c96ed03d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 52 deletions

View File

@ -46,7 +46,11 @@ export default class extends Controller {
for (let i = this.messagesDropdownContent.length - 1; i >= 0; i--) {
const row = this.messagesDropdownContent[i];
if (currentURL.includes(row.id.replace(this.router.rootURL, "/"))) {
if (
currentURL.includes(
row.id.toLowerCase().replace(this.router.rootURL, "/")
)
) {
value = row.id;
break;
}

View File

@ -4,7 +4,16 @@ export default class extends DiscourseRoute {
model(params) {
return this.modelFor("user")
.get("groups")
.filterBy("name", params.name.toLowerCase())[0];
.find((group) => {
return group.name.toLowerCase() === params.name.toLowerCase();
});
}
afterModel(model) {
if (!model) {
this.transitionTo("exception-unknown");
return;
}
}
setupController(controller, model) {

View File

@ -19,7 +19,6 @@ 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",
@ -971,52 +970,3 @@ acceptance(
});
}
);
acceptance(
"User Private Messages - user with uppercase username",
function (needs) {
needs.user({
groups: [{ id: 14, name: "awesome_group", has_messages: true }],
});
needs.pretender((server, helper) => {
const response = cloneJSON(userFixtures["/u/charlie.json"]);
response.user.username = "chArLIe";
server.get("/u/charlie.json", () => helper.response(response));
server.get(
"/topics/private-messages-group/:username/:group_name.json",
() => {
return helper.response({
topic_list: {
topics: [
{ id: 1, posters: [] },
{ id: 2, posters: [] },
],
},
});
}
);
});
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"
);
});
test("viewing group inbox", async function (assert) {
await visit("/u/charlie/messages/group/awesome_group");
assert.strictEqual(
query(".user-nav-messages-dropdown .selected-name").textContent.trim(),
"awesome_group",
"dropdown menu displays the right group name"
);
});
}
);

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
module PageObjects
module Pages
class UserPrivateMessages < PageObjects::Pages::Base
def visit(user)
page.visit "/u/#{user.username}/messages"
self
end
def visit_group_inbox(user, group)
page.visit "/u/#{user.username}/messages/group/#{group.name}"
self
end
def has_right_inbox_dropdown_value?(value)
has_css?(".user-nav-messages-dropdown .combo-box-header[data-name='#{value}']")
end
end
end
end

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
describe "Viewing user private messages", type: :system do
fab!(:user) { Fabricate(:user, username: "mIxed_caSE_usERNAME") }
fab!(:user2) { Fabricate(:user) }
let(:user_private_messages_page) { PageObjects::Pages::UserPrivateMessages.new }
before { sign_in(user) }
describe "when the user has group messages" do
fab!(:group) do
Fabricate(:group, name: "miXeD_caSE_name", has_messages: true).tap { |g| g.add(user) }
end
before { SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:everyone] }
it "allows the user to view the default messages inbox" do
user_private_messages_page.visit(user)
expect(user_private_messages_page).to have_right_inbox_dropdown_value("Inbox")
end
it "allows the user to view the group messages inbox of a group" do
user_private_messages_page.visit_group_inbox(user, group)
expect(user_private_messages_page).to have_right_inbox_dropdown_value("miXeD_caSE_name")
end
end
end