feat: 移除 Client 真实采购手工授权 (#114)

This commit is contained in:
chengma
2026-08-10 18:37:35 +08:00
parent 8188153b08
commit 10bb892e6c
29 changed files with 124 additions and 702 deletions
+4 -4
View File
@@ -325,7 +325,7 @@ func TestClientAssignment_一人多客户端并按采购员隔离列表(t *testi
}
}
func TestListPurchaseClientOptions_返回可见客户端且离线Live仍可选(t *testing.T) {
func TestListPurchaseClientOptions_全部可见客户端均可选(t *testing.T) {
db := newTestDB(t)
admin, buyerA, _ := prepareClientAssignmentUsers(t, db)
now := time.Now().UTC()
@@ -350,11 +350,11 @@ func TestListPurchaseClientOptions_返回可见客户端且离线Live仍可选(t
if err != nil {
t.Fatalf("读取采购客户端候选失败: %v", err)
}
if len(options.Rows) != 3 || options.SelectableCount != 2 {
t.Fatalf("应显示全部可见客户端且两个 live 可选,实际 %+v", options)
if len(options.Rows) != 3 || options.SelectableCount != 3 {
t.Fatalf("应显示全部可见客户端且全部可选,实际 %+v", options)
}
if options.Rows[2].ClientID != "live-offline" || options.Rows[2].Status != "离线" {
t.Fatalf("离线 live 客户端必须保留在候选中,实际 %+v", options.Rows)
t.Fatalf("离线客户端必须保留在候选中,实际 %+v", options.Rows)
}
}
-7
View File
@@ -219,13 +219,6 @@ func CreatePurchaseTasksWithOptions(db *sql.DB, actor *model.User, requests []Pu
}
confirmedBy, confirmedAt := "", ""
if executionMode == model.TaskExecutionLive {
purchaseMode, err := repository.ClientPurchaseMode(tx, clientID)
if err != nil {
return result, err
}
if purchaseMode != string(model.TaskExecutionLive) {
return result, fmt.Errorf("所选客户端未声明 live 能力,不能执行真实采购任务")
}
confirmedBy, confirmedAt = actor.UserID, model.NowISO()
}
+5 -4
View File
@@ -403,7 +403,7 @@ func TestCreatePurchaseTasksWithOptions_正常采购员可创建真实任务(t *
}
}
func TestCreatePurchaseTasksWithOptions_真实模式保留账号和Client能力门禁(t *testing.T) {
func TestCreatePurchaseTasksWithOptions_真实模式不要求Client预先声明Live(t *testing.T) {
db := newTestDB(t)
key := seedPurchasableWorkflow(t, db, "SYB-GATE")
SaveSybMapping(db, "SYB-GATE", key, "USR-1")
@@ -411,10 +411,11 @@ func TestCreatePurchaseTasksWithOptions_真实模式保留账号和Client能力
RegisterClient(db, model.Client{ClientID: "CLIENT-DRY", Capabilities: `{"purchase_mode":"dry_run"}`}, true)
request := []PurchaseTaskRequest{{SybID: "SYB-GATE", MaxPriceCent: 4200}}
if _, err := CreatePurchaseTasksWithOptions(db, admin, request, PurchaseTaskOptions{
result, err := CreatePurchaseTasksWithOptions(db, admin, request, PurchaseTaskOptions{
ClientID: "CLIENT-DRY", ExecutionMode: model.TaskExecutionLive,
}); err == nil || !strings.Contains(err.Error(), "未声明 live") {
t.Fatalf("dry_run 客户端必须被拒绝: %v", err)
})
if err != nil || result.Created != 1 {
t.Fatalf("当前账号可见客户端不应被历史能力状态阻止: result=%+v err=%v", result, err)
}
disabled := *admin
disabled.Status = model.UserDisabled
+1 -5
View File
@@ -220,11 +220,7 @@ func ListPurchaseClientOptions(db *sql.DB, actor *model.User, threshold time.Dur
return nil, err
}
result := &PurchaseClientOptions{Rows: clients}
for _, client := range clients {
if client.PurchaseMode == string(model.TaskExecutionLive) {
result.SelectableCount++
}
}
result.SelectableCount = len(clients)
return result, nil
}