feat(cli): add approval order workflow#428
Conversation
AkashiSensei
left a comment
There was a problem hiding this comment.
可以先不着急改,还有个比较费劲的问题,目前 --admin 作为管理员操作不合理,我先统一约定下这个问题吧,管理员命令使用统一的 admin 前缀,然后管理员和用户 skill 分离。
| return nil | ||
| } | ||
|
|
||
| func runOrderReject(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
order reject 会调用普通 PUT /api/v1/approvalorder/{id} 更新工单为 Rejected。但后端当前只拦截非管理员设置 Approved,没有拦截 Rejected / Canceled / 修改内容,也没有校验工单创建者。这样普通用户只要知道 order id,就可能通过 CLI 拒绝或改写他人的工单。建议先在后端补齐权限校验,或在 CLI 合并前不要暴露审核类写操作。
There was a problem hiding this comment.
@AkashiSensei 已补后端权限边界,并同步调整 CLI。普通 PUT /api/v1/approvalorder/{id} 现在只允许创建者更新自己的 Pending 工单,且不允许通过该接口变更为审核状态;管理员审核拆到新的 PUT /api/v1/admin/approvalorder/{id}/review,只允许管理员调用。CLI 侧也不再把审核动作暴露在普通 crater order ... 下,改为 crater admin order approve/reject/check。对应代码:backend/internal/handler/approvalorder.go、cli/cmd/order.go、cli/internal/api/approvalorder.go。验证:go test ./...(cli)、go test ./internal/handler/operations ./internal/bizerr ./internal/resputil(backend)、go build ./cmd/crater/main.go(backend)。
| lockEnabled, _ := cmd.Flags().GetBool("lock") | ||
| permanent, _ := cmd.Flags().GetBool("permanent") | ||
| days, _ := cmd.Flags().GetInt("days") | ||
| lockHours, _ := cmd.Flags().GetInt("hours") |
There was a problem hiding this comment.
--hours 在 flag 注册处是 Uint,但这里用 GetInt("hours") 读取。pflag 会返回类型不匹配错误;当前代码忽略错误后 lockHours 变成 0,因此 crater order approve ... --lock --hours 6 会被误判为没有锁定时长。建议改成 GetUint 后显式转换,或拆出独立的 --lock-hours。
There was a problem hiding this comment.
@AkashiSensei 已修复。CLI 的 order edit 现在会先读取工单详情并保留未显式传入的字段;管理员审核命令改走 review-only API,只发送 status/reviewNotes。后端从 token 填充 reviewerID,并且新审核 API 不覆盖原 content。对应代码:cli/cmd/order.go、cli/internal/api/approvalorder.go、backend/internal/handler/approvalorder.go。覆盖测试:新增 cli/test/snapshots/order/order_test.go,并更新 cli/test/snapshots/read/read_matrix_test.go 覆盖完整 order/admin order 命令。
| return api.ApprovalOrderRequest{}, errUsageFromIssues(issues) | ||
| } | ||
|
|
||
| return api.ApprovalOrderRequest{ |
There was a problem hiding this comment.
审核命令会完整构造 update payload;reviewerID 默认 0,reason / type-id / hours 不传也会以空值或 0 发送。后端会按这个 payload 覆盖工单字段,因此批准/拒绝时可能清空原申请原因、延期小时数,并把审核人写成 0。建议审核前先读取工单详情,默认保留原 content,并从 active auth info 自动填 reviewerID,或强制要求所有会被覆盖的字段。
| } | ||
| lockEnabled, _ := cmd.Flags().GetBool("lock") | ||
| permanent, _ := cmd.Flags().GetBool("permanent") | ||
| days, _ := cmd.Flags().GetInt("days") |
There was a problem hiding this comment.
--days / --minutes 是 Int,当前校验只判断三段时长是否全为 0。--lock --days -1 这类输入会通过本地校验,后端会直接把负 duration 加到锁定时间上。建议本地拒绝任意负值,后端也补一层保护。
There was a problem hiding this comment.
@AkashiSensei 已在 CLI 和后端都补了保护。CLI 会拒绝 --lock --days -1 / --minutes -1 等负数输入,也会在非永久锁定时要求正 duration;后端 AddLockTime 同样拒绝任意负数 duration,并要求非永久锁定必须提供正 duration。对应代码:cli/cmd/order.go、backend/internal/handler/operations/lock.go。覆盖测试:cli/test/snapshots/order/order_test.go 中包含 admin order approve --lock 缺少 duration 和负数 duration 两类场景。
60d66d2 to
41afd94
Compare
|
@AkashiSensei 已按本轮 review 完成调整并推送到 PR 分支(最新提交 主要修改:
验证:
|
|
@AkashiSensei 又补了一轮后端 order lifecycle 修复,并修掉了之前 这轮主要处理:
验证:
|
Summary / 摘要
English
This PR adds a complete approval-order workflow to the Crater CLI on a separate branch. It covers user submission/cancellation and admin review actions, including optional job locking before approval.
中文
本 PR 在独立分支中为 Crater CLI 增加完整审批工单流程,覆盖用户提交/取消工单,以及管理员审核工单;其中作业类工单支持在批准前先锁定作业。
Added Commands / 新增命令
User workflow / 用户流程
crater order submitcrater order edit <id>crater order lscrater order get <id>crater order by-name <name>crater order cancel <id> --yesAdmin workflow / 管理员流程
crater order ls --admincrater order get <id> --admincrater order approve <id>crater order approve <id> --lock ...crater order reject <id> --review-notes <reason>crater order check --yesImplementation Details / 实现说明
English
cli/internal/api.crater ordercommand implementation undercli/cmd.--json --no-interactivesupport for all commands.crater-cli-approval-orderSkill for AI-agent usage.cli/docs/COMMANDS.mdwith the approval-order command contract.中文
cli/internal/api中新增审批工单 API client。cli/cmd中新增crater order命令实现。--json --no-interactive。crater-cli-approval-orderSkill,方便 AI Agent 正确执行审批工作流。cli/docs/COMMANDS.md中的审批工单命令契约。Test Coverage / 测试覆盖
Added tests / 新增测试
cli/test/snapshots/order/order_test.go.cli/testdata/snapshots/order/order.en.txtarcli/testdata/snapshots/order/order.zh-CN.txtarSnapshot cases cover / 快照覆盖场景
--lockbut no lock duration.--yesin non-interactive mode.Verification / 验证
UPDATE_SNAPSHOTS=1 go test ./test/snapshots/ordergo test ./...go build ./...Notes / 备注
English
This PR intentionally implements the write workflow for approval orders only. It does not include the broader read-resource CLI from the other branch.
中文
本 PR 只实现审批工单写流程,不包含另一个分支中的通用资源读取 CLI。