rbac system first stage

This commit is contained in:
2026-02-03 21:37:06 +11:00
parent 9f7e7c88a0
commit c4a4226647
38 changed files with 1966 additions and 114 deletions

View File

@@ -1,6 +1,10 @@
package nav
import "git.haelnorr.com/h/oslstats/internal/db"
import (
"context"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/pkg/contexts"
)
type ProfileItem struct {
name string // Label to display
@@ -8,8 +12,8 @@ type ProfileItem struct {
}
// Return the list of profile links
func getProfileItems() []ProfileItem {
return []ProfileItem{
func getProfileItems(ctx context.Context) []ProfileItem {
items := []ProfileItem{
{
name: "Profile",
href: "/profile",
@@ -19,12 +23,23 @@ func getProfileItems() []ProfileItem {
href: "/account",
},
}
// Add admin link if user has admin role
cache := contexts.Permissions(ctx)
if cache != nil && cache.Roles["admin"] {
items = append(items, ProfileItem{
name: "Admin Panel",
href: "/admin",
})
}
return items
}
// Returns the right portion of the navbar
templ navRight() {
{{ user := db.CurrentUser(ctx) }}
{{ items := getProfileItems() }}
{{ items := getProfileItems(ctx) }}
<div class="flex items-center gap-2">
<div class="sm:flex sm:gap-2">
if user != nil {