@allbluecn/web-app 0.27.11 → 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/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/story/peek-panel.tsx +24 -13
- package/src/components/story/story-list-view.tsx +1 -1
- 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 +1 -1
- package/src/lib/collab/use-presence-list-refresh.ts +8 -1
- 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 +8 -5
- 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
package/package.json
CHANGED
|
@@ -61,6 +61,7 @@ vi.mock("@/server/serverFns/project", () => ({
|
|
|
61
61
|
listProjectsBriefFn: vi.fn(() => Promise.resolve([])),
|
|
62
62
|
}));
|
|
63
63
|
vi.mock("@tanstack/react-router", () => ({
|
|
64
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
64
65
|
useNavigate: () => vi.fn(),
|
|
65
66
|
Link: ({
|
|
66
67
|
to,
|
|
@@ -55,6 +55,7 @@ vi.mock("@/server/serverFns/project", () => ({
|
|
|
55
55
|
ensureBuiltinProjectFn: vi.fn(() => Promise.resolve(null)),
|
|
56
56
|
}));
|
|
57
57
|
vi.mock("@tanstack/react-router", () => ({
|
|
58
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
58
59
|
useNavigate: () => vi.fn(),
|
|
59
60
|
}));
|
|
60
61
|
vi.mock("@/lib/collab/use-presence-list-refresh", () => ({
|
|
@@ -55,6 +55,7 @@ vi.mock("@/server/serverFns/project", () => ({
|
|
|
55
55
|
ensureBuiltinProjectFn: vi.fn(() => Promise.resolve(null)),
|
|
56
56
|
}));
|
|
57
57
|
vi.mock("@tanstack/react-router", () => ({
|
|
58
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
58
59
|
useNavigate: () => vi.fn(),
|
|
59
60
|
}));
|
|
60
61
|
vi.mock("@/lib/collab/use-presence-list-refresh", () => ({
|
|
@@ -61,6 +61,7 @@ vi.mock("@/server/serverFns/project", () => ({
|
|
|
61
61
|
ensureBuiltinProjectFn: vi.fn(() => Promise.resolve(null)),
|
|
62
62
|
}));
|
|
63
63
|
vi.mock("@tanstack/react-router", () => ({
|
|
64
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
64
65
|
useNavigate: () => vi.fn(),
|
|
65
66
|
}));
|
|
66
67
|
vi.mock("@/lib/collab/use-presence-list-refresh", () => ({
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
19
19
|
import { useNavigate } from "@tanstack/react-router";
|
|
20
|
+
import { useRouteContext } from "@tanstack/react-router";
|
|
20
21
|
import { usePresenceListRefresh } from "@/lib/collab/use-presence-list-refresh";
|
|
21
22
|
import { toastError } from "@/lib/toast-error";
|
|
22
23
|
import { toast } from "@/components/ui/toast";
|
|
@@ -81,6 +82,7 @@ function isPeekMode(v: string | null): v is PeekMode {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
export function BugListView({ users: initialUsers, projects: initialProjects, labels }: BugListViewProps) {
|
|
85
|
+
const { session } = useRouteContext({ from: "/_nav/bugs/" });
|
|
84
86
|
const navigate = useNavigate();
|
|
85
87
|
const [filterConditions, setFilterConditions] = useState<FilterCondition[]>([]);
|
|
86
88
|
const [projects, setProjects] = useState(initialProjects);
|
|
@@ -360,7 +362,7 @@ export function BugListView({ users: initialUsers, projects: initialProjects, la
|
|
|
360
362
|
const refreshBugList = useCallback(() => {
|
|
361
363
|
paged.refresh();
|
|
362
364
|
}, [paged.refresh]);
|
|
363
|
-
usePresenceListRefresh({ module: "bugs", refresh: refreshBugList });
|
|
365
|
+
usePresenceListRefresh({ module: "bugs", refresh: refreshBugList, selfUserId: session?.user?.id });
|
|
364
366
|
|
|
365
367
|
// ── 看板列组装(任务 33 / 任务 41):paged groups 条目数据 → Record<列 key, items> ──
|
|
366
368
|
// 取舍:bug 无 board 专用 columns serverFn(testcase 的 listTestCaseBoardColumnsFn
|
|
@@ -230,6 +230,11 @@ export function StoryPeekPanel({
|
|
|
230
230
|
|
|
231
231
|
useEffect(() => {
|
|
232
232
|
let cancelled = false;
|
|
233
|
+
// 切换/卸载即中止上一条需求的在途请求(TanStack serverFn 原生支持 signal):
|
|
234
|
+
// 连续点击时旧响应不再解码、旧 story 不再挂载详情树——桌面端实测爆发期
|
|
235
|
+
// 请求墙钟 140ms 全来自渲染主线程拥塞(服务端仅 2-5ms),中止旧载是
|
|
236
|
+
// 「连点卡死/不切换」的主修。中止抛错走 cancelled 分支,不进错误态。
|
|
237
|
+
const abort = new AbortController();
|
|
233
238
|
setError(null);
|
|
234
239
|
// 跳转时保留旧内容(不 setData(null)):同步卸载含 TipTap 等重节点的详情树会
|
|
235
240
|
// 阻塞主线程,导致顶部 MorphIcon 关闭/返回按钮的形变动画掉帧卡顿。
|
|
@@ -238,17 +243,17 @@ export function StoryPeekPanel({
|
|
|
238
243
|
// 并行化提速:只需 storyId 的请求与 detail 同时发出(原实现先等 detail
|
|
239
244
|
// 再串行十连发,白付一个 RTT);仅 labels/stories/iterations 依赖
|
|
240
245
|
// story.projectId,detail 落地后再补发并二次合并。
|
|
241
|
-
const detailP = getStoryDetailFn({ data: { storyId: effectiveStoryId } });
|
|
246
|
+
const detailP = getStoryDetailFn({ data: { storyId: effectiveStoryId }, signal: abort.signal });
|
|
242
247
|
const restP = Promise.all([
|
|
243
|
-
listCommentsFn({ data: { storyId: effectiveStoryId } }),
|
|
244
|
-
listActivitiesFn({ data: { storyId: effectiveStoryId, take: 50 } }),
|
|
245
|
-
listLabelsFn({ data: {} }), // S24:prefetch 阶段无 story.projectId,全量标签;创建走详情态编辑器
|
|
246
|
-
listChildStoriesFn({ data: { parentId: effectiveStoryId } }),
|
|
247
|
-
getDependenciesFn({ data: { storyId: effectiveStoryId } }),
|
|
248
|
-
getLinksFn({ data: { storyId: effectiveStoryId } }),
|
|
249
|
-
getAttachmentsFn({ data: { storyId: effectiveStoryId } }),
|
|
250
|
-
getLinkedDesignsFn({ data: { storyId: effectiveStoryId } }),
|
|
251
|
-
getLinkedDocsFn({ data: { storyId: effectiveStoryId } }),
|
|
248
|
+
listCommentsFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
249
|
+
listActivitiesFn({ data: { storyId: effectiveStoryId, take: 50 }, signal: abort.signal }),
|
|
250
|
+
listLabelsFn({ data: {}, signal: abort.signal }), // S24:prefetch 阶段无 story.projectId,全量标签;创建走详情态编辑器
|
|
251
|
+
listChildStoriesFn({ data: { parentId: effectiveStoryId }, signal: abort.signal }),
|
|
252
|
+
getDependenciesFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
253
|
+
getLinksFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
254
|
+
getAttachmentsFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
255
|
+
getLinkedDesignsFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
256
|
+
getLinkedDocsFn({ data: { storyId: effectiveStoryId }, signal: abort.signal }),
|
|
252
257
|
]);
|
|
253
258
|
(async () => {
|
|
254
259
|
try {
|
|
@@ -289,13 +294,18 @@ export function StoryPeekPanel({
|
|
|
289
294
|
relationsData,
|
|
290
295
|
});
|
|
291
296
|
setRefreshing(false);
|
|
292
|
-
// projectId
|
|
297
|
+
// projectId 相关补发:完成后二次合并(供父需求选择器/迭代选择器)。
|
|
298
|
+
// 延迟 1.5s 再发——listStoriesFn(take 200 + count)在万级项目下是
|
|
299
|
+
// 点击路径上最重的查询,且选择器极少在面板打开后立刻使用;错峰等
|
|
300
|
+
// 队列空闲,不让它参与点击爆发的拥塞(桌面端单连接排队放大)。
|
|
301
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
302
|
+
if (cancelled) return;
|
|
293
303
|
const [storiesResult, iterationsResult] = await Promise.all([
|
|
294
304
|
story.projectId
|
|
295
|
-
? listStoriesFn({ data: { projectId: story.projectId } })
|
|
305
|
+
? listStoriesFn({ data: { projectId: story.projectId }, signal: abort.signal })
|
|
296
306
|
: Promise.resolve({ items: [] }),
|
|
297
307
|
story.projectId
|
|
298
|
-
? listIterationsFn({ data: { projectId: story.projectId, includeArchived: false } })
|
|
308
|
+
? listIterationsFn({ data: { projectId: story.projectId, includeArchived: false }, signal: abort.signal })
|
|
299
309
|
: Promise.resolve({ items: [] }),
|
|
300
310
|
]);
|
|
301
311
|
if (cancelled) return;
|
|
@@ -320,6 +330,7 @@ export function StoryPeekPanel({
|
|
|
320
330
|
})();
|
|
321
331
|
return () => {
|
|
322
332
|
cancelled = true;
|
|
333
|
+
abort.abort();
|
|
323
334
|
};
|
|
324
335
|
}, [effectiveStoryId]);
|
|
325
336
|
|
|
@@ -384,7 +384,7 @@ export function StoryListView({ stories: initialStories, users: initialUsers, pr
|
|
|
384
384
|
|
|
385
385
|
// 列表实时刷新(§7.1):presence 信号(成员进出本模块实体页)+ 回前台 +
|
|
386
386
|
// 轮询兜底 → 走既有重拉入口(协同落库不 bump updatedAt,列表无推送通道)
|
|
387
|
-
usePresenceListRefresh({ module: "stories", refresh: listRefresh });
|
|
387
|
+
usePresenceListRefresh({ module: "stories", refresh: listRefresh, selfUserId: session?.user?.id });
|
|
388
388
|
|
|
389
389
|
// 托盘 mini 面板快捷记录(跨窗口):立即重拉列表,不等 presence 轮询兜底的
|
|
390
390
|
// 30-60s。事件由 QuickCaptureInvalidator(Providers 全局)在主窗收到 Electron
|
|
@@ -32,6 +32,7 @@ vi.mock("@tanstack/react-start", () => ({
|
|
|
32
32
|
|
|
33
33
|
const { mockNavigate } = vi.hoisted(() => ({ mockNavigate: vi.fn() }));
|
|
34
34
|
vi.mock("@tanstack/react-router", () => ({
|
|
35
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
35
36
|
Link: ({ children }: { children?: React.ReactNode }) => <a>{children}</a>,
|
|
36
37
|
useNavigate: () => mockNavigate,
|
|
37
38
|
}));
|
|
@@ -31,6 +31,7 @@ vi.mock("@tanstack/react-start", () => ({
|
|
|
31
31
|
|
|
32
32
|
const { mockNavigate } = vi.hoisted(() => ({ mockNavigate: vi.fn() }));
|
|
33
33
|
vi.mock("@tanstack/react-router", () => ({
|
|
34
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
34
35
|
Link: ({ children }: { children?: React.ReactNode }) => <a>{children}</a>,
|
|
35
36
|
useNavigate: () => mockNavigate,
|
|
36
37
|
}));
|
|
@@ -30,6 +30,7 @@ vi.mock("@tanstack/react-start", () => ({
|
|
|
30
30
|
// 任务 10 起 list-view 挂 Peek 面板:useNavigate(打开详情)+ Link(关联需求)
|
|
31
31
|
const { mockNavigate } = vi.hoisted(() => ({ mockNavigate: vi.fn() }));
|
|
32
32
|
vi.mock("@tanstack/react-router", () => ({
|
|
33
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
33
34
|
Link: ({ children }: { children?: React.ReactNode }) => <a>{children}</a>,
|
|
34
35
|
useNavigate: () => mockNavigate,
|
|
35
36
|
}));
|
|
@@ -42,6 +42,7 @@ vi.mock("@/server/serverFns/story", () => ({
|
|
|
42
42
|
|
|
43
43
|
const { mockNavigate } = vi.hoisted(() => ({ mockNavigate: vi.fn() }));
|
|
44
44
|
vi.mock("@tanstack/react-router", () => ({
|
|
45
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
45
46
|
useNavigate: () => mockNavigate,
|
|
46
47
|
// 桌面 Link:把 to + params 展开为 href,供断言关联需求链接指向
|
|
47
48
|
Link: ({
|
|
@@ -30,6 +30,7 @@ vi.mock("@tanstack/react-start", () => ({
|
|
|
30
30
|
|
|
31
31
|
const { mockNavigate } = vi.hoisted(() => ({ mockNavigate: vi.fn() }));
|
|
32
32
|
vi.mock("@tanstack/react-router", () => ({
|
|
33
|
+
useRouteContext: () => ({ session: { user: { id: "user_1" } } }),
|
|
33
34
|
Link: ({ children }: { children?: React.ReactNode }) => <a>{children}</a>,
|
|
34
35
|
useNavigate: () => mockNavigate,
|
|
35
36
|
}));
|
|
@@ -77,6 +77,7 @@ import {
|
|
|
77
77
|
type TestCaseViewType,
|
|
78
78
|
} from "./views/view-types";
|
|
79
79
|
import { BUILTIN_INDEPENDENT_DISPLAY_ID } from "@/lib/builtin-project";
|
|
80
|
+
import { useRouteContext } from "@tanstack/react-router";
|
|
80
81
|
import { usePresenceListRefresh } from "@/lib/collab/use-presence-list-refresh";
|
|
81
82
|
import { toastError } from "@/lib/toast-error";
|
|
82
83
|
import { m } from "@/paraglide/messages.js";
|
|
@@ -93,6 +94,7 @@ interface CaseListResult {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
export function TestCaseListView({ projects: initialProjects, initialFolders, initialUsers }: TestCaseListViewProps) {
|
|
97
|
+
const { session } = useRouteContext({ from: "/_nav/test-cases/" });
|
|
96
98
|
// P1 作用域(任务 17 改造):项目选择器落在工具栏 Popover(story-toolbar 同款),
|
|
97
99
|
// scopeProjectId=undefined 表示「全部项目」聚合 scope(后端任务 16 已支持缺省
|
|
98
100
|
// 聚合读路径)。默认仍落内置「独立需求」项目(首屏行为不变);回退口径对齐
|
|
@@ -507,7 +509,7 @@ export function TestCaseListView({ projects: initialProjects, initialFolders, in
|
|
|
507
509
|
void fetchGroups();
|
|
508
510
|
if (view === "board") void fetchBoard();
|
|
509
511
|
}, [fetchCases, fetchGroups, view, fetchBoard]);
|
|
510
|
-
usePresenceListRefresh({ module: "test-cases", refresh: refreshCaseList });
|
|
512
|
+
usePresenceListRefresh({ module: "test-cases", refresh: refreshCaseList, selfUserId: session?.user?.id });
|
|
511
513
|
|
|
512
514
|
const refreshFolders = useCallback(async () => {
|
|
513
515
|
try {
|
|
@@ -112,7 +112,7 @@ export const SDK_GROUPS: SdkGroup[] = [
|
|
|
112
112
|
"items": [
|
|
113
113
|
{
|
|
114
114
|
"name": "@allbluecn/web-app",
|
|
115
|
-
"version": "v0.27.
|
|
115
|
+
"version": "v0.27.12",
|
|
116
116
|
"lastUpdate": "Nov 6, 2026",
|
|
117
117
|
"source": "apps/web/package.json",
|
|
118
118
|
"docsUrl": "https://github.com/allbluecn/allblue"
|
|
@@ -78,6 +78,10 @@ export interface UsePresenceListRefreshArgs {
|
|
|
78
78
|
module: string
|
|
79
79
|
/** 列表重拉回调(列表页既有 refresh 入口,闭包始终取最新) */
|
|
80
80
|
refresh: () => void
|
|
81
|
+
/** 当前用户 id:从签名中剔除——自己进出实体页不改变任何列表数据,
|
|
82
|
+
触发的刷新是纯浪费(桌面端单用户下 teammates 常只有自己,剔除前
|
|
83
|
+
每次开面板都会整列表重拉)。缺省不过滤(兼容未传的调用方) */
|
|
84
|
+
selfUserId?: string | null
|
|
81
85
|
/** 轮询间隔 ms(默认 60s;传 0 关闭轮询) */
|
|
82
86
|
pollIntervalMs?: number
|
|
83
87
|
/** presence 信号防抖窗口 ms(默认 1s;测试可调小) */
|
|
@@ -91,6 +95,7 @@ export interface UsePresenceListRefreshArgs {
|
|
|
91
95
|
export function usePresenceListRefresh({
|
|
92
96
|
module,
|
|
93
97
|
refresh,
|
|
98
|
+
selfUserId,
|
|
94
99
|
pollIntervalMs = PRESENCE_LIST_REFRESH_POLL_MS,
|
|
95
100
|
debounceMs = PRESENCE_LIST_REFRESH_DEBOUNCE_MS,
|
|
96
101
|
}: UsePresenceListRefreshArgs): void {
|
|
@@ -102,7 +107,9 @@ export function usePresenceListRefresh({
|
|
|
102
107
|
presenceStore,
|
|
103
108
|
(state) =>
|
|
104
109
|
entityViewersSignature(
|
|
105
|
-
[...state.teammates.values()].filter(
|
|
110
|
+
[...state.teammates.values()].filter(
|
|
111
|
+
(s) => s.module === module && s.user.id !== selfUserId,
|
|
112
|
+
),
|
|
106
113
|
),
|
|
107
114
|
)
|
|
108
115
|
|
|
@@ -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({
|
|
@@ -264,16 +265,18 @@ export const updateStoryFn = createServerFn({ method: "POST" })
|
|
|
264
265
|
select: STORY_LIST_SELECT,
|
|
265
266
|
});
|
|
266
267
|
if (!existing) throw new Error("需求不存在");
|
|
267
|
-
|
|
268
|
+
// 事务内的成员/负责人校验必须走 tx:PGlite 单连接下事务独占实例,
|
|
269
|
+
// 经外层 client 发查询会与本事务互相等待(死锁至 P2028,云端连接池无此问题)
|
|
270
|
+
await assertProjectMembership(existing.projectId, userId, undefined, tx);
|
|
268
271
|
|
|
269
272
|
// 跨项目移动:目标项目同样须为有效成员(防止借移动向他项目注入数据)
|
|
270
273
|
const newProjectId = data.projectId ?? existing.projectId;
|
|
271
274
|
if (data.projectId !== undefined && newProjectId !== existing.projectId) {
|
|
272
|
-
await assertProjectMembership(newProjectId, userId);
|
|
275
|
+
await assertProjectMembership(newProjectId, userId, undefined, tx);
|
|
273
276
|
}
|
|
274
277
|
|
|
275
278
|
if (data.assigneeId !== undefined) {
|
|
276
|
-
await validateAssignee(existing.projectId, data.assigneeId);
|
|
279
|
+
await validateAssignee(existing.projectId, data.assigneeId, tx);
|
|
277
280
|
}
|
|
278
281
|
|
|
279
282
|
const updates: Prisma.StoryUpdateInput = {};
|
|
@@ -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> {
|