feat(api-keys): enhance manage_kbs capability for KB lifecycle management

Update the manage_kbs capability to cover the full lifecycle of knowledge bases, including create, copy, duplicate, update, and delete operations. Adjust related API routes and tests to ensure proper access control and policy requirements for knowledge base management.
This commit is contained in:
wizardchen
2026-07-15 10:50:41 +08:00
committed by lyingbug
parent b3bb60f03c
commit 97490ef7ed
3 changed files with 27 additions and 4 deletions
@@ -429,6 +429,25 @@ func TestChunkerPreviewRouteRequiresRetrieveOrIngestCapability(t *testing.T) {
}
}
func TestKBCloneProgressRouteRequiresRetrieveOrManageKbsCapability(t *testing.T) {
gin.SetMode(gin.TestMode)
g := &rbacGuards{}
v1 := gin.New().Group("/api/v1")
RegisterKnowledgeBaseRoutes(v1, &handler.KnowledgeBaseHandler{}, g)
policy := mustLookupAPIKeyPolicy(t, g, http.MethodGet, "/api/v1/knowledge-bases/copy/progress/:task_id")
if !policy.RequireFullAccess {
t.Fatal("policy should require full access without a matching capability")
}
if !policyHasCapability(policy, types.APIKeyCapabilityRetrieve) {
t.Fatalf("policy capabilities = %#v, want retrieve", policy.Capabilities)
}
if !policyHasCapability(policy, types.APIKeyCapabilityManageKnowledgeBases) {
t.Fatalf("policy capabilities = %#v, want manage_kbs", policy.Capabilities)
}
}
func TestFAQImportProgressRouteRequiresRetrieveOrIngestCapability(t *testing.T) {
gin.SetMode(gin.TestMode)
g := &rbacGuards{}