fix(token): 状态筛选按正交维度派生过期/耗尽,修复「已过期」筛不全 - #6670
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (7)
WalkthroughThe change adds API key status filtering across the backend and frontend. Expired and exhausted states are derived from expiration and quota data. Token validation uses these values directly, and table filtering sends status criteria to the server. ChangesAPI key status semantics
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant ApiKeysTable
participant searchApiKeys
participant SearchTokens
participant SearchUserTokens
User->>ApiKeysTable: Select status filter
ApiKeysTable->>searchApiKeys: Send status query and cache key
searchApiKeys->>SearchTokens: Request filtered tokens
SearchTokens->>SearchUserTokens: Pass status filter
SearchUserTokens-->>ApiKeysTable: Return matching API keys
ApiKeysTable-->>User: Render derived status badges
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/features/keys/components/api-keys-table.tsx`:
- Around line 70-101: Update the local helpers isDisabledApiKeyRow and
renderApiKeyStatusBadge with explicit return annotations: boolean for
isDisabledApiKeyRow and a nullable React node type for renderApiKeyStatusBadge,
preserving their existing return behavior.
In `@web/src/features/keys/lib/utils.ts`:
- Around line 28-30: Update isApiKeyExpired so only expired_time === -1 is
treated as non-expiring, and compare the expiry value against the current Unix
timestamp in seconds rather than milliseconds. Preserve the boolean return
contract while matching the backend predicate exactly.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b9e4a0f1-1f46-4ee6-b5b9-5c00dc19f840
📒 Files selected for processing (8)
controller/token.gomodel/token.goweb/src/features/keys/api.tsweb/src/features/keys/components/api-keys-columns.tsxweb/src/features/keys/components/api-keys-table.tsxweb/src/features/keys/lib/index.tsweb/src/features/keys/lib/utils.tsweb/src/features/keys/types.ts
令牌的启用/禁用与过期/耗尽是两个正交维度,原实现把 3/4 当作与 1/2 互斥的枚举存进同一字段,叠加 Redis 开关导致行为不一致: - ValidateUserToken 仅在 !RedisEnabled 时把 status 覆写为 3/4,Redis 启用时过期令牌 DB 永远 status=1;且只有被调用过的令牌才触发判断, 从未被调用的过期令牌永远保持 status=1。按 status=3 筛选几乎查不到。 - 前端 status 筛选不传后端、未设 manualFiltering,退化为对当前页的 客户端过滤,跨页过期令牌必然漏掉。 - Status 列徽章直接用 status,启用但过期的令牌显示绿色 Enabled。 对齐 redemption-codes 的实现,按正交维度拆分: 后端: - SearchUserTokens 增加 status 参数,expired=expired_time<now(任意 status)、exhausted=!unlimited && remain_quota<=0(任意 status)、 enabled/disabled 按 status 精确匹配(含对应派生态)。 - ValidateUserToken 不再把 status 覆写为 3/4,过期/耗尽态从 expired_time/remain_quota 派生判断,消除 Redis 开关不一致。 - UpdateToken 启用校验从 expired_time/remain_quota 派生,不依赖 cleanToken.Status==3/4。 - 删除无调用者的 SelectUpdate(原仅 ValidateUserToken 调用,仍 Select status 有误用风险)。 前端: - 新增 isApiKeyExpired/isApiKeyExhausted(参考 isRedemptionExpired), Status 列 cell 与 filterFn 用派生态判断,过期/耗尽优先于用户意图展示。 - api-keys-table 提取 statusFilterValue 纳入 shouldSearch/queryKey, searchApiKeys 传 status,useDataTable 加 manualFiltering。 - isDisabledApiKeyRow 与移动端徽章纳入过期/耗尽派生态。 Closes QuantumNous#6661
a01fa93 to
d914abe
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
令牌的「启用/禁用」与「过期/耗尽」是两个正交维度,原实现把派生维度 3/4 当作与 1/2 互斥的枚举存进同一
status字段,叠加 Redis 开关导致行为不一致。本 PR 采用 issue #6661 的「方式二」:保留
enable/disable是用户意图的互斥维度,expired/exhausted从expired_time/remain_quota读时派生,可叠加到任意意图上。数据层本就正交,过期是时间派生属性,同仓库 redemption-codes 已是此模式,且无需后台同步基础设施——读时算一次永远正确,status 只保留启停意图,3/4 成为历史遗留值。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit