mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
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:
parent
8837ee4b39
commit
57c96ed03d
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
21
spec/system/page_objects/pages/user_private_messages.rb
Normal file
21
spec/system/page_objects/pages/user_private_messages.rb
Normal 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
|
30
spec/system/viewing_user_private_messages_spec.rb
Normal file
30
spec/system/viewing_user_private_messages_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user