数据引擎-快手平台数据抽取bug修复
This commit is contained in:
@@ -6,11 +6,26 @@ import (
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// GetCurrentUser 从 context 中获取当前登录用户
|
||||
// 如果未找到用户信息,返回默认 "unknown" 用户名
|
||||
// GetCurrentUser 从 context 中获取当前登录用户名
|
||||
func GetCurrentUser(ctx context.Context) string {
|
||||
if user, ok := ctx.Value("user").(*beans.User); ok && user != nil && user.UserName != "" {
|
||||
return user.UserName
|
||||
if u := getUser(ctx); u != nil {
|
||||
return u.UserName
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// GetCurrentTenantId 从 context 中获取当前租户 ID
|
||||
func GetCurrentTenantId(ctx context.Context) uint64 {
|
||||
if u := getUser(ctx); u != nil {
|
||||
return u.TenantId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// getUser 从 context 中获取 *beans.User
|
||||
func getUser(ctx context.Context) *beans.User {
|
||||
if user, ok := ctx.Value("user").(*beans.User); ok {
|
||||
return user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user