feat(comments): add internal comments and author comment editing (#552)

* feat(comments): add internal comments and author comment editing

* chore(i18n): add Korean comment translations and update AGENTS.md i18n rule

* style(comments): refine visibility selector corner radius and align send button height

* fix(webui): avoid ResizeObserver loop when resizing file browser
This commit is contained in:
Yiling-J
2026-11-26 14:54:45 +08:00
committed by GitHub
parent 1066900c78
commit fee6f39828
43 changed files with 2751 additions and 301 deletions
+110
View File
@@ -82,6 +82,7 @@ describe('file api', () => {
vi.spyOn(assetService, 'updateAssetName').mockImplementation(vi.fn())
vi.spyOn(assetService, 'deleteAssets').mockImplementation(vi.fn())
vi.spyOn(assetService, 'createComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'updateComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'completeComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'deleteComment').mockImplementation(vi.fn())
vi.spyOn(assetService, 'addCommentReaction').mockImplementation(vi.fn())
@@ -291,6 +292,7 @@ describe('file api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: false,
completionLastChangedBy: null,
reactionCounts: [],
})
@@ -351,6 +353,7 @@ describe('file api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: false,
completionLastChangedBy: null,
reactionCounts: [],
})
@@ -408,6 +411,7 @@ describe('file api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: false,
completionLastChangedBy: null,
reactionCounts: [],
},
@@ -553,6 +557,7 @@ describe('file api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: true,
isInternal: false,
completionLastChangedBy: { id: 'user1', name: 'Test User' },
reactionCounts: [],
})
@@ -579,6 +584,110 @@ describe('file api', () => {
expect(assetService.getComment).toHaveBeenCalledWith('comment-id', 'user1')
})
it('POST /files/:fileId/comments forwards isInternal', async () => {
vi.mocked(assetService.createComment).mockResolvedValue({
id: 'comment-internal-id',
assetId: 'test-id',
message: 'internal note',
annotations: null,
second: null,
creator: { id: 'user1', name: 'Test User' },
replies: [],
attachments: [],
mentions: [],
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: true,
completionLastChangedBy: null,
reactionCounts: [],
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/test-id/comments', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'internal note', attachmentIds: [], isInternal: true }),
})
expect(res.status).toBe(201)
const json = await res.json()
expect(json.isInternal).toBe(true)
expect(assetService.createComment).toHaveBeenCalledWith(
expect.objectContaining({
assetId: 'test-id',
userId: 'user1',
message: 'internal note',
isInternal: true,
}),
expect.anything(),
)
})
it('PATCH /comments/:commentId updates comment and logs comment_update audit entry', async () => {
vi.mocked(assetService.updateComment).mockResolvedValue({
id: 'comment-id',
assetId: 'file-id',
message: 'edited text',
annotations: null,
second: null,
creator: { id: 'user1', name: 'Test User' },
replies: [],
attachments: [],
mentions: [],
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: true,
completionLastChangedBy: null,
reactionCounts: [],
})
vi.mocked(assetService.getAssetContext).mockResolvedValue({
teamId: 'test-team',
projectId: 'proj-1',
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/comments/comment-id', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: 'edited text',
isInternal: true,
second: null,
attachmentIds: ['att-1'],
}),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json.message).toBe('edited text')
expect(json.isInternal).toBe(true)
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,
type: ResourceType.Comment,
id: 'comment-id',
})
expect(assetService.updateComment).toHaveBeenCalledWith({
commentId: 'comment-id',
userId: 'user1',
message: 'edited text',
isInternal: true,
second: null,
attachmentIds: ['att-1'],
})
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'comment_update',
teamId: 'test-team',
userId: 'user1',
projectId: 'proj-1',
itemId: 'comment-id',
})
})
it('POST /comments/:commentId/complete reopens with isCompleted false', async () => {
vi.mocked(runOperation).mockResolvedValue({ commentId: 'comment-id', resolved: false })
vi.mocked(assetService.getComment).mockResolvedValue({
@@ -1133,6 +1242,7 @@ describe('file api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: false,
completionLastChangedBy: null,
reactionCounts: [],
},
+34
View File
@@ -18,6 +18,7 @@ import {
import {
archiveAssetsRequestSchema,
createCommentRequestSchema,
updateCommentRequestSchema,
deleteFilesRequestSchema,
batchGetFilesRequestSchema,
paginationParamsSchema,
@@ -199,6 +200,7 @@ const route = new Hono<{ Variables: { user: User } }>()
annotations: req.annotations,
second: req.second,
attachmentIds: req.attachmentIds,
isInternal: req.isInternal,
})
const context = await assetService.getAssetContext(fileId)
@@ -361,6 +363,38 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json(await assetService.getComment(commentId, user.id))
},
)
.patch('/comments/:commentId', zValidator('json', updateCommentRequestSchema), async (c) => {
const commentId = c.req.param('commentId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Comment,
id: commentId,
})
const updated = await assetService.updateComment({
commentId,
userId: user.id,
message: req.message,
isInternal: req.isInternal,
second: req.second,
attachmentIds: req.attachmentIds,
})
const context = await assetService.getAssetContext(updated.assetId)
await auditLogService.logAction({
action: AuditAction.comment_update,
teamId: context.teamId,
userId: user.id,
projectId: context.projectId,
itemId: commentId,
})
return c.json(updated)
})
.delete('/comments/:commentId', async (c) => {
const commentId = c.req.param('commentId')
const user = c.get('user')
@@ -65,6 +65,7 @@ describe('public share print comments and frame api', () => {
updatedAt: new Date().toISOString(),
sessionId: null,
isCompleted: false,
isInternal: false,
completionLastChangedBy: null,
reactionCounts: [],
},
@@ -76,6 +77,9 @@ describe('public share print comments and frame api', () => {
})
expect(res.status).toBe(200)
expect(assetService.listAllComments).toHaveBeenCalledWith('file-1', undefined, {
excludeInternal: true,
})
const body = await res.json()
expect(body.breadcrumbs).toEqual(['Client Review', 'Inner Folder'])
expect(body.asset.ancestorFolders).toEqual([{ id: 'inner', name: 'Inner Folder' }])
@@ -127,4 +131,36 @@ describe('public share print comments and frame api', () => {
signal: expect.any(AbortSignal),
})
})
it('GET /shares/:shareId/files/:fileId/comments excludes internal comments', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
id: 'share-1',
rootFolderId: 'share-root',
projectId: 'proj-1',
} as never)
vi.spyOn(assetService, 'resolveTargetAssetId').mockResolvedValue('file-1')
const listSpy = vi.spyOn(assetService, 'listComments').mockResolvedValue({
data: [],
pageInfo: { cursor: undefined, total: 0 },
})
const app = new Hono().route('/', publicShareRoute)
const res = await app.request('/shares/share-1/files/file-1/comments')
expect(res.status).toBe(200)
expect(listSpy).toHaveBeenCalledWith('file-1', expect.anything(), undefined, {
excludeInternal: true,
})
})
it('POST /shares/:shareId/files/:fileId/comments rejects isInternal=true with 400', async () => {
const app = new Hono().route('/', publicShareRoute)
const res = await app.request('/shares/share-1/files/file-1/comments', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'secret', attachmentIds: [], isInternal: true }),
})
expect(res.status).toBe(400)
})
})
+32 -11
View File
@@ -155,6 +155,9 @@ function toFieldInfo(
}
export function handlePublicShareError(c: Context, err: unknown) {
if (err instanceof HTTPException) {
throw err
}
if (err instanceof ShareLinkPasswordInvalidError) {
return c.json({ error: 'Unauthorized' }, 401)
}
@@ -273,13 +276,16 @@ const route = app
order = parts[1]
}
const res = await assetService.listChildren({
...req,
assetId: folderId,
assetType: req.assetType || 'file',
sort,
order,
})
const res = await assetService.listChildren(
{
...req,
assetId: folderId,
assetType: req.assetType || 'file',
sort,
order,
},
{ excludeInternalComments: true },
)
if (shareLink.watermarkConfigId && res.data.length > 0) {
// Resolve symlink targets once and reuse for the media lookup, so each
@@ -327,7 +333,10 @@ const route = app
try {
const shareLink = await shareService.verifyPublicAccess(shareId, fileId, password)
let asset = await assetService.getAsset({ assetId: fileId })
let asset = await assetService.getAsset(
{ assetId: fileId },
{ excludeInternalComments: true },
)
// Only video/image/3d assets are subject to watermark protection; skip the
// watermark lookup entirely for other media types (pdf, audio, ...).
@@ -412,7 +421,9 @@ const route = app
const targetFileId = await assetService.resolveTargetAssetId(fileId)
const userId = await getPublicShareUserId(c, shareId)
const res = await assetService.listComments(targetFileId, req, userId)
const res = await assetService.listComments(targetFileId, req, userId, {
excludeInternal: true,
})
return c.json(res)
} catch (err) {
return handlePublicShareError(c, err)
@@ -426,7 +437,10 @@ const route = app
try {
const shareLink = await shareService.verifyPublicAccess(shareId, fileId, password)
let asset = await assetService.getAsset({ assetId: fileId })
let asset = await assetService.getAsset(
{ assetId: fileId },
{ excludeInternalComments: true },
)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
if (
@@ -447,7 +461,9 @@ const route = app
const targetFileId = await assetService.resolveTargetAssetId(fileId)
const userId = await getPublicShareUserId(c, shareId)
const comments = await assetService.listAllComments(targetFileId, userId)
const comments = await assetService.listAllComments(targetFileId, userId, {
excludeInternal: true,
})
// Scope breadcrumbs strictly to folders inside the share link root so private
// project and parent folder names are never leaked.
@@ -518,6 +534,10 @@ const route = app
return c.json({ error: 'Attachments are not allowed on public share comments' }, 400)
}
if (req.isInternal) {
return c.json({ error: 'Internal comments are not allowed on public share links' }, 400)
}
try {
const shareLink = await shareService.verifyPublicAccess(shareId, fileId, password)
@@ -540,6 +560,7 @@ const route = app
annotations: req.annotations,
second: req.second,
attachmentIds: req.attachmentIds,
isInternal: false,
},
{ shareLinkId: shareId },
)
+1
View File
@@ -305,6 +305,7 @@ describe('Share API', () => {
sort: 'name',
order: 'asc',
}),
{ excludeInternalComments: true },
)
})