rbac system first stage
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
// Package contexts provides utilities for loading and extracting structs from contexts
|
||||
package contexts
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/permissions"
|
||||
"git.haelnorr.com/h/oslstats/internal/roles"
|
||||
)
|
||||
|
||||
type Key string
|
||||
|
||||
@@ -8,7 +14,10 @@ func (c Key) String() string {
|
||||
return "oslstats context key " + string(c)
|
||||
}
|
||||
|
||||
var DevModeKey Key = Key("devmode")
|
||||
var (
|
||||
DevModeKey Key = Key("devmode")
|
||||
PermissionCacheKey Key = Key("permissions")
|
||||
)
|
||||
|
||||
func DevMode(ctx context.Context) DevInfo {
|
||||
devmode, ok := ctx.Value(DevModeKey).(DevInfo)
|
||||
@@ -22,3 +31,18 @@ type DevInfo struct {
|
||||
WebsocketBase string
|
||||
HTMXLog bool
|
||||
}
|
||||
|
||||
// Permissions retrieves the permission cache from context (type-safe)
|
||||
func Permissions(ctx context.Context) *PermissionCache {
|
||||
cache, ok := ctx.Value(PermissionCacheKey).(*PermissionCache)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return cache
|
||||
}
|
||||
|
||||
type PermissionCache struct {
|
||||
Permissions map[permissions.Permission]bool
|
||||
Roles map[roles.Role]bool
|
||||
HasWildcard bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user