refactor(api-keys): use role field and route-level API key guards
Replace scopes JSON with a viewer/contributor/admin role column, move unsafe-method authorization from path-prefix middleware to declarative APIKey* guards on routes, and close remaining KB-scope gaps in handlers.
This commit is contained in:
@@ -462,6 +462,13 @@ func (s *customAgentService) GetSuggestedQuestions(
|
||||
limit = 6
|
||||
}
|
||||
|
||||
if err := types.AuthorizeTenantAPIKeyKnowledgeTargets(ctx, kbIDs, knowledgeIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := types.AuthorizeTenantAPIKeyOptionalTagIDs(ctx, tagIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get tenant ID from context
|
||||
tenantID, ok := types.TenantIDFromContext(ctx)
|
||||
if !ok {
|
||||
@@ -541,6 +548,12 @@ func (s *customAgentService) GetSuggestedQuestions(
|
||||
}
|
||||
}
|
||||
|
||||
filteredKBIDs, err := types.FilterKnowledgeBasesForTenantAPIKeyScope(ctx, kbIDs, effectiveKBIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
effectiveKBIDs = filteredKBIDs
|
||||
|
||||
if len(effectiveKBIDs) == 0 && len(knowledgeIDs) == 0 {
|
||||
return s.truncateQuestions(result, limit), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user