chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,93 @@
|
||||
package im
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"academy/internal/application/access"
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
secutils "academy/internal/utils"
|
||||
)
|
||||
|
||||
// authorizeOutboundResource checks actual file ownership and live KB sharing.
|
||||
// An answer can echo a user-supplied handle; appearing in that answer never
|
||||
// grants access to another workspace's storage credentials.
|
||||
func (s *Service) authorizeOutboundResource(
|
||||
ctx context.Context,
|
||||
tenant *types.Tenant,
|
||||
agent *types.CustomAgent,
|
||||
kbIDs []string,
|
||||
reference string,
|
||||
) error {
|
||||
if tenant == nil || tenant.ID == 0 || s.resourceCatalog == nil {
|
||||
return access.ErrUnauthorized
|
||||
}
|
||||
caller := types.CallerFromContext(ctx)
|
||||
if caller.TenantID != tenant.ID {
|
||||
return access.ErrUnauthorized
|
||||
}
|
||||
physical, resource, err := s.resourceCatalog.ResolvePath(ctx, reference)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
owner := secutils.ParseTenantIDFromStoragePath(physical)
|
||||
if resource != nil {
|
||||
owner = resource.TenantID
|
||||
}
|
||||
if owner == 0 {
|
||||
return access.ErrForbidden
|
||||
}
|
||||
if owner == tenant.ID {
|
||||
return secutils.ValidateStoragePathTenant(physical, owner)
|
||||
}
|
||||
bindings, ok := s.resourceCatalog.(interface {
|
||||
interfaces.KBResourceLookup
|
||||
interfaces.MessageFileBindingLookup
|
||||
})
|
||||
if !ok || s.kbService == nil || s.kbShareService == nil {
|
||||
return access.ErrForbidden
|
||||
}
|
||||
origins, err := bindings.GetMessageFileBindings(ctx, owner, reference, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if origins == nil {
|
||||
return access.ErrForbidden
|
||||
}
|
||||
for _, kbID := range origins.KnowledgeBaseIDs {
|
||||
if !outboundKBInScope(agent, kbIDs, kbID) {
|
||||
continue
|
||||
}
|
||||
kb, err := s.kbService.GetKnowledgeBaseByIDOnly(ctx, kbID)
|
||||
if err != nil || kb == nil || kb.TenantID != owner {
|
||||
continue
|
||||
}
|
||||
grant, err := access.ResolveKB(ctx, access.KBRequest{Caller: caller}, kb,
|
||||
types.OrgRoleViewer, s.kbShareService, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := access.ResolveKBFile(ctx, grant, kbID, reference, s.resourceCatalog, bindings); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return access.ErrForbidden
|
||||
}
|
||||
|
||||
func outboundKBInScope(agent *types.CustomAgent, kbIDs []string, kbID string) bool {
|
||||
if len(kbIDs) != 0 {
|
||||
return slices.Contains(kbIDs, kbID)
|
||||
}
|
||||
if agent == nil {
|
||||
return true
|
||||
}
|
||||
switch agent.Config.KBSelectionMode {
|
||||
case "all":
|
||||
return true
|
||||
case "none":
|
||||
return false
|
||||
default:
|
||||
return slices.Contains(agent.Config.KnowledgeBases, kbID)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user