mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 22:14:50 +00:00
* fix(share): only return share-visible field values on public share links The public share children and file detail endpoints returned every custom field value on an asset, while the share's field settings only hid them in the share UI. Filter fieldValues server-side to the fields turned on for the share, matching what GET /shares/:shareId/fields already returns. * fix(share): stop returning share passwords and compare them in constant time Share link responses included the saved password in plain text. Remove it from ShareLinkInfo; clients already get hasPassword. Check the password a guest enters with a constant-time comparison of SHA-256 digests instead of a string comparison. The share settings panel no longer pre-fills the saved password. When a password is set, the field starts empty with a hint, Save stays disabled until a new password is typed, and the field clears after saving. Turning the password off still removes it. * fix(kanban): limit task lists and task reads to the caller's projects Kanban checked only team membership for task reads, so a member invited to one project could list every task in the team and open any task, its linked files, comments and activity. - Task lists and the tasks linked to a file now include, for project-scoped members, only tasks in projects they belong to plus tasks they created, report, or are assigned to. Team-scoped members see every task as before. - Reading a task, its files, comments and activity follows the same rule: a project-scoped member outside the task's project needs to be its creator, reporter or assignee. - Linking a file to a task (create, update, or the link endpoints) now requires Read on that file, since linked files are shown to everyone who can read the task. * fix(security): sign only issued comment attachments and keep files on comment delete Kanban comment attachments: - Upload keys now include the team and the uploader: kanban/attachments/<teamId>/<userId>/<ulid>/<file name>. - addComment rejects any attachment key that was not issued to the comment author for the task's team, so a client can no longer store an arbitrary storage key in a comment. - When comments are read, only keys of kanban comment attachments for the task's team (or the previous kanban/attachments/<ulid>/<name> form) are presigned. Keys stored earlier that point anywhere else are dropped. Asset comment attachments: - createComment only links attachment uploads made by the commenter in the same project that are not linked to another comment. Project files can no longer be linked as comment attachments. - deleteComment deletes the stored object and asset only for attachment uploads not linked elsewhere; anything else linked to the comment is only unlinked. Upload keys: - Sanitize the file name in kanban and project attachment upload keys, as regular uploads already do, so a name cannot add path segments. - The local storage backend rejects keys with a '..' segment instead of resolving them into another object's path. * fix(security): enforce visibility and protect comment attachments --------- Co-authored-by: phj1081 <5908832+phj1081@users.noreply.github.com>
355 lines
10 KiB
TypeScript
355 lines
10 KiB
TypeScript
import { zValidator } from '@hono/zod-validator'
|
|
import { Hono } from 'hono'
|
|
import { kanbanService } from '@shumai/core/src/kanban/kanban'
|
|
import { notificationService } from '@shumai/core/src/notification/notification'
|
|
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
|
import {
|
|
authzService,
|
|
Permission,
|
|
ResourceType,
|
|
resolveEffectiveRole,
|
|
} from '@shumai/core/src/authz/authz'
|
|
import {
|
|
createKanbanTaskSchema,
|
|
updateKanbanTaskSchema,
|
|
listKanbanTasksRequestSchema,
|
|
linkTaskAssetsSchema,
|
|
linkAssetToTaskSchema,
|
|
AuditAction,
|
|
} from '@shumai/dtos'
|
|
import type { Prisma } from '@shumai/db'
|
|
import { HTTPException } from 'hono/http-exception'
|
|
|
|
type User = Prisma.UserGetPayload<Record<string, never>>
|
|
|
|
/**
|
|
* Linking a file to a task shows its name, folder path and thumbnail to everyone
|
|
* who can read the task, so the caller must be able to read each linked file.
|
|
*/
|
|
async function assertCanReadAssets(user: User, assetIds: string[] | undefined) {
|
|
for (const id of new Set(assetIds ?? [])) {
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.Asset,
|
|
id,
|
|
})
|
|
}
|
|
}
|
|
|
|
const route = new Hono<{ Variables: { user: User } }>()
|
|
.post('/teams/:teamId/kanban/tasks', zValidator('json', createKanbanTaskSchema), async (c) => {
|
|
const { teamId } = c.req.param()
|
|
const req = c.req.valid('json')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.Team,
|
|
id: teamId,
|
|
})
|
|
|
|
const role = await resolveEffectiveRole(teamId, undefined, user.id)
|
|
if (!role) {
|
|
throw new HTTPException(403, { message: 'User is not a member of the team' })
|
|
}
|
|
|
|
await assertCanReadAssets(user, req.assetIds)
|
|
|
|
const task = await kanbanService.createTask(teamId, req, user.id, role)
|
|
|
|
await auditLogService.logAction({
|
|
action: AuditAction.kanban_task_create,
|
|
teamId,
|
|
userId: user.id,
|
|
projectId: task.projectId ?? undefined,
|
|
itemId: task.id,
|
|
})
|
|
|
|
if (req.assigneeId && req.assigneeId !== user.id) {
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_assigned',
|
|
teamId,
|
|
projectId: task.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: task.id,
|
|
targetUserId: req.assigneeId,
|
|
})
|
|
}
|
|
|
|
if (req.reporterId && req.reporterId !== user.id && req.reporterId !== req.assigneeId) {
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_created',
|
|
teamId,
|
|
projectId: task.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: task.id,
|
|
targetUserId: req.reporterId,
|
|
})
|
|
}
|
|
|
|
return c.json(task)
|
|
})
|
|
.get(
|
|
'/teams/:teamId/kanban/tasks',
|
|
zValidator('query', listKanbanTasksRequestSchema),
|
|
async (c) => {
|
|
const { teamId } = c.req.param()
|
|
const req = c.req.valid('query')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.Team,
|
|
id: teamId,
|
|
})
|
|
|
|
const result = await kanbanService.listTasks(teamId, req, user.id)
|
|
return c.json(result)
|
|
},
|
|
)
|
|
.get('/teams/:teamId/kanban/tasks/:taskId', async (c) => {
|
|
const { taskId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
const task = await kanbanService.getTask(taskId, user.id)
|
|
return c.json(task)
|
|
})
|
|
.patch(
|
|
'/teams/:teamId/kanban/tasks/:taskId',
|
|
zValidator('json', updateKanbanTaskSchema),
|
|
async (c) => {
|
|
const { teamId, taskId } = c.req.param()
|
|
const req = c.req.valid('json')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
await assertCanReadAssets(user, req.assetIds)
|
|
|
|
const existing = await kanbanService.getTask(taskId)
|
|
const role = await resolveEffectiveRole(teamId, existing.projectId ?? undefined, user.id)
|
|
const task = await kanbanService.updateTask(taskId, req, user.id, role)
|
|
|
|
const hasMeaningfulChanges =
|
|
req.title !== undefined ||
|
|
req.description !== undefined ||
|
|
req.priority !== undefined ||
|
|
req.startDate !== undefined ||
|
|
req.dueDate !== undefined ||
|
|
req.goalId !== undefined ||
|
|
req.assigneeId !== undefined ||
|
|
req.reporterId !== undefined ||
|
|
req.targetFolderId !== undefined ||
|
|
(req.status !== undefined && req.status !== existing.status)
|
|
|
|
if (hasMeaningfulChanges) {
|
|
await auditLogService.logAction({
|
|
action: AuditAction.kanban_task_update,
|
|
teamId,
|
|
userId: user.id,
|
|
projectId: task.projectId ?? undefined,
|
|
itemId: task.id,
|
|
})
|
|
}
|
|
|
|
if (req.status !== undefined && req.status !== existing.status) {
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_status_updated',
|
|
teamId,
|
|
projectId: task.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: task.id,
|
|
stakeholderIds: [task.creator?.id, task.assignee?.id, task.reporter?.id],
|
|
})
|
|
}
|
|
|
|
if (
|
|
req.assigneeId !== undefined &&
|
|
req.assigneeId !== existing.assignee?.id &&
|
|
req.assigneeId !== null &&
|
|
req.assigneeId !== user.id
|
|
) {
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_assigned',
|
|
teamId,
|
|
projectId: task.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: task.id,
|
|
targetUserId: req.assigneeId,
|
|
})
|
|
}
|
|
|
|
const hasOtherDetailsChanged =
|
|
req.title !== undefined ||
|
|
req.description !== undefined ||
|
|
req.priority !== undefined ||
|
|
req.startDate !== undefined ||
|
|
req.dueDate !== undefined ||
|
|
req.goalId !== undefined ||
|
|
req.reporterId !== undefined ||
|
|
req.targetFolderId !== undefined
|
|
|
|
if (hasOtherDetailsChanged && req.status === undefined) {
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_updated',
|
|
teamId,
|
|
projectId: task.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: task.id,
|
|
stakeholderIds: [task.creator?.id, task.assignee?.id, task.reporter?.id],
|
|
})
|
|
}
|
|
|
|
return c.json(task)
|
|
},
|
|
)
|
|
.delete('/teams/:teamId/kanban/tasks/:taskId', async (c) => {
|
|
const { teamId, taskId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
const existing = await kanbanService.getTask(taskId)
|
|
const role = await resolveEffectiveRole(teamId, existing.projectId ?? undefined, user.id)
|
|
|
|
notificationService.notifyKanbanTaskEvent({
|
|
type: 'kanban_task_deleted',
|
|
teamId,
|
|
projectId: existing.projectId,
|
|
creatorId: user.id,
|
|
kanbanTaskId: taskId,
|
|
stakeholderIds: [existing.creator?.id, existing.assignee?.id, existing.reporter?.id],
|
|
})
|
|
|
|
await auditLogService.logAction({
|
|
action: AuditAction.kanban_task_delete,
|
|
teamId,
|
|
userId: user.id,
|
|
projectId: existing.projectId ?? undefined,
|
|
itemId: taskId,
|
|
})
|
|
|
|
await kanbanService.deleteTask(taskId, user.id, role)
|
|
return c.json({ success: true })
|
|
})
|
|
.get('/teams/:teamId/kanban/tasks/:taskId/assets', async (c) => {
|
|
const { taskId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
const assets = await kanbanService.listTaskAssets(taskId)
|
|
return c.json(assets)
|
|
})
|
|
.post(
|
|
'/teams/:teamId/kanban/tasks/:taskId/assets',
|
|
zValidator('json', linkTaskAssetsSchema),
|
|
async (c) => {
|
|
const { teamId, taskId } = c.req.param()
|
|
const req = c.req.valid('json')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
await assertCanReadAssets(user, req.assetIds)
|
|
|
|
await kanbanService.linkAssets(teamId, taskId, req.assetIds)
|
|
return c.json({ success: true })
|
|
},
|
|
)
|
|
.delete('/teams/:teamId/kanban/tasks/:taskId/assets/:assetId', async (c) => {
|
|
const { teamId, taskId, assetId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
await kanbanService.unlinkAsset(teamId, taskId, assetId)
|
|
return c.json({ success: true })
|
|
})
|
|
.get('/teams/:teamId/kanban/assets/:assetId/tasks', async (c) => {
|
|
const { teamId, assetId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.Team,
|
|
id: teamId,
|
|
})
|
|
|
|
const tasks = await kanbanService.listTasksForAsset(teamId, assetId, user.id)
|
|
return c.json({ data: tasks, total: tasks.length })
|
|
})
|
|
.post(
|
|
'/teams/:teamId/kanban/assets/:assetId/tasks',
|
|
zValidator('json', linkAssetToTaskSchema),
|
|
async (c) => {
|
|
const { teamId, assetId } = c.req.param()
|
|
const req = c.req.valid('json')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: req.taskId,
|
|
})
|
|
|
|
await assertCanReadAssets(user, [assetId])
|
|
|
|
await kanbanService.linkAsset(teamId, req.taskId, assetId)
|
|
return c.json({ success: true })
|
|
},
|
|
)
|
|
.delete('/teams/:teamId/kanban/assets/:assetId/tasks/:taskId', async (c) => {
|
|
const { teamId, assetId, taskId } = c.req.param()
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.KanbanTask,
|
|
id: taskId,
|
|
})
|
|
|
|
await kanbanService.unlinkAsset(teamId, taskId, assetId)
|
|
return c.json({ success: true })
|
|
})
|
|
|
|
export default route
|