docs(settings): add email notifications documentation to team settings (#432)

* docs(settings): add email notification documentation to team settings

* fix(notification): use correct webui route URLs for project and asset links in emails
This commit is contained in:
Yiling-J
2026-09-28 11:27:59 +08:00
committed by GitHub
parent d98f486c9d
commit af8f24aa95
7 changed files with 269 additions and 49 deletions
@@ -441,6 +441,41 @@ describe('EmailService', () => {
expect(status.subject).toContain('Grace updated status of task "Refactor auth"')
expect(status.html).toContain('Moved to In Progress')
})
it('generates correct action links without team id for project and asset URLs', () => {
const baseUrl = emailService.getBaseUrl()
// Project link
const projectEmail = emailService.renderNotificationEmail({
type: NotificationType.new_user_join_project,
creatorName: 'Alice',
teamName: 'Designers',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
projectName: 'Project Alpha',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
})
expect(projectEmail.html).toContain(`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`)
expect(projectEmail.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
// Asset link
const assetEmail = emailService.renderNotificationEmail({
type: NotificationType.comment_created,
creatorName: 'Alice',
teamName: 'Designers',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
projectName: 'Project Alpha',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
assetId: '01KY2ASSET1234567890ABCDEF',
assetName: 'logo.png',
commentMessage: 'Looks good',
})
expect(assetEmail.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`,
)
expect(assetEmail.html).not.toContain('/teams/')
})
})
describe('renderBatchedNotificationEmail', () => {
@@ -594,5 +629,64 @@ describe('EmailService', () => {
expect(rendered.html).toContain('diagram.png')
expect(rendered.html).toContain('https://example.com/diagram.png')
})
it('generates correct project action links in batched notification emails', () => {
const baseUrl = emailService.getBaseUrl()
const rendered = emailService.renderBatchedNotificationEmail({
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
recipientName: 'Bob',
items: [
{
id: 'n-1',
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
projectName: 'Project Alpha',
assetId: '01KY2ASSET1234567890ABCDEF',
assetName: 'hero.png',
createdAt: new Date('2026-09-27T10:00:00Z'),
},
],
})
expect(rendered.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`,
)
expect(rendered.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
// Test collapsed group (>3 items)
const collapsedItems = Array.from({ length: 4 }, (_, i) => ({
id: `n-${i}`,
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
projectName: 'Project Alpha',
assetId: `asset-${i}`,
assetName: `file_${i}.png`,
createdAt: new Date('2026-09-27T10:00:00Z'),
}))
const renderedCollapsed = emailService.renderBatchedNotificationEmail({
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
recipientName: 'Bob',
items: collapsedItems,
})
expect(renderedCollapsed.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`,
)
expect(renderedCollapsed.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
})
})
})
+32 -38
View File
@@ -312,20 +312,18 @@ Sent from Shumai at ${baseUrl}
let actionUrl = baseUrl
let actionText = 'View in Shumai'
if (ctx.teamId) {
if (ctx.projectId && ctx.assetId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}/projects/${ctx.projectId}?assetId=${ctx.assetId}`
actionText = 'View Asset'
} else if (ctx.projectId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}/projects/${ctx.projectId}`
actionText = 'View Project'
} else if (ctx.kanbanTaskId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}?kanbanTaskId=${ctx.kanbanTaskId}`
actionText = 'View Task'
} else {
actionUrl = `${baseUrl}/teams/${ctx.teamId}`
actionText = 'Open Team'
}
if (ctx.projectId && ctx.assetId) {
actionUrl = `${baseUrl}/projects/${ctx.projectId}/files/${ctx.assetId}`
actionText = 'View Asset'
} else if (ctx.projectId) {
actionUrl = `${baseUrl}/projects/${ctx.projectId}`
actionText = 'View Project'
} else if (ctx.teamId && ctx.kanbanTaskId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}/kanban?taskId=${ctx.kanbanTaskId}`
actionText = 'View Task'
} else if (ctx.teamId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}`
actionText = 'Open Team'
}
let subject = '[Shumai] Notification'
@@ -673,9 +671,7 @@ Team: ${ctx.teamName}
return t > latest ? t : latest
}, 0)
const timeStr = latestTime > 0 ? formatUploadTime(new Date(latestTime)) : undefined
const targetUrl = first.projectId
? `${baseUrl}/teams/${ctx.teamId}/projects/${first.projectId}`
: teamUrl
const targetUrl = first.projectId ? `${baseUrl}/projects/${first.projectId}` : teamUrl
htmlRows.push(
`
@@ -840,27 +836,25 @@ function getItemAction(
baseUrl: string,
item: BatchedNotificationItem,
): { url: string; text: string } {
if (item.teamId) {
if (item.projectId && item.assetId) {
return {
url: `${baseUrl}/teams/${item.teamId}/projects/${item.projectId}?assetId=${item.assetId}`,
text: 'View Asset',
}
} else if (item.projectId) {
return {
url: `${baseUrl}/teams/${item.teamId}/projects/${item.projectId}`,
text: 'View Project',
}
} else if (item.kanbanTaskId) {
return {
url: `${baseUrl}/teams/${item.teamId}?kanbanTaskId=${item.kanbanTaskId}`,
text: 'View Task',
}
} else {
return {
url: `${baseUrl}/teams/${item.teamId}`,
text: 'Open Team',
}
if (item.projectId && item.assetId) {
return {
url: `${baseUrl}/projects/${item.projectId}/files/${item.assetId}`,
text: 'View Asset',
}
} else if (item.projectId) {
return {
url: `${baseUrl}/projects/${item.projectId}`,
text: 'View Project',
}
} else if (item.teamId && item.kanbanTaskId) {
return {
url: `${baseUrl}/teams/${item.teamId}/kanban?taskId=${item.kanbanTaskId}`,
text: 'View Task',
}
} else if (item.teamId) {
return {
url: `${baseUrl}/teams/${item.teamId}`,
text: 'Open Team',
}
}
return { url: baseUrl, text: 'Open Shumai' }