chore: Scope mention label lookup in emails to the team (#14229)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-10-22 07:56:59 -04:00
1 parent a5b8c9102c
commit 2ec2e2025e
3 files changed
+37 -6

No files matched your search

+1 -1
View File
@@ -363,7 +363,7 @@ export default abstract class BaseEmail<
// Process user mentions to ensure they are up to date with the database
const processedNode = ProsemirrorHelper.toProsemirror(
await ProsemirrorHelper.processMentions(node)
await ProsemirrorHelper.processMentions(node, team.id)
);
let content = await ProsemirrorHelper.toHTML(processedNode, {
@@ -143,7 +143,7 @@ describe("ProsemirrorHelper", () => {
mentionedParagraph,
]);
const newDoc = await ProsemirrorHelper.processMentions(doc);
const newDoc = await ProsemirrorHelper.processMentions(doc, user.teamId);
expect(newDoc.content?.[1]?.content?.[1].attrs?.label).toEqual("Unknown");
});
@@ -192,13 +192,13 @@ describe("ProsemirrorHelper", () => {
mentionedParagraph,
]);
const newDoc = await ProsemirrorHelper.processMentions(doc);
const newDoc = await ProsemirrorHelper.processMentions(doc, user.teamId);
expect(newDoc.content?.[1]?.content?.[1].attrs?.label).toEqual(user.name);
});
it("should handle multiple renamed users", async () => {
const firstUser = await buildUser();
const secondUser = await buildUser();
const secondUser = await buildUser({ teamId: firstUser.teamId });
const firstMentionAttrs: MentionAttrs = {
id: "9a17c1c8-d178-4350-9001-203a73070fcb",
@@ -266,7 +266,10 @@ describe("ProsemirrorHelper", () => {
mentionedParagraph,
]);
const newDoc = await ProsemirrorHelper.processMentions(doc);
const newDoc = await ProsemirrorHelper.processMentions(
doc,
firstUser.teamId
);
expect(newDoc.content?.[1]?.content?.[1].attrs?.label).toEqual(
firstNewName
);
@@ -274,6 +277,32 @@ describe("ProsemirrorHelper", () => {
secondNewName
);
});
it("should not resolve users from another team", async () => {
const user = await buildUser();
const otherTeamUser = await buildUser();
const doc = buildProseMirrorDoc([
{
type: "paragraph",
content: [
{
type: "mention",
attrs: {
id: "9a17c1c8-d178-4350-9001-203a73070fcb",
type: MentionType.User,
label: "other.user",
actorId: user.id,
modelId: otherTeamUser.id,
},
},
],
},
]);
const newDoc = await ProsemirrorHelper.processMentions(doc, user.teamId);
expect(newDoc.content?.[0]?.content?.[0].attrs?.label).toEqual("Unknown");
});
});
describe("getNodeForMentionEmail", () => {
+3 -1
View File
@@ -962,9 +962,10 @@ export class ProsemirrorHelper extends SharedProsemirrorHelper {
* displayed correctly.
*
* @param data The ProsemirrorData object to process
* @param teamId the team that mentioned users must belong to.
* @returns The processed ProsemirrorData with updated mentions
*/
static async processMentions(data: ProsemirrorData | Node) {
static async processMentions(data: ProsemirrorData | Node, teamId: string) {
const json = "toJSON" in data ? (data.toJSON() as ProsemirrorData) : data;
// First pass: collect all user IDs from mentions
@@ -994,6 +995,7 @@ export class ProsemirrorHelper extends SharedProsemirrorHelper {
? await User.findAll({
where: {
id: uniqueUserIds,
teamId,
},
attributes: ["id", "name"],
})