MCPcopy
hub / github.com/mudler/LocalAI / GetCachedUserPermissions

Function GetCachedUserPermissions

core/http/auth/permissions.go:15–25  ·  view source on GitHub ↗

GetCachedUserPermissions returns the user's permission record, using a request-scoped cache stored in the echo context. This avoids duplicate DB lookups when multiple middlewares (RequireRouteFeature, RequireModelAccess) both need permissions in the same request.

(c echo.Context, db *gorm.DB, userID string)

Source from the content-addressed store, hash-verified

13// DB lookups when multiple middlewares (RequireRouteFeature, RequireModelAccess)
14// both need permissions in the same request.
15func GetCachedUserPermissions(c echo.Context, db *gorm.DB, userID string) (*UserPermission, error) {
16 if perm, ok := c.Get(contextKeyPermissions).(*UserPermission); ok && perm != nil {
17 return perm, nil
18 }
19 perm, err := GetUserPermissions(db, userID)
20 if err != nil {
21 return nil, err
22 }
23 c.Set(contextKeyPermissions, perm)
24 return perm, nil
25}
26
27// Feature name constants — all code must use these, never bare strings.
28const (

Callers 5

RegisterUIAPIRoutesFunction · 0.92
ListModelsEndpointFunction · 0.92
RequireFeatureFunction · 0.85
RequireRouteFeatureFunction · 0.85
RequireModelAccessFunction · 0.85

Calls 3

GetUserPermissionsFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected