mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
Merge commit from fork
* 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>
This commit is contained in:
@@ -6,6 +6,7 @@ import { AssetType } from '@shumai/db'
|
||||
import { authMiddleware } from './middleware/auth'
|
||||
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
|
||||
vi.mock('./middleware/auth', () => ({
|
||||
// any is used here because Hono's Context and Next types are complex to mock in vitest.mock
|
||||
@@ -84,4 +85,28 @@ describe('Attachment API', () => {
|
||||
itemId: 'asset1',
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the upload key inside the attachment folder', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(assetService.createAsset).mockResolvedValue({ id: 'asset1' } as any)
|
||||
vi.mocked(s3Service.presign).mockResolvedValue('http://mock-s3-url')
|
||||
|
||||
const fileName = '../../files/01JAAAAAAAAAAAAAAAAAAAAAAA/master.mov'
|
||||
const res = await app.request('/projects/project1/attachments', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer test' },
|
||||
body: JSON.stringify({ fileName, contentType: 'video/quicktime', size: 100 }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const key = vi.mocked(assetService.createAsset).mock.lastCall?.[0].key as string
|
||||
const parts = key.split('/')
|
||||
expect(parts[0]).toBe('attachments')
|
||||
expect(parts).toHaveLength(3)
|
||||
expect(parts).not.toContain('..')
|
||||
expect(s3Service.presign).toHaveBeenCalledWith(expect.any(String), key, 'PUT')
|
||||
expect(assetService.createAsset).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: fileName }),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
||||
import { projectService } from '@shumai/core/src/project/project'
|
||||
import { AssetType } from '@shumai/db'
|
||||
import { ulid } from 'ulid'
|
||||
import { sanitizeFilename } from '@shumai/core/src/utils/filename'
|
||||
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import type { Prisma } from '@shumai/db'
|
||||
|
||||
@@ -27,7 +28,7 @@ const route = new Hono<{ Variables: { user: User } }>().post(
|
||||
id: projectId,
|
||||
})
|
||||
|
||||
const key = `attachments/${ulid()}/${req.fileName}`
|
||||
const key = `attachments/${ulid()}/${sanitizeFilename(req.fileName)}`
|
||||
|
||||
const assetInfo = await assetService.createAsset({
|
||||
name: req.fileName,
|
||||
|
||||
@@ -30,7 +30,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const attachment = await kanbanService.createAttachment(teamId, req)
|
||||
const attachment = await kanbanService.createAttachment(teamId, user.id, req)
|
||||
return c.json(attachment)
|
||||
},
|
||||
)
|
||||
@@ -123,7 +123,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: taskId,
|
||||
})
|
||||
|
||||
const events = await kanbanService.listEvents(taskId)
|
||||
const events = await kanbanService.listEvents(taskId, user.id)
|
||||
return c.json({ data: events })
|
||||
})
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import { kanbanService } from '@shumai/core/src/kanban/kanban'
|
||||
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
||||
import { notificationService } from '@shumai/core/src/notification/notification'
|
||||
import { KanbanTaskStatus, KanbanTaskPriority } from '@shumai/db/enums'
|
||||
import { HTTPException } from 'hono/http-exception'
|
||||
import { authzService } from '@shumai/core/src/authz/authz'
|
||||
import kanbanRoute from './index'
|
||||
|
||||
vi.mock('@shumai/core/src/authz/authz', () => ({
|
||||
@@ -19,6 +21,7 @@ vi.mock('@shumai/core/src/authz/authz', () => ({
|
||||
ResourceType: {
|
||||
Team: 'team',
|
||||
Project: 'project',
|
||||
Asset: 'asset',
|
||||
KanbanGoal: 'kanbanGoal',
|
||||
KanbanTask: 'kanbanTask',
|
||||
},
|
||||
@@ -51,6 +54,7 @@ describe('Kanban API Routes', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.mocked(authzService.hasPermission).mockResolvedValue(undefined)
|
||||
vi.mocked(auditLogService.logAction).mockResolvedValue({} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(notificationService.notifyKanbanTaskEvent).mockResolvedValue(undefined as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
app = new Hono()
|
||||
@@ -218,6 +222,7 @@ describe('Kanban API Routes', () => {
|
||||
status: 'READY',
|
||||
goalId: 'goal-1',
|
||||
}),
|
||||
'user-1',
|
||||
)
|
||||
})
|
||||
|
||||
@@ -248,7 +253,7 @@ describe('Kanban API Routes', () => {
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.id).toBe(taskId)
|
||||
expect(mockGet).toHaveBeenCalledWith(taskId)
|
||||
expect(mockGet).toHaveBeenCalledWith(taskId, 'user-1')
|
||||
})
|
||||
|
||||
it('PATCH /teams/:teamId/kanban/tasks/:taskId', async () => {
|
||||
@@ -493,6 +498,74 @@ describe('Kanban API Routes', () => {
|
||||
expect(mockLinkAssets).toHaveBeenCalledWith(teamId, taskId, ['asset-1', 'asset-2'])
|
||||
})
|
||||
|
||||
describe('linking files the caller cannot read', () => {
|
||||
const denyAsset = (deniedAssetId: string) =>
|
||||
vi.mocked(authzService.hasPermission).mockImplementation(async (req) => {
|
||||
if (req.type === 'asset' && req.id === deniedAssetId) {
|
||||
throw new HTTPException(403, { message: 'User has only project scope' })
|
||||
}
|
||||
})
|
||||
|
||||
it('checks Read on every file linked to a task', async () => {
|
||||
const mockLinkAssets = vi.spyOn(kanbanService, 'linkAssets').mockResolvedValue(undefined)
|
||||
denyAsset('asset-2')
|
||||
|
||||
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/assets`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ assetIds: ['asset-1', 'asset-2'] }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
expect(mockLinkAssets).not.toHaveBeenCalled()
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: 'asset', id: 'asset-1', permission: 'Read' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('checks Read on the file when linking it from the file side', async () => {
|
||||
const mockLinkAsset = vi.spyOn(kanbanService, 'linkAsset').mockResolvedValue(undefined)
|
||||
denyAsset('asset-1')
|
||||
|
||||
const res = await app.request(`/teams/${teamId}/kanban/assets/asset-1/tasks`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ taskId }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
expect(mockLinkAsset).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('checks Read on files passed when updating a task', async () => {
|
||||
const mockUpdate = vi.spyOn(kanbanService, 'updateTask')
|
||||
denyAsset('asset-9')
|
||||
|
||||
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ assetIds: ['asset-9'] }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
expect(mockUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('checks Read on files passed when creating a task', async () => {
|
||||
const mockCreate = vi.spyOn(kanbanService, 'createTask')
|
||||
denyAsset('asset-9')
|
||||
|
||||
const res = await app.request(`/teams/${teamId}/kanban/tasks`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ title: 'Task', assetIds: ['asset-9'] }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
expect(mockCreate).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it('DELETE /teams/:teamId/kanban/tasks/:taskId/assets/:assetId', async () => {
|
||||
const mockUnlinkAsset = vi.spyOn(kanbanService, 'unlinkAsset').mockResolvedValue(undefined)
|
||||
|
||||
@@ -530,7 +603,7 @@ describe('Kanban API Routes', () => {
|
||||
const json = await res.json()
|
||||
expect(json.total).toBe(1)
|
||||
expect(json.data).toHaveLength(1)
|
||||
expect(mockListTasksForAsset).toHaveBeenCalledWith(teamId, 'asset-1')
|
||||
expect(mockListTasksForAsset).toHaveBeenCalledWith(teamId, 'asset-1', 'user-1')
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/kanban/assets/:assetId/tasks', async () => {
|
||||
@@ -585,7 +658,7 @@ describe('Kanban API Routes', () => {
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.id).toBe('att-1')
|
||||
expect(mockAttachment).toHaveBeenCalledWith(teamId, {
|
||||
expect(mockAttachment).toHaveBeenCalledWith(teamId, 'user-1', {
|
||||
fileName: 'test.png',
|
||||
size: 1024,
|
||||
contentType: 'image/png',
|
||||
@@ -683,7 +756,7 @@ describe('Kanban API Routes', () => {
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.data).toHaveLength(1)
|
||||
expect(mockEvents).toHaveBeenCalledWith(taskId)
|
||||
expect(mockEvents).toHaveBeenCalledWith(taskId, 'user-1')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -22,6 +22,21 @@ 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()
|
||||
@@ -40,6 +55,8 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
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({
|
||||
@@ -89,7 +106,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const result = await kanbanService.listTasks(teamId, req)
|
||||
const result = await kanbanService.listTasks(teamId, req, user.id)
|
||||
return c.json(result)
|
||||
},
|
||||
)
|
||||
@@ -104,7 +121,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: taskId,
|
||||
})
|
||||
|
||||
const task = await kanbanService.getTask(taskId)
|
||||
const task = await kanbanService.getTask(taskId, user.id)
|
||||
return c.json(task)
|
||||
})
|
||||
.patch(
|
||||
@@ -122,6 +139,8 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
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)
|
||||
@@ -262,6 +281,8 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: taskId,
|
||||
})
|
||||
|
||||
await assertCanReadAssets(user, req.assetIds)
|
||||
|
||||
await kanbanService.linkAssets(teamId, taskId, req.assetIds)
|
||||
return c.json({ success: true })
|
||||
},
|
||||
@@ -291,7 +312,7 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const tasks = await kanbanService.listTasksForAsset(teamId, assetId)
|
||||
const tasks = await kanbanService.listTasksForAsset(teamId, assetId, user.id)
|
||||
return c.json({ data: tasks, total: tasks.length })
|
||||
})
|
||||
.post(
|
||||
@@ -309,6 +330,8 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: req.taskId,
|
||||
})
|
||||
|
||||
await assertCanReadAssets(user, [assetId])
|
||||
|
||||
await kanbanService.linkAsset(teamId, req.taskId, assetId)
|
||||
return c.json({ success: true })
|
||||
},
|
||||
|
||||
@@ -24,6 +24,7 @@ describe('public share print comments and frame api', () => {
|
||||
rootFolderId: 'share-root',
|
||||
projectId: 'proj-1',
|
||||
watermarkConfigId: null,
|
||||
fieldVisibility: { status: true, internalNote: false },
|
||||
} as never)
|
||||
|
||||
vi.spyOn(assetService, 'getAsset').mockResolvedValue({
|
||||
@@ -34,6 +35,11 @@ describe('public share print comments and frame api', () => {
|
||||
type: 'file',
|
||||
status: 'active',
|
||||
proxyType: 'video',
|
||||
fieldValues: [
|
||||
{ fieldId: 'status', value: 'Approved' },
|
||||
{ fieldId: 'internalNote', value: 'Private note' },
|
||||
{ fieldId: 'rating', value: 3 },
|
||||
],
|
||||
ancestorFolders: [
|
||||
{ id: 'inner', name: 'Inner Folder' },
|
||||
{ id: 'share-root', name: 'Share Root' },
|
||||
@@ -73,6 +79,7 @@ describe('public share print comments and frame api', () => {
|
||||
const body = await res.json()
|
||||
expect(body.breadcrumbs).toEqual(['Client Review', 'Inner Folder'])
|
||||
expect(body.asset.ancestorFolders).toEqual([{ id: 'inner', name: 'Inner Folder' }])
|
||||
expect(body.asset.fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
expect(JSON.stringify(body)).not.toContain('Secret Project Folder')
|
||||
expect(JSON.stringify(body)).not.toContain('private-parent')
|
||||
expect(body.comments).toHaveLength(1)
|
||||
|
||||
@@ -123,6 +123,20 @@ async function applyWatermarkToAssetMedia(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps only the custom field values the share link is configured to show.
|
||||
* Fields are hidden by default; `fieldVisibility` lists the keys turned on
|
||||
* for this share, matching what `GET /shares/:shareId/fields` returns.
|
||||
*/
|
||||
function filterSharedFieldValues(asset: AssetInfo, fieldVisibility: unknown): AssetInfo {
|
||||
if (!asset.fieldValues) return asset
|
||||
const visibility = (fieldVisibility || {}) as Record<string, boolean>
|
||||
return {
|
||||
...asset,
|
||||
fieldValues: asset.fieldValues.filter((fv) => Boolean(visibility[fv.fieldId])),
|
||||
}
|
||||
}
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
function toFieldInfo(
|
||||
@@ -297,6 +311,8 @@ const route = app
|
||||
}
|
||||
}
|
||||
|
||||
res.data = res.data.map((item) => filterSharedFieldValues(item, shareLink.fieldVisibility))
|
||||
|
||||
return c.json(res)
|
||||
} catch (err) {
|
||||
return handlePublicShareError(c, err)
|
||||
@@ -335,7 +351,7 @@ const route = app
|
||||
asset.media.hls.url = `/api/shares/${shareLink.id}/files/${asset.id}/m3u8/master.m3u8${pwQuery}`
|
||||
}
|
||||
|
||||
return c.json(asset)
|
||||
return c.json(filterSharedFieldValues(asset, shareLink.fieldVisibility))
|
||||
} catch (err) {
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
@@ -445,7 +461,10 @@ const route = app
|
||||
const breadcrumbs = shareLink.name ? [shareLink.name, ...scopedFolders] : scopedFolders
|
||||
|
||||
return c.json({
|
||||
asset: { ...asset, ancestorFolders: scopedAncestors },
|
||||
asset: {
|
||||
...filterSharedFieldValues(asset, shareLink.fieldVisibility),
|
||||
ancestorFolders: scopedAncestors,
|
||||
},
|
||||
breadcrumbs,
|
||||
comments,
|
||||
})
|
||||
|
||||
@@ -438,6 +438,119 @@ describe('Share API', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('public share field values', () => {
|
||||
const shareLinkWithFields = {
|
||||
id: 'share1',
|
||||
name: 'My Share',
|
||||
isDisabled: false,
|
||||
allowDownload: false,
|
||||
rootFolderId: 'folder1',
|
||||
projectId: 'project1',
|
||||
password: null,
|
||||
expireAt: null,
|
||||
watermarkConfigId: null,
|
||||
fieldVisibility: { status: true, internalNote: false },
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any
|
||||
|
||||
const assetWithFields = {
|
||||
id: 'file1',
|
||||
name: 'a.png',
|
||||
sizeByte: 1,
|
||||
fileCount: 0,
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
proxyType: 'pdf',
|
||||
fieldValues: [
|
||||
{ fieldId: 'status', value: 'Approved' },
|
||||
{ fieldId: 'internalNote', value: 'not for guests' },
|
||||
{ fieldId: 'rating', value: 3 },
|
||||
],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any
|
||||
|
||||
test('children only include field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithFields)
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('children with watermark only include field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
watermarkConfigId: 'cfg1',
|
||||
})
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
vi.spyOn(assetService, 'resolveLatestVersionId').mockImplementation(async (id) => id)
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('children include no field values when the share shows no fields', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
fieldVisibility: null,
|
||||
})
|
||||
vi.spyOn(assetService, 'listChildren').mockResolvedValue({
|
||||
data: [assetWithFields],
|
||||
pageInfo: { total: 1, cursor: undefined },
|
||||
})
|
||||
|
||||
const res = await app.request('/shares/share1/folders/folder1/children?assetType=file')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.data[0].fieldValues).toEqual([])
|
||||
})
|
||||
|
||||
test('file detail only includes field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithFields)
|
||||
vi.spyOn(assetService, 'getAsset').mockResolvedValue(assetWithFields)
|
||||
|
||||
const res = await app.request('/shares/share1/files/file1')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
|
||||
test('file detail with watermark only includes field values visible on the share', async () => {
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
...shareLinkWithFields,
|
||||
watermarkConfigId: 'cfg1',
|
||||
})
|
||||
vi.spyOn(assetService, 'getAsset').mockResolvedValue({
|
||||
...assetWithFields,
|
||||
proxyType: 'image',
|
||||
media: { proxyType: 'image', videoTranscodes: [], imageTranscodes: [] },
|
||||
})
|
||||
vi.spyOn(assetService, 'resolveLatestVersionId').mockResolvedValue('file1')
|
||||
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
|
||||
|
||||
const res = await app.request('/shares/share1/files/file1')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.fieldValues).toEqual([{ fieldId: 'status', value: 'Approved' }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /shares/:shareId/files/:fileId', () => {
|
||||
const shareLinkWithWatermark = {
|
||||
id: 'share1',
|
||||
|
||||
Reference in New Issue
Block a user