admin page updates
This commit is contained in:
@@ -10,4 +10,5 @@ func (c Key) String() string {
|
||||
var (
|
||||
DevModeKey Key = Key("devmode")
|
||||
PermissionCacheKey Key = Key("permissions")
|
||||
PreviewRoleKey Key = Key("preview-role")
|
||||
)
|
||||
|
||||
25
internal/contexts/preview_role.go
Normal file
25
internal/contexts/preview_role.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package contexts
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/db"
|
||||
)
|
||||
|
||||
// WithPreviewRole adds a preview role to the context
|
||||
func WithPreviewRole(ctx context.Context, role *db.Role) context.Context {
|
||||
return context.WithValue(ctx, PreviewRoleKey, role)
|
||||
}
|
||||
|
||||
// GetPreviewRole retrieves the preview role from the context, or nil if not present
|
||||
func GetPreviewRole(ctx context.Context) *db.Role {
|
||||
if role, ok := ctx.Value(PreviewRoleKey).(*db.Role); ok {
|
||||
return role
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsPreviewMode returns true if the user is currently in preview mode
|
||||
func IsPreviewMode(ctx context.Context) bool {
|
||||
return GetPreviewRole(ctx) != nil
|
||||
}
|
||||
Reference in New Issue
Block a user