This commit is contained in:
@@ -3,7 +3,6 @@ package asset_audit
|
||||
import (
|
||||
"context"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -100,6 +99,7 @@ func BuildLog(ctx context.Context, p BuildLogParams) *model.AssetOperationLog {
|
||||
func OperatorFromContext(ctx context.Context) OperatorInfo {
|
||||
uid := middleware.GetUserIDFromContext(ctx)
|
||||
ut := middleware.GetUserTypeFromContext(ctx)
|
||||
username := strings.TrimSpace(middleware.GetUsernameFromContext(ctx))
|
||||
|
||||
if uid == 0 {
|
||||
return SystemOperator("系统任务")
|
||||
@@ -109,19 +109,19 @@ func OperatorFromContext(ctx context.Context) OperatorInfo {
|
||||
switch ut {
|
||||
case constants.UserTypeSuperAdmin, constants.UserTypePlatform:
|
||||
op.Type = constants.AssetAuditOperatorTypeAdmin
|
||||
op.Name = fmt.Sprintf("后台用户#%d", uid)
|
||||
op.Name = fallbackOperatorName(username, "平台用户")
|
||||
case constants.UserTypeAgent:
|
||||
op.Type = constants.AssetAuditOperatorTypeAgent
|
||||
op.Name = fmt.Sprintf("代理用户#%d", uid)
|
||||
op.Name = fallbackOperatorName(username, "代理账号")
|
||||
case constants.UserTypeEnterprise:
|
||||
op.Type = constants.AssetAuditOperatorTypeEnterprise
|
||||
op.Name = fmt.Sprintf("企业用户#%d", uid)
|
||||
op.Name = fallbackOperatorName(username, "企业账号")
|
||||
case constants.UserTypePersonalCustomer:
|
||||
op.Type = constants.AssetAuditOperatorTypePersonal
|
||||
op.Name = fmt.Sprintf("个人客户#%d", uid)
|
||||
op.Name = fallbackOperatorName(username, "个人客户")
|
||||
default:
|
||||
op.Type = constants.AssetAuditOperatorTypeAdmin
|
||||
op.Name = fmt.Sprintf("用户#%d", uid)
|
||||
op.Name = fallbackOperatorName(username, "平台用户")
|
||||
}
|
||||
return op
|
||||
}
|
||||
@@ -267,3 +267,10 @@ func strPtr(v string) *string {
|
||||
func uintPtr(v uint) *uint {
|
||||
return &v
|
||||
}
|
||||
|
||||
func fallbackOperatorName(name string, fallback string) string {
|
||||
if strings.TrimSpace(name) != "" {
|
||||
return name
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user