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,45 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// RequireKBWrite consumes an explicit operation grant. Tenant ownership and
|
||||
// role checks belong to the entry point that resolved the grant; an execution
|
||||
// tenant alone, or a shared-agent/read grant, never authorizes a mutation.
|
||||
func RequireKBWrite(ctx context.Context, kb *types.KnowledgeBase) error {
|
||||
if kb == nil || kb.ID == "" || kb.TenantID == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
if scope, ok := types.TenantAPIKeyScopeFromContext(ctx); ok && !scope.FullAccess &&
|
||||
!scope.HasCapability(types.APIKeyCapabilityIngest) {
|
||||
return ErrForbidden
|
||||
}
|
||||
if !HasKBGrant(ctx, kb.ID, kb.TenantID, types.OrgRoleEditor) {
|
||||
return ErrForbidden
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithKBTaskWrite is for trusted workers continuing an admitted operation.
|
||||
// The worker supplies a server-loaded KB and verifies its child-resource
|
||||
// bindings before any side effects. It grants only this KB, preserves the
|
||||
// original caller (including an absent caller), and never creates an Admin.
|
||||
// This is a task execution grant, not a way to authorize an incoming request.
|
||||
func WithKBTaskWrite(ctx context.Context, kb *types.KnowledgeBase, expectedTenant uint64) (context.Context, error) {
|
||||
if kb == nil || kb.ID == "" || expectedTenant == 0 || kb.TenantID != expectedTenant {
|
||||
return ctx, ErrForbidden
|
||||
}
|
||||
ctx = types.WithExecutionTenant(ctx, expectedTenant)
|
||||
grant := kbGrant{
|
||||
caller: types.CallerFromContext(ctx),
|
||||
kbID: kb.ID,
|
||||
tenantID: expectedTenant,
|
||||
permission: types.OrgRoleEditor,
|
||||
task: true,
|
||||
}
|
||||
// A worker gets exactly one scope, without inheriting another task's KBs.
|
||||
return context.WithValue(ctx, types.KBGrantsContextKey, []kbGrant{grant}), nil
|
||||
}
|
||||
Reference in new issue
Block a user