feat(gateway): 优化gateway相关功能
Quality check / Web UI (push) Successful in 9m19s

This commit is contained in:
mei
2026-09-12 15:32:27 +08:00
parent 0d89b7fe8f
commit 9b656cebee
84 changed files with 2769 additions and 825 deletions
+24 -2
View File
@@ -181,7 +181,7 @@ func HandleTestAccount(c *gin.Context) {
// HandleCheckDeleteAccount 检查删除账号请求
//
// 删除账号会同时删除相关规则,先请求该接口获取受影响的规则
// 删除账号会同时删除相关规则(含消息网关规则),先请求该接口获取受影响的规则
func HandleCheckDeleteAccount(c *gin.Context) {
userInfo, err := user.GetUserInfoByGinCtx(c)
if err != nil {
@@ -201,7 +201,16 @@ func HandleCheckDeleteAccount(c *gin.Context) {
return
}
response.OK(c, rules)
gatewayRules, err := getGatewayRulesByAccountID(accountID, userInfo.ID)
if err != nil {
response.ServerError(c, "获取相关网关规则失败")
return
}
response.OK(c, gin.H{
"rules": rules,
"gateway_rules": gatewayRules,
})
}
// HandleDeleteAccount 删除账号及其关联规则
@@ -243,6 +252,19 @@ func HandleDeleteAccount(c *gin.Context) {
}
}
// 删除相关的消息网关规则
gatewayRules, err := getGatewayRulesByAccountID(accountID, userInfo.ID)
if err != nil {
response.ServerError(c, "获取相关网关规则失败")
return
}
for _, oneRule := range gatewayRules {
if err := rule.DeleteGatewayRuleByID(oneRule.ID, userInfo.ID); err != nil {
response.ServerError(c, "删除相关网关规则失败")
return
}
}
// 删除账号
gormDB, err := db.GetGormDB()
if err != nil {
+14
View File
@@ -45,6 +45,20 @@ func getRulesByAccountID(accountID uint, uid uint) ([]*model.Rule, error) {
return rules, nil
}
// getGatewayRulesByAccountID 获取账号相关的消息网关规则列表
func getGatewayRulesByAccountID(accountID uint, uid uint) ([]*model.GatewayRule, error) {
gormDB, err := db.GetGormDB()
if err != nil {
return nil, err
}
rules := []*model.GatewayRule{}
if err := gormDB.Where("account_id = ? AND uid = ?", accountID, uid).Find(&rules).Error; err != nil {
return nil, err
}
return rules, nil
}
// maskAccount 掩码账号配置中的敏感字段,避免 Cookie/密码原样返回给前端
func maskAccount(account model.Account) model.Account {
fields := accountConfigChecker.InitValidatorRegistry().FieldsOf(account.Type)