Files
crawler-plugin/admin-frontend-vue/src/api/user-secrets.ts
T
huangzd1997 0f3fd3e0ec test(公司tab): 把两条「筛空」日志分支钉进用例,并订正 company_id 口径
d2977a30 给密钥管理与用量统计接了公司 tab,但"筛空早退"那两支日志一直没人看守:
主管的文案写的是「主管名下无子账户」,可这条分支真正的成因几乎只可能是 company_id
越界(主管的 base 恒含本人,UserDataScopeSupport:55/:78)——排障时会把人往错的方向指。
现在两支分别带 companyScope 宽度,并各钉一条 ListAppender 用例互不放过:
超管只许吐「公司或分组筛后」,主管只许吐「交集为空(多为越界 company_id)」。
分母 UserApiSecretServiceTest 50 例、UserSecretUsageServiceTest 12 例,Failures/Errors 均 0。

同批订正三处会漂的口径:两个 api 模块的注释原写「company_id=0 会让后端 requireCompanyId
直接抛」,实际 DataReadScope.readScope 第一行把 <=0 归一成「没选公司」,0 与缺失等价;
company-tab-wiring 的取值口注释去掉行号(api 文件一改就漂);两支接口的 OpenAPI 描述
补上「company_id 只收窄不放大、跨公司查看仅超管」。
docs/plans/19-company-tab.md 记一条评审未修项(Task 9 I-1):同一页里
POST /user-secrets/{userId}/check 与 DELETE /{userId} 一期就没有归属闸门,本轮把读接进
公司 tab 后它成了唯一还开着的越权写点,补校验是会 403 的行为变更 ⇒ 单独一张工单。
2026-10-05 13:52:33 +08:00

116 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { http } from './http'
import { unwrap } from './envelope'
/** 单模块状态(脱敏值 + 连通性)。 */
export interface AdminUserSecretModule {
moduleKey: string
moduleLabel: string
masked: string
/** 完整明文值:仅代理列有值(后端对密钥列不下发明文)。 */
full: string
exists: boolean
/** 是否由后台代填并锁定:锁定时客户端不可修改或清空。 */
locked: boolean
checkStatus: string
checkCode: string
checkMessage: string
checkLatencyMs: number | null
checkedAt: string | null
updatedAt: string | null
}
/** 一行一用户:三个字段列 + 行级状态(三类都检测通过才算 passed)。 */
export interface AdminUserSecretRow {
userId: number
username: string
/** 所属数据权限分组名(可能多个)。 */
groups: string[]
/** 所属主管(创建人)用户名;无分组时的兜底展示。 */
leaderUsername: string
similarAsin: AdminUserSecretModule
appearancePatent: AdminUserSecretModule
proxy: AdminUserSecretModule
status: string
statusMessage: string
/** 首次配置时间(三模块中最早);从未配置为 null。 */
createdAt: string | null
updatedAt: string | null
}
export interface AdminUserSecretPage {
items: AdminUserSecretRow[]
total: number
page: number
pageSize: number
/** 分组筛选项(超管=全部;主管=自己带的分组)。 */
groupOptions?: GroupOption[]
}
export interface GroupOption {
id: number
groupName: string
}
export interface UserSecretQuery {
keyword?: string
checkStatus?: string
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
groupId?: number
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
companyId?: number | null
page: number
pageSize: number
}
/** 分页查询用户密钥(一行一用户):GET /api/admin/user-secrets(筛选参数必须 snake_case,camel 会被后端静默忽略)。 */
export async function fetchUserSecretList(params: UserSecretQuery): Promise<AdminUserSecretPage> {
const query: Record<string, string | number> = { page: params.page, pageSize: params.pageSize }
if (params.keyword) query.keyword = params.keyword
if (params.checkStatus) query.checkStatus = params.checkStatus
if (params.groupId) query.group_id = params.groupId
// 用 `!= null` 而不是上面几行的 truthy 写法:这一项类型是 `number | null`(null = 没选公司)。
// 后端把 company_id<=0 归一成「没选公司」(DataReadScope.readScope 第一行),0 与缺失等价,按类型判即可。
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get('/api/admin/user-secrets', { params: query })
return unwrap<AdminUserSecretPage>(data)
}
/** 立即检测该用户全部已配置项:POST /api/admin/user-secrets/{userId}/check
* 逐模块检测(每项最多「首查 + 传输层失败重试一次」,最坏约 31s/项),故放宽超时到 180s。 */
export async function checkUserSecret(userId: number) {
const { data } = await http.post(`/api/admin/user-secrets/${userId}/check`, undefined, { timeout: 180_000 })
return unwrap<
Array<{
moduleKey: string
checkStatus: string
checkCode: string
checkMessage: string
checkLatencyMs: number | null
checkedAt: string | null
viaProxy: boolean
}>
>(data)
}
/** 清空该用户全部密钥与代理配置:DELETE /api/admin/user-secrets/{userId} */
export async function deleteUserSecret(userId: number): Promise<void> {
const { data } = await http.delete(`/api/admin/user-secrets/${userId}`)
unwrap<unknown>(data)
}
/** 代填并锁定该用户某模块配置(当前仅代理):PUT /api/admin/user-secrets/{userId}/modules/{moduleKey} */
export async function saveUserSecretModule(
userId: number,
moduleKey: string,
value: string,
): Promise<AdminUserSecretModule> {
const { data } = await http.put(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`, { value })
return unwrap<AdminUserSecretModule>(data)
}
/** 清空该用户某模块配置并解除锁定:DELETE /api/admin/user-secrets/{userId}/modules/{moduleKey} */
export async function clearUserSecretModule(userId: number, moduleKey: string): Promise<void> {
const { data } = await http.delete(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`)
unwrap<unknown>(data)
}