Files
ai_academy/internal/application/service/sandboxalloc/owner.go
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

43 lines
1.4 KiB
Go

package sandboxalloc
import (
"strings"
"academy/internal/sandbox/allocation"
"academy/internal/types"
)
// ownerFromSession maps the session's persisted owner onto allocation.Owner.
// Only the authentication source is stored; the kind follows from it, and is
// cross-checked against the owner id's shape so a row whose source disagrees
// with its owner can never look like a verified person.
func ownerFromSession(s *types.Session) allocation.Owner {
src := allocation.AuthSource(strings.TrimSpace(s.OwnerAuthSource))
if src == "" {
src = allocation.SourceUnknown
}
o := allocation.Owner{TenantID: s.TenantID, ID: s.UserID, Kind: allocation.KindUnknown, Source: src}
id := strings.TrimSpace(s.UserID)
switch src {
case allocation.SourceWeb:
if id != "" && !strings.Contains(id, ":") {
o.Kind = allocation.KindWebUser
}
case allocation.SourceAPIDirectHeader, allocation.SourceAPISignedToken:
if strings.HasPrefix(id, types.SessionOwnerAPIExternalUserPrefix) {
o.Kind = allocation.KindAPIExternalUser
}
case allocation.SourceAPITenantKey:
o.Kind = allocation.KindAPITenantKey
case allocation.SourceAPIPlatformKey:
o.Kind = allocation.KindAPIPlatformKey
case allocation.SourceMCPEndpoint:
o.Kind = allocation.KindMCPEndpoint
case allocation.SourceEmbed:
o.Kind = allocation.KindEmbed
case allocation.SourceIM:
o.Kind = allocation.KindIM
}
return o
}