fix(router): allow scoped API keys to poll FAQ import progress
Register the FAQ import progress route through apiKeyRoute with retrieve or ingest capability so scoped keys that start imports can poll task status without hitting APIKeyGate fail-closed 403.
This commit is contained in:
@@ -387,11 +387,14 @@ func RegisterFAQRoutes(r *gin.RouterGroup, handler *handler.FAQHandler, g *rbacG
|
||||
// FAQ import result display status
|
||||
faq.PUT("/import/last-result/display", g.OwnedKBOrAdmin(), g.KBAccessWrite("id"), handler.UpdateLastImportResultDisplayStatus)
|
||||
}
|
||||
// FAQ import progress route (outside of knowledge-base scope) — Viewer+
|
||||
faqImport := r.Group("/faq/import")
|
||||
{
|
||||
faqImport.GET("/progress/:task_id", g.Viewer(), handler.GetImportProgress)
|
||||
}
|
||||
// FAQ import progress route (outside of knowledge-base scope) — Viewer+.
|
||||
// Scoped API keys that can ingest (they start the import) or retrieve may
|
||||
// poll their own import/dry-run progress. The task is tenant-scoped by
|
||||
// requireTaskProgressTenant, so a key only ever sees its own tenant's
|
||||
// tasks. Declared through apiKeyRoute so the APIKeyGate doesn't fail-closed
|
||||
// and 403 the poller with "scope does not allow this operation".
|
||||
g.apiKeyRoute(r, http.MethodGet, "/faq/import/progress/:task_id",
|
||||
apiKeyRetrieve(apiKeyIngest(apiKeyFullAccess())), g.Viewer(), handler.GetImportProgress)
|
||||
}
|
||||
|
||||
// RegisterKnowledgeBaseRoutes 注册知识库相关的路由
|
||||
|
||||
@@ -401,6 +401,25 @@ func TestChunkerPreviewRouteRequiresRetrieveOrIngestCapability(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFAQImportProgressRouteRequiresRetrieveOrIngestCapability(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
g := &rbacGuards{}
|
||||
v1 := gin.New().Group("/api/v1")
|
||||
|
||||
RegisterFAQRoutes(v1, &handler.FAQHandler{}, g)
|
||||
|
||||
policy := mustLookupAPIKeyPolicy(t, g, http.MethodGet, "/api/v1/faq/import/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.APIKeyCapabilityIngest) {
|
||||
t.Fatalf("policy capabilities = %#v, want ingest", policy.Capabilities)
|
||||
}
|
||||
}
|
||||
|
||||
func mustLookupAPIKeyPolicy(
|
||||
t *testing.T,
|
||||
g *rbacGuards,
|
||||
|
||||
Reference in New Issue
Block a user