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" } }