@allbluecn/web-app 0.27.10 → 0.27.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/__tests__/bench/baselines/format-timestamp.json +44 -0
- package/src/__typeprobe__.d.ts +4 -0
- package/src/components/bug/__tests__/peek-modes.test.tsx +1 -0
- package/src/components/bug/__tests__/saved-views.test.tsx +1 -0
- package/src/components/bug/__tests__/toolbar-shell.test.tsx +1 -0
- package/src/components/bug/__tests__/view-type.test.tsx +1 -0
- package/src/components/bug/bug-list-view.tsx +3 -1
- package/src/components/shared-kit/peek/__tests__/dock-resize.test.tsx +153 -0
- package/src/components/shared-kit/peek/dock-resize.ts +214 -0
- package/src/components/story/detail/story-detail-toolbar/children.tsx +5 -3
- package/src/components/story/peek-panel.tsx +81 -17
- package/src/components/story/relations/story-ref-row.tsx +14 -10
- package/src/components/story/story-list-view.tsx +1 -1
- package/src/components/story/views/story-list/index.tsx +4 -1
- package/src/components/story/views/story-list/row.tsx +24 -18
- package/src/components/testcase/__tests__/filters.test.tsx +1 -0
- package/src/components/testcase/__tests__/list-view-scope.test.tsx +1 -0
- package/src/components/testcase/__tests__/list-view.test.tsx +1 -0
- package/src/components/testcase/__tests__/peek-panel.test.tsx +1 -0
- package/src/components/testcase/__tests__/view-fallback.test.tsx +1 -0
- package/src/components/testcase/list-view.tsx +3 -1
- package/src/lib/changelog/sdk-versions.ts +2 -2
- package/src/lib/collab/use-presence-list-refresh.ts +8 -1
- package/src/paraglide/README.md +1 -1
- package/src/paraglide/messages/_index.js +89922 -5751
- package/src/paraglide/messages/en.js +28780 -0
- package/src/paraglide/messages/story_peek_resizepanel1.js +30 -0
- package/src/paraglide/messages/zh.js +28778 -0
- package/src/server/bug/bug-crud-helpers.ts +9 -3
- package/src/server/lib/project-membership.ts +9 -3
- package/src/server/lib/validate-assignee.ts +9 -3
- package/src/server/serverFns/__tests__/story-crud.test.ts +2 -1
- package/src/server/serverFns/bug/__tests__/bug-crud.test.ts +2 -1
- package/src/server/serverFns/bug/bug-crud.ts +7 -5
- package/src/server/serverFns/story/__tests__/story-crud-date-key.test.ts +3 -0
- package/src/server/serverFns/story/story-crud.ts +23 -8
- package/src/server/serverFns/testcase/testcase-crud.ts +11 -10
- package/src/server/team-access.ts +10 -2
- package/src/server/testcase/permissions.ts +4 -2
|
@@ -18,19 +18,25 @@
|
|
|
18
18
|
// S2(裁决:纯机械拆分):bug-crud.ts 的纯 helper 子流程迁此——主文件只留
|
|
19
19
|
// serverFn 定义。import 自兄弟文件,测试经 bug-crud re-export 零改动。
|
|
20
20
|
|
|
21
|
+
import type { Prisma } from "@allbluecn/database";
|
|
21
22
|
import { getPrisma } from "@allbluecn/database/get-prisma";
|
|
22
23
|
import type { AvatarConfig } from "@allbluecn/kernel";
|
|
23
24
|
import { isUserInTeam } from "@/server/team-access";
|
|
24
25
|
|
|
25
|
-
export async function validateBugAssignee(
|
|
26
|
+
export async function validateBugAssignee(
|
|
27
|
+
projectId: string,
|
|
28
|
+
assigneeId: string | null | undefined,
|
|
29
|
+
db?: Prisma.TransactionClient,
|
|
30
|
+
) {
|
|
26
31
|
if (!assigneeId) return;
|
|
27
|
-
|
|
32
|
+
// db:事务内调用必须传 tx(PGlite 单连接死锁,见 lib/project-membership.ts 注)
|
|
33
|
+
const prisma = db ?? (await getPrisma());
|
|
28
34
|
const project = await prisma.project.findUnique({
|
|
29
35
|
where: { id: projectId },
|
|
30
36
|
select: { ownerId: true },
|
|
31
37
|
});
|
|
32
38
|
if (!project) throw new Error("项目不存在");
|
|
33
|
-
const ok = await isUserInTeam(project.ownerId, assigneeId);
|
|
39
|
+
const ok = await isUserInTeam(project.ownerId, assigneeId, db);
|
|
34
40
|
if (!ok) throw new Error("负责人必须是团队成员");
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -19,12 +19,17 @@
|
|
|
19
19
|
// 相同的 assertProjectMembership 副本,仅错误文案不同)。
|
|
20
20
|
// 语义与各副本完全一致:成员行不存在或 status === "suspended" 视为无权限(invited 放行)。
|
|
21
21
|
|
|
22
|
+
import type { Prisma } from "@allbluecn/database";
|
|
22
23
|
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
23
24
|
|
|
24
25
|
export const PROJECT_FORBIDDEN_MESSAGE = '无权限操作该项目'
|
|
25
26
|
|
|
26
|
-
export async function isProjectMember(projectId: string, userId: string): Promise<boolean> {
|
|
27
|
-
|
|
27
|
+
export async function isProjectMember(projectId: string, userId: string, db?: Prisma.TransactionClient): Promise<boolean> {
|
|
28
|
+
// db:事务内调用方必须传 tx——PGlite 单连接下事务独占实例,回调内经外层
|
|
29
|
+
// client 发查询 = 外层查询排在独占锁后等事务提交、事务又在等该查询 → 死锁
|
|
30
|
+
// 直到事务超时(P2028,云端连接池无此问题)。2026-11-06 客户端「更新卡死
|
|
31
|
+
// 30s」根因。validate-assignee / bug-crud-helpers / testcase permissions 同注。
|
|
32
|
+
const prisma = db ?? (await getPrisma())
|
|
28
33
|
const membership = await prisma.projectMember.findUnique({
|
|
29
34
|
where: { projectId_userId: { projectId, userId } },
|
|
30
35
|
select: { status: true },
|
|
@@ -36,8 +41,9 @@ export async function assertProjectMembership(
|
|
|
36
41
|
projectId: string,
|
|
37
42
|
userId: string,
|
|
38
43
|
message: string = PROJECT_FORBIDDEN_MESSAGE,
|
|
44
|
+
db?: Prisma.TransactionClient,
|
|
39
45
|
): Promise<void> {
|
|
40
|
-
if (!(await isProjectMember(projectId, userId))) {
|
|
46
|
+
if (!(await isProjectMember(projectId, userId, db))) {
|
|
41
47
|
throw new Error(message)
|
|
42
48
|
}
|
|
43
49
|
}
|
|
@@ -3,17 +3,23 @@
|
|
|
3
3
|
// Copyright (C) 2026 AllBlue Contributors
|
|
4
4
|
|
|
5
5
|
// 负责人合法性校验(story / testcase 双域共用,A2x-7 审计:两域曾各持一份逐字相同的本地实现)
|
|
6
|
+
import type { Prisma } from "@allbluecn/database";
|
|
6
7
|
import { getPrisma } from "@allbluecn/database/get-prisma";
|
|
7
8
|
import { isUserInTeam } from "@/server/team-access";
|
|
8
9
|
|
|
9
|
-
export async function validateAssignee(
|
|
10
|
+
export async function validateAssignee(
|
|
11
|
+
projectId: string,
|
|
12
|
+
assigneeId: string | null | undefined,
|
|
13
|
+
db?: Prisma.TransactionClient,
|
|
14
|
+
) {
|
|
10
15
|
if (!assigneeId) return;
|
|
11
|
-
|
|
16
|
+
// db:事务内调用必须传 tx(PGlite 单连接死锁,见 lib/project-membership.ts 注)
|
|
17
|
+
const prisma = db ?? (await getPrisma());
|
|
12
18
|
const project = await prisma.project.findUnique({
|
|
13
19
|
where: { id: projectId },
|
|
14
20
|
select: { ownerId: true },
|
|
15
21
|
});
|
|
16
22
|
if (!project) throw new Error("项目不存在");
|
|
17
|
-
const ok = await isUserInTeam(project.ownerId, assigneeId);
|
|
23
|
+
const ok = await isUserInTeam(project.ownerId, assigneeId, db);
|
|
18
24
|
if (!ok) throw new Error("负责人必须是团队成员");
|
|
19
25
|
}
|
|
@@ -367,7 +367,8 @@ describe("createStoryFn", () => {
|
|
|
367
367
|
await createStoryFn({ data: { name: "新需求", projectId: P, assigneeId: "u-2" } });
|
|
368
368
|
|
|
369
369
|
expect(M.projectFindUnique).toHaveBeenCalledWith({ where: { id: P }, select: { ownerId: true } });
|
|
370
|
-
|
|
370
|
+
// validateAssignee 现透传 db(事务外恒 undefined)——第三参签名扩展
|
|
371
|
+
expect(M.isUserInTeam).toHaveBeenCalledWith("owner-1", "u-2", undefined);
|
|
371
372
|
});
|
|
372
373
|
|
|
373
374
|
it("负责人不在团队内时抛错且不创建", async () => {
|
|
@@ -594,7 +594,8 @@ describe("updateBugFn", () => {
|
|
|
594
594
|
|
|
595
595
|
await updateBugFn({ data: { bugId: "b1", assigneeId: "u2" } });
|
|
596
596
|
|
|
597
|
-
|
|
597
|
+
// validateBugAssignee 现透传 db(事务内 = tx mock)——第三参签名扩展
|
|
598
|
+
expect(mocks.isUserInTeam).toHaveBeenCalledWith("owner-1", "u2", expect.anything());
|
|
598
599
|
expect(mocks.userFindUnique).toHaveBeenCalledWith({ where: { id: "u2" }, select: { username: true } });
|
|
599
600
|
expect(mocks.bugActivityCreate).toHaveBeenCalledWith(
|
|
600
601
|
expect.objectContaining({
|
|
@@ -64,8 +64,9 @@ const BUG_SOURCE_VALUES = BUG_SOURCES.map((s) => s.value) as [BugSource, ...BugS
|
|
|
64
64
|
// (事务内已有 existing.projectId,免二次反查)使用;成员谓词与
|
|
65
65
|
// assertBugsInMemberProjects/deleteBugFn 一致(有效成员关系,suspended 视同无权)
|
|
66
66
|
/** 项目有效成员校验(共享口径见 server/lib/project-membership:suspended 视同无权限) */
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// db:事务内调用(updateBugFn)必须传 tx——PGlite 单连接死锁,见 lib/project-membership.ts 注
|
|
68
|
+
const assertProjectMembership = (projectId: string, userId: string, _message?: string, db?: Prisma.TransactionClient) =>
|
|
69
|
+
assertProjectMembershipShared(projectId, userId, "无权限操作该项目的 BUG", db);
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
const listSchema = z.object({
|
|
@@ -404,11 +405,12 @@ export const updateBugFn = createServerFn({ method: "POST" })
|
|
|
404
405
|
});
|
|
405
406
|
if (!existing) throw new Error("BUG 不存在");
|
|
406
407
|
|
|
407
|
-
// R8:写路径成员校验,与 delete/archive/bulk 同口径(复用 existing.projectId
|
|
408
|
-
|
|
408
|
+
// R8:写路径成员校验,与 delete/archive/bulk 同口径(复用 existing.projectId 免二次反查)。
|
|
409
|
+
// 校验走 tx(PGlite 单连接死锁,见 lib/project-membership.ts 注)
|
|
410
|
+
await assertProjectMembership(existing.projectId, userId, undefined, tx);
|
|
409
411
|
|
|
410
412
|
if (data.assigneeId !== undefined) {
|
|
411
|
-
await validateBugAssignee(existing.projectId, data.assigneeId);
|
|
413
|
+
await validateBugAssignee(existing.projectId, data.assigneeId, tx);
|
|
412
414
|
}
|
|
413
415
|
|
|
414
416
|
const updates: Prisma.BugUpdateInput = {};
|
|
@@ -83,6 +83,9 @@ vi.mock("@allbluecn/database/get-prisma", () => {
|
|
|
83
83
|
const tx = {
|
|
84
84
|
story: { findUnique: mocks.storyFindUnique, update: mocks.storyUpdate },
|
|
85
85
|
storyActivity: { create: mocks.activityCreate },
|
|
86
|
+
// updateStoryFn 事务内成员校验改走 tx(PGlite 单连接死锁修复)后,
|
|
87
|
+
// assertProjectMembership 经 tx.projectMember 发查询
|
|
88
|
+
projectMember: { findUnique: mocks.memberFindUnique },
|
|
86
89
|
};
|
|
87
90
|
return {
|
|
88
91
|
getPrisma: async () => ({
|
|
@@ -36,8 +36,9 @@ import type { Prisma } from "@allbluecn/database";
|
|
|
36
36
|
import { assertProjectMembership as assertProjectMembershipShared } from "@/server/lib/project-membership";
|
|
37
37
|
|
|
38
38
|
/** 项目有效成员校验(共享口径见 server/lib/project-membership:suspended 视同无权限) */
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// db:事务内调用(updateStoryFn)必须传 tx——PGlite 单连接死锁,见 lib/project-membership.ts 注
|
|
40
|
+
const assertProjectMembership = (projectId: string, userId: string, _message?: string, db?: Prisma.TransactionClient) =>
|
|
41
|
+
assertProjectMembershipShared(projectId, userId, "无权限操作该项目的需求", db);
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
const listSchema = z.object({
|
|
@@ -120,8 +121,10 @@ export const createStoryFn = createServerFn({ method: "POST" })
|
|
|
120
121
|
// 发号 + 建单事务段已提取为共享导出(convertBugToStoryFn 复用,任务 6 DRY)
|
|
121
122
|
return withSequenceNumberRetry(
|
|
122
123
|
() =>
|
|
123
|
-
prisma.$transaction(
|
|
124
|
-
|
|
124
|
+
prisma.$transaction(
|
|
125
|
+
(tx) =>
|
|
126
|
+
createStoryInternal(tx, { ...data, projectId: resolvedProjectId }, userId),
|
|
127
|
+
STORY_TX_OPTIONS,
|
|
125
128
|
),
|
|
126
129
|
{ exhaustedMessage: "创建需求失败:编号冲突,请重试" },
|
|
127
130
|
);
|
|
@@ -196,6 +199,16 @@ function storyDescriptionToContent(description: string): { html: string; markdow
|
|
|
196
199
|
return { html: description, markdown: description };
|
|
197
200
|
}
|
|
198
201
|
|
|
202
|
+
/**
|
|
203
|
+
* 交互式事务超时选项。Prisma 缺省 5s:桌面端(PGlite)单连接,事务语句与
|
|
204
|
+
* 并发查询(PeekPanel 十余个并行 serverFn / 列表分页 / presence / 同步引擎)
|
|
205
|
+
* 在 PGlite 内部队列串行排队,排队等待计入事务计时——列表页繁忙时轻松击穿
|
|
206
|
+
* 5s 报 P2028「A query cannot be executed on an expired transaction」(实测
|
|
207
|
+
* 5005ms)。放宽到 30s(maxWait 同步放宽兜事务启动排队);云端连接池下
|
|
208
|
+
* 事务本体 <100ms,放宽无副作用——只影响真正拥塞时的等待上限。
|
|
209
|
+
*/
|
|
210
|
+
const STORY_TX_OPTIONS = { maxWait: 10_000, timeout: 30_000 } as const;
|
|
211
|
+
|
|
199
212
|
export const updateStoryFn = createServerFn({ method: "POST" })
|
|
200
213
|
.middleware([authContextMiddleware])
|
|
201
214
|
.validator(updateSchema)
|
|
@@ -252,16 +265,18 @@ export const updateStoryFn = createServerFn({ method: "POST" })
|
|
|
252
265
|
select: STORY_LIST_SELECT,
|
|
253
266
|
});
|
|
254
267
|
if (!existing) throw new Error("需求不存在");
|
|
255
|
-
|
|
268
|
+
// 事务内的成员/负责人校验必须走 tx:PGlite 单连接下事务独占实例,
|
|
269
|
+
// 经外层 client 发查询会与本事务互相等待(死锁至 P2028,云端连接池无此问题)
|
|
270
|
+
await assertProjectMembership(existing.projectId, userId, undefined, tx);
|
|
256
271
|
|
|
257
272
|
// 跨项目移动:目标项目同样须为有效成员(防止借移动向他项目注入数据)
|
|
258
273
|
const newProjectId = data.projectId ?? existing.projectId;
|
|
259
274
|
if (data.projectId !== undefined && newProjectId !== existing.projectId) {
|
|
260
|
-
await assertProjectMembership(newProjectId, userId);
|
|
275
|
+
await assertProjectMembership(newProjectId, userId, undefined, tx);
|
|
261
276
|
}
|
|
262
277
|
|
|
263
278
|
if (data.assigneeId !== undefined) {
|
|
264
|
-
await validateAssignee(existing.projectId, data.assigneeId);
|
|
279
|
+
await validateAssignee(existing.projectId, data.assigneeId, tx);
|
|
265
280
|
}
|
|
266
281
|
|
|
267
282
|
const updates: Prisma.StoryUpdateInput = {};
|
|
@@ -504,7 +519,7 @@ export const updateStoryFn = createServerFn({ method: "POST" })
|
|
|
504
519
|
? { ...castStoryUsers(updated), description: data.description }
|
|
505
520
|
: castStoryUsers(updated);
|
|
506
521
|
return { story: echo, activities: [] as ActivityItem[] };
|
|
507
|
-
});
|
|
522
|
+
}, STORY_TX_OPTIONS);
|
|
508
523
|
});
|
|
509
524
|
|
|
510
525
|
const deleteSchema = z.object({ storyId: z.string() });
|
|
@@ -57,10 +57,10 @@ import { touchCollabSnapshot } from "@/server/collab/touch-snapshot";
|
|
|
57
57
|
import { assertTestCaseProjectMember, assertTestProjectMembership as assertProjectMembership } from "@/server/testcase/permissions";
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
/** folderId
|
|
61
|
-
async function assertFolderInProject(projectId: string, folderId: string | null | undefined) {
|
|
60
|
+
/** folderId 归属校验(拒绝路径零写:事务前完成;事务内调用必须传 tx,PGlite 单连接死锁) */
|
|
61
|
+
async function assertFolderInProject(projectId: string, folderId: string | null | undefined, db?: Prisma.TransactionClient) {
|
|
62
62
|
if (!folderId) return;
|
|
63
|
-
const prisma = await getPrisma();
|
|
63
|
+
const prisma = db ?? (await getPrisma());
|
|
64
64
|
const folder = await prisma.testCaseFolder.findUnique({
|
|
65
65
|
where: { id: folderId },
|
|
66
66
|
select: { projectId: true },
|
|
@@ -68,10 +68,10 @@ async function assertFolderInProject(projectId: string, folderId: string | null
|
|
|
68
68
|
if (!folder || folder.projectId !== projectId) throw new Error("模块不存在或不属于该项目");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/** storyId
|
|
72
|
-
async function assertStoryInProject(projectId: string, storyId: string | null | undefined) {
|
|
71
|
+
/** storyId 归属校验(防止跨项目挂载,拒绝路径零写;事务内调用必须传 tx,PGlite 单连接死锁) */
|
|
72
|
+
async function assertStoryInProject(projectId: string, storyId: string | null | undefined, db?: Prisma.TransactionClient) {
|
|
73
73
|
if (!storyId) return;
|
|
74
|
-
const prisma = await getPrisma();
|
|
74
|
+
const prisma = db ?? (await getPrisma());
|
|
75
75
|
const story = await prisma.story.findUnique({
|
|
76
76
|
where: { id: storyId },
|
|
77
77
|
select: { projectId: true },
|
|
@@ -372,15 +372,16 @@ export const updateTestCaseFn = createServerFn({ method: "POST" })
|
|
|
372
372
|
select: TEST_CASE_LIST_SELECT,
|
|
373
373
|
});
|
|
374
374
|
if (!existing) throw new Error("用例不存在");
|
|
375
|
-
|
|
375
|
+
// 事务内的成员/归属/负责人校验必须走 tx(PGlite 单连接死锁,见 lib/project-membership.ts 注)
|
|
376
|
+
await assertProjectMembership(existing.projectId, userId, tx);
|
|
376
377
|
|
|
377
378
|
if (data.expectedVersion !== undefined && data.expectedVersion !== existing.version) {
|
|
378
379
|
throw new Error("用例已被他人修改(版本冲突),请刷新后重试");
|
|
379
380
|
}
|
|
380
381
|
|
|
381
|
-
await assertFolderInProject(existing.projectId, data.folderId);
|
|
382
|
-
await assertStoryInProject(existing.projectId, data.storyId);
|
|
383
|
-
await validateAssignee(existing.projectId, data.assigneeId);
|
|
382
|
+
await assertFolderInProject(existing.projectId, data.folderId, tx);
|
|
383
|
+
await assertStoryInProject(existing.projectId, data.storyId, tx);
|
|
384
|
+
await validateAssignee(existing.projectId, data.assigneeId, tx);
|
|
384
385
|
|
|
385
386
|
const updates: Prisma.TestCaseUpdateInput = {};
|
|
386
387
|
// 内容面(caseSnapshot 锁定的五个字段)实际变更才 version+1。
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { prisma } from '@allbluecn/database'
|
|
2
|
+
import type { Prisma } from '@allbluecn/database'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* db:调用方已有事务句柄(Prisma $transaction 的 tx)时必须传入——PGlite 单连接
|
|
6
|
+
* 下事务独占实例,回调内若经外层 client 发查询会与本事务互相等待(死锁直到
|
|
7
|
+
* Prisma 事务超时 P2028);云端连接池拿不同连接无此问题。下同(见
|
|
8
|
+
* lib/project-membership.ts 注)。
|
|
9
|
+
*/
|
|
10
|
+
export async function isUserInTeam(ownerId: string, userId: string, db?: Prisma.TransactionClient): Promise<boolean> {
|
|
4
11
|
if (ownerId === userId) return true
|
|
5
|
-
const
|
|
12
|
+
const client = db ?? prisma
|
|
13
|
+
const m = await client.teamMembership.findUnique({ where: { memberId: userId } })
|
|
6
14
|
return m?.ownerId === ownerId
|
|
7
15
|
}
|
|
8
16
|
|
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
// 测试模块「资源 → 项目 → 成员」守卫(审计 2026-10-25:getPlanFn / getRunFn / getRunCaseFn /
|
|
19
19
|
// getTestCaseFn / listTestCaseActivitiesFn 读侧无归属校验,而同文件写侧均有)。
|
|
20
20
|
|
|
21
|
+
import type { Prisma } from "@allbluecn/database";
|
|
21
22
|
import { getPrisma } from "@allbluecn/database/get-prisma";
|
|
22
23
|
import { assertProjectMembership } from "@/server/lib/project-membership";
|
|
23
24
|
|
|
24
25
|
export const TESTCASE_FORBIDDEN_MESSAGE = "无权限操作该项目的测试模块";
|
|
25
26
|
|
|
26
|
-
export function assertTestProjectMembership(projectId: string, userId: string): Promise<void> {
|
|
27
|
-
|
|
27
|
+
export function assertTestProjectMembership(projectId: string, userId: string, db?: Prisma.TransactionClient): Promise<void> {
|
|
28
|
+
// db:事务内调用必须传 tx(PGlite 单连接死锁,见 lib/project-membership.ts 注)
|
|
29
|
+
return assertProjectMembership(projectId, userId, TESTCASE_FORBIDDEN_MESSAGE, db);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export async function assertTestCaseProjectMember(caseId: string, userId: string): Promise<string> {
|