rbac system first stage
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user