mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
feat(agentic kanban): phase 1 not-agentic kanban board (#330)
* feat(kanban): implement AI-native kanban database models, services, and REST APIs * feat(webui): implement team kanban board and task management * style(webui): increase kanban dialog widths and form container * fix(webui): ensure kanban dialogs override sm:max-w-lg base class * style(webui): set edit task dialog max width to 5xl * chore: untrack kanban plan markdown files * feat(webui): update kanban page layout to 2 columns and refine task activity UI * fix(webui): constrain kanban column and board heights for vertical scrolling * feat(kanban): unify task status transition into updateTask API and allow unconstrained human task transitions * fix(webui): add optimistic updates to kanban drag-and-drop to eliminate flash * refactor(webui): remove client-side search box from kanban header * feat(kanban): redesign task dialog comments area and add attachment support * refactor(webui): remove top status action bar from task info dialog * fix(webui): narrow query cache predicate and add defensive guards for kanban drag optimistic update * feat(kanban): add drag-and-drop task reordering with fractional indexing (#331) * feat(kanban): add drag-and-drop task reordering with fractional indexing * fix(kanban): improve card drop zones, snap indicators, and column highlight * fix(kanban): enable card droppables only during active drag * fix(kanban): refine hover styles and drop indicators for column boundaries * fix(kanban): unify bottom drop indicator and fix top indicator clipping * fix(kanban): ensure full column highlight and full coverage drop target * minor change * feat(kanban): allow agent tasks free drag-and-drop and enforce status change permissions (#332) * refactor(kanban): rename task_type_agentic translation keys to task_type_agent * feat(kanban): refactor task type enum to isAgentTask boolean (#333) * refactor(kanban): remove phase 2 agent execution logic and streamline phase 1 kanban * feat(kanban): add notifications and audit logging for kanban (#334) * feat(kanban): redesign config area layout and add parent tasks multi-selector (#335) * feat(webui): redesign kanban task dialog config area * feat(kanban): simplify task dependencies with parent tasks multi-selector * refactor(kanban): remove unused links routes and legacy dependency methods * feat(kanban): connect assets and kanban tasks with many-to-many relationship (#336) * feat(kanban): connect assets and kanban tasks with many-to-many relationship * feat(kanban): improve asset picker layout, infinite scrolling, and breadcrumb icon styling * fix(kanban): ensure asset picker scrollarea is scrollable with min-h-0 and shrink-0 flex styling * fix(kanban): hide recently deleted in folder tree picker and adjust header padding * fix(kanban): use lucide files icon instead of paperclip for linked assets * feat(kanban): improve task deletion, goal sidebar interaction, and card styling (#337) * feat(kanban): improve task deletion, goal sidebar interaction, and card styling * feat(kanban): move agent task badge after priority and update to orange style * feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions (#338) * feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions * style(kanban): rotate kanban icon 180 degrees in sidebar and top nav * style(kanban): remove rotate-180 from SquareKanban icons * feat(kanban): add unassigned goal record and fix all tasks count (#339) * feat(kanban): add unassigned goal record and fix all tasks count * feat(kanban): toggle task count with three-dot action button on goal card hover * fix(ci): pin bun version to 1.3.14 across CI and Docker (#340) * fix(webui): truncate goal name to max 2 lines in kanban sidebar (#341)
This commit is contained in:
@@ -419,7 +419,14 @@ describe('NotificationService', () => {
|
||||
const info = await svc['toNotificationInfo'](
|
||||
await prisma.notification.findUniqueOrThrow({
|
||||
where: { id: n.id },
|
||||
include: { creator: true, team: true, project: true, asset: true, user: true },
|
||||
include: {
|
||||
creator: true,
|
||||
team: true,
|
||||
project: true,
|
||||
asset: true,
|
||||
user: true,
|
||||
kanbanTask: true,
|
||||
},
|
||||
}),
|
||||
null,
|
||||
)
|
||||
@@ -430,4 +437,103 @@ describe('NotificationService', () => {
|
||||
expect(info.asset?.originalWidth).toBe(1280)
|
||||
expect(info.asset?.originalHeight).toBe(720)
|
||||
})
|
||||
|
||||
it('notifyKanbanTaskEvent broadcasts to stakeholders excluding actor and parses mentions', async () => {
|
||||
const tm = await prisma.team.create({ data: { name: 'Team Kanban' } })
|
||||
const u1 = await prisma.user.create({
|
||||
data: { name: 'Actor', email: `actor-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const u2 = await prisma.user.create({
|
||||
data: { name: 'Assignee', email: `assignee-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const u3 = await prisma.user.create({
|
||||
data: { name: 'Mentioned', email: `mentioned-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const task = await prisma.kanbanTask.create({
|
||||
data: {
|
||||
teamId: tm.id,
|
||||
creatorId: u1.id,
|
||||
title: 'Important task',
|
||||
},
|
||||
})
|
||||
|
||||
const svc = notificationService
|
||||
await svc.notifyKanbanTaskEvent({
|
||||
type: NotificationType.kanban_task_comment_created,
|
||||
teamId: tm.id,
|
||||
creatorId: u1.id,
|
||||
kanbanTaskId: task.id,
|
||||
stakeholderIds: [u1.id, u2.id],
|
||||
commentMessage: `Hey <@${u3.id}> please check this`,
|
||||
})
|
||||
|
||||
const notifications = await prisma.notification.findMany({
|
||||
where: { kanbanTaskId: task.id },
|
||||
orderBy: { id: 'asc' },
|
||||
})
|
||||
|
||||
// u1 is actor, should not get notification.
|
||||
// u2 is stakeholder, gets kanban_task_comment_created.
|
||||
// u3 is mentioned, gets mention.
|
||||
expect(notifications).toHaveLength(2)
|
||||
|
||||
const commentNotif = notifications.find(
|
||||
(n) => n.type === NotificationType.kanban_task_comment_created,
|
||||
)
|
||||
expect(commentNotif?.userId).toBe(u2.id)
|
||||
|
||||
const mentionNotif = notifications.find((n) => n.type === NotificationType.mention)
|
||||
expect(mentionNotif?.userId).toBe(u3.id)
|
||||
})
|
||||
|
||||
it('filters kanban notifications based on user preferences', async () => {
|
||||
const tm = await prisma.team.create({ data: { name: 'Team Settings' } })
|
||||
const u1 = await prisma.user.create({
|
||||
data: { name: 'U1', email: `u1-set-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: tm.id, userId: u1.id, role: 'owner' },
|
||||
})
|
||||
const task = await prisma.kanbanTask.create({
|
||||
data: { teamId: tm.id, creatorId: u1.id, title: 'Task' },
|
||||
})
|
||||
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
teamId: tm.id,
|
||||
type: NotificationType.kanban_task_created,
|
||||
userId: u1.id,
|
||||
kanbanTaskId: task.id,
|
||||
},
|
||||
})
|
||||
await prisma.notification.create({
|
||||
data: {
|
||||
teamId: tm.id,
|
||||
type: NotificationType.kanban_task_comment_created,
|
||||
userId: u1.id,
|
||||
kanbanTaskId: task.id,
|
||||
},
|
||||
})
|
||||
|
||||
const svc = notificationService
|
||||
// By default both are enabled
|
||||
const listDefault = await svc.list(tm.id, u1.id, {})
|
||||
expect(listDefault.data).toHaveLength(2)
|
||||
|
||||
// Disable kanbanTasks
|
||||
await userMetadataService.upsertMetadata(u1.id, tm.id, 'notification_settings', {
|
||||
comments: true,
|
||||
replies: true,
|
||||
mentions: true,
|
||||
yourUploads: false,
|
||||
otherUploads: true,
|
||||
statusUpdates: true,
|
||||
kanbanTasks: false,
|
||||
kanbanComments: true,
|
||||
})
|
||||
|
||||
const listWithoutTasks = await svc.list(tm.id, u1.id, {})
|
||||
expect(listWithoutTasks.data).toHaveLength(1)
|
||||
expect(listWithoutTasks.data[0].type).toBe(NotificationType.kanban_task_comment_created)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,6 +15,74 @@ import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadat
|
||||
const mentionRegex = /<@([^>]+)>/g
|
||||
|
||||
export class NotificationService {
|
||||
async notifyKanbanTaskEvent(params: {
|
||||
type: NotificationType
|
||||
teamId: string
|
||||
projectId?: string | null
|
||||
creatorId: string
|
||||
kanbanTaskId?: string
|
||||
stakeholderIds?: (string | null | undefined)[]
|
||||
targetUserId?: string
|
||||
commentMessage?: string
|
||||
}) {
|
||||
const recipients = new Set<string>()
|
||||
if (params.targetUserId) {
|
||||
recipients.add(params.targetUserId)
|
||||
}
|
||||
if (params.stakeholderIds) {
|
||||
for (const id of params.stakeholderIds) {
|
||||
if (id) recipients.add(id)
|
||||
}
|
||||
}
|
||||
recipients.delete(params.creatorId)
|
||||
|
||||
const promises: Promise<void>[] = []
|
||||
for (const recipientId of recipients) {
|
||||
promises.push(
|
||||
this.createAsync({
|
||||
type: params.type,
|
||||
teamId: params.teamId,
|
||||
projectId: params.projectId ?? undefined,
|
||||
creatorId: params.creatorId,
|
||||
kanbanTaskId: params.kanbanTaskId,
|
||||
userId: recipientId,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
if (params.commentMessage) {
|
||||
const matches = [...params.commentMessage.matchAll(mentionRegex)]
|
||||
const mentionedIds = new Set<string>()
|
||||
|
||||
for (const match of matches) {
|
||||
if (match.length > 1) {
|
||||
const userId = match[1]
|
||||
if (mentionedIds.has(userId)) {
|
||||
continue
|
||||
}
|
||||
mentionedIds.add(userId)
|
||||
|
||||
if (params.creatorId === userId) {
|
||||
continue
|
||||
}
|
||||
|
||||
promises.push(
|
||||
this.createAsync({
|
||||
type: NotificationType.mention,
|
||||
teamId: params.teamId,
|
||||
projectId: params.projectId ?? undefined,
|
||||
creatorId: params.creatorId,
|
||||
kanbanTaskId: params.kanbanTaskId,
|
||||
userId: userId,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
async create(req: CreateNotificationRequest) {
|
||||
// Note: Do not await this, we fire and forget similarly to Go
|
||||
this.createAsync(req).catch((err) => {
|
||||
@@ -36,6 +104,16 @@ export class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve ProjectID from KanbanTaskId if missing
|
||||
if (!projectId && req.kanbanTaskId) {
|
||||
const task = await prisma.kanbanTask.findUnique({
|
||||
where: { id: req.kanbanTaskId },
|
||||
})
|
||||
if (task?.projectId) {
|
||||
projectId = task.projectId
|
||||
}
|
||||
}
|
||||
|
||||
// Check project notification settings
|
||||
if (projectId) {
|
||||
const project = await prisma.project.findUnique({
|
||||
@@ -57,6 +135,7 @@ export class NotificationService {
|
||||
creatorId: req.creatorId,
|
||||
assetId: req.assetId,
|
||||
taskId: req.taskId,
|
||||
kanbanTaskId: req.kanbanTaskId,
|
||||
userId: targetUserId,
|
||||
},
|
||||
})
|
||||
@@ -71,7 +150,8 @@ export class NotificationService {
|
||||
// 2. Handle Mentions for Comment/Reply types
|
||||
if (
|
||||
(req.type === NotificationType.comment_created ||
|
||||
req.type === NotificationType.reply_created) &&
|
||||
req.type === NotificationType.reply_created ||
|
||||
req.type === NotificationType.kanban_task_comment_created) &&
|
||||
req.commentMessage
|
||||
) {
|
||||
const matches = [...req.commentMessage.matchAll(mentionRegex)]
|
||||
@@ -128,23 +208,25 @@ export class NotificationService {
|
||||
yourUploads: false,
|
||||
otherUploads: true,
|
||||
statusUpdates: true,
|
||||
kanbanTasks: true,
|
||||
kanbanComments: true,
|
||||
}
|
||||
|
||||
const typeConditions: Prisma.NotificationWhereInput[] = []
|
||||
|
||||
// 1. Comments
|
||||
if (settings.comments) {
|
||||
if (settings.comments ?? true) {
|
||||
typeConditions.push({ type: NotificationType.comment_created, userId: null })
|
||||
}
|
||||
|
||||
// 2. Replies
|
||||
if (settings.replies) {
|
||||
if (settings.replies ?? true) {
|
||||
typeConditions.push({ type: NotificationType.reply_created, userId: userId })
|
||||
typeConditions.push({ type: NotificationType.reply_created, userId: null })
|
||||
}
|
||||
|
||||
// 3. Mentions
|
||||
if (settings.mentions) {
|
||||
if (settings.mentions ?? true) {
|
||||
typeConditions.push({ type: NotificationType.mention, userId: userId })
|
||||
}
|
||||
|
||||
@@ -161,11 +243,35 @@ export class NotificationService {
|
||||
}
|
||||
|
||||
// 5. Status Updates
|
||||
if (settings.statusUpdates) {
|
||||
if (settings.statusUpdates ?? true) {
|
||||
typeConditions.push({ type: NotificationType.metadata_field_updated_status })
|
||||
}
|
||||
|
||||
// 6. Always include team/project join notifications
|
||||
// 6. Kanban Tasks
|
||||
if (settings.kanbanTasks ?? true) {
|
||||
typeConditions.push({
|
||||
type: {
|
||||
in: [
|
||||
NotificationType.kanban_task_created,
|
||||
NotificationType.kanban_task_assigned,
|
||||
NotificationType.kanban_task_status_updated,
|
||||
NotificationType.kanban_task_updated,
|
||||
NotificationType.kanban_task_deleted,
|
||||
],
|
||||
},
|
||||
userId: userId,
|
||||
})
|
||||
}
|
||||
|
||||
// 7. Kanban Comments
|
||||
if (settings.kanbanComments ?? true) {
|
||||
typeConditions.push({
|
||||
type: NotificationType.kanban_task_comment_created,
|
||||
userId: userId,
|
||||
})
|
||||
}
|
||||
|
||||
// 8. Always include team/project join notifications
|
||||
typeConditions.push({ type: NotificationType.new_user_join_team })
|
||||
typeConditions.push({ type: NotificationType.new_user_join_project })
|
||||
|
||||
@@ -193,6 +299,7 @@ export class NotificationService {
|
||||
{
|
||||
OR: [
|
||||
{ type: NotificationType.mention }, // Always allow mentions (targeted)
|
||||
{ userId: userId }, // Direct targeted notifications (e.g. assigned, stakeholder)
|
||||
{ projectId: { in: projectFilter } }, // Only show notifications for projects user is member of
|
||||
],
|
||||
},
|
||||
@@ -270,6 +377,7 @@ export class NotificationService {
|
||||
project: true,
|
||||
asset: true,
|
||||
user: true,
|
||||
kanbanTask: true,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -329,7 +437,14 @@ export class NotificationService {
|
||||
|
||||
private async toNotificationInfo(
|
||||
n: Prisma.NotificationGetPayload<{
|
||||
include: { creator: true; team: true; project: true; asset: true; user: true }
|
||||
include: {
|
||||
creator: true
|
||||
team: true
|
||||
project: true
|
||||
asset: true
|
||||
user: true
|
||||
kanbanTask: true
|
||||
}
|
||||
}>,
|
||||
lastRead: Prisma.NotificationGetPayload<Record<string, never>> | null,
|
||||
): Promise<NotificationInfo> {
|
||||
@@ -368,6 +483,14 @@ export class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
if (n.kanbanTask) {
|
||||
info.kanbanTask = {
|
||||
id: n.kanbanTask.id,
|
||||
title: n.kanbanTask.title,
|
||||
status: n.kanbanTask.status,
|
||||
}
|
||||
}
|
||||
|
||||
if (n.asset) {
|
||||
const a = n.asset
|
||||
let previewUrl = ''
|
||||
|
||||
Reference in New Issue
Block a user