feat(config): add box owner policy settings
Adds configuration options and environment variables to manage box owner policies, including settings for refresh counts and expiry.
This commit is contained in:
61
lib/server/account_nav.go
Normal file
61
lib/server/account_nav.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"warpbox/lib/metastore"
|
||||
)
|
||||
|
||||
type AccountNavView struct {
|
||||
Username string
|
||||
IsAdmin bool
|
||||
ActiveSection string
|
||||
AlertCount int
|
||||
AlertSeverity string
|
||||
CanViewBoxes bool
|
||||
CanViewAlerts bool
|
||||
CanViewUsers bool
|
||||
CanViewAPIKeys bool
|
||||
CanViewSettings bool
|
||||
}
|
||||
|
||||
func (app *App) accountNavView(ctx *gin.Context, activeSection string) AccountNavView {
|
||||
perms := currentAccountPermissions(ctx)
|
||||
isAdmin := perms.AdminAccess
|
||||
|
||||
return AccountNavView{
|
||||
Username: app.currentAdminUsername(ctx),
|
||||
IsAdmin: isAdmin,
|
||||
ActiveSection: activeSection,
|
||||
AlertSeverity: "ok",
|
||||
CanViewBoxes: true,
|
||||
CanViewAlerts: true,
|
||||
CanViewUsers: perms.AdminUsersManage,
|
||||
CanViewAPIKeys: true,
|
||||
CanViewSettings: perms.AdminSettingsManage,
|
||||
}
|
||||
}
|
||||
|
||||
func currentAccountPermissions(ctx *gin.Context) metastore.EffectivePermissions {
|
||||
value, ok := ctx.Get("adminPerms")
|
||||
if !ok {
|
||||
return metastore.EffectivePermissions{}
|
||||
}
|
||||
perms, ok := value.(metastore.EffectivePermissions)
|
||||
if !ok {
|
||||
return metastore.EffectivePermissions{}
|
||||
}
|
||||
return perms
|
||||
}
|
||||
|
||||
func normalizeAlertSeverity(severity string) string {
|
||||
normalized := strings.ToLower(strings.TrimSpace(severity))
|
||||
switch normalized {
|
||||
case "danger", "warning", "info", "ok":
|
||||
return normalized
|
||||
default:
|
||||
return "ok"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user