Files
crawler-plugin/admin-frontend-vue/src/api/user-secret-usage.ts
T
huangzd1997 1b8b62fd14 test(公司tab): 把两条「筛空」日志分支钉进用例,并订正 company_id 口径
baf8baef 给密钥管理与用量统计接了公司 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

53 lines
2.1 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 AdminUserSecretUsageRow {
userId: number
username: string
groups: string[]
similarAsinCount: number
appearancePatentCount: number
proxyCount: number
totalCount: number
}
export interface AdminUserSecretUsagePage {
items: AdminUserSecretUsageRow[]
total: number
page: number
pageSize: number
/** 所选范围内(不分页)三类总次数。 */
totalCalls: number
similarAsinCalls: number
appearancePatentCalls: number
proxyCalls: number
groupOptions?: Array<{ id: number; groupName: string }>
}
export interface UserSecretUsageQuery {
startDate?: string
endDate?: string
keyword?: string
/** 按数据权限分组筛选(仅超管生效);后端参数为 snake_case。 */
groupId?: number
/** 公司 tab 的当前口径;不传 = 后端按操作者自己的公司(批次 1 里非超管只有这一家)。 */
companyId?: number | null
page: number
pageSize: number
}
/** 分页查询密钥用量:GET /api/admin/user-secret-usage(group_id 必须 snake_case)。 */
export async function fetchUserSecretUsage(params: UserSecretUsageQuery): Promise<AdminUserSecretUsagePage> {
const query: Record<string, string | number> = { page: params.page, pageSize: params.pageSize }
if (params.startDate) query.startDate = params.startDate
if (params.endDate) query.endDate = params.endDate
if (params.keyword) query.keyword = params.keyword
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-secret-usage', { params: query })
return unwrap<AdminUserSecretUsagePage>(data)
}