This commit is contained in:
+24
-2
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user