rbac system first stage
This commit is contained in:
6
internal/view/component/admin/user_list.templ
Normal file
6
internal/view/component/admin/user_list.templ
Normal file
@@ -0,0 +1,6 @@
|
||||
package admin
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
|
||||
templ UserList(users *db.Users) {
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
8
internal/view/layout/admin_dashboard.templ
Normal file
8
internal/view/layout/admin_dashboard.templ
Normal file
@@ -0,0 +1,8 @@
|
||||
package layout
|
||||
|
||||
templ AdminDashboard() {
|
||||
@Global("Admin")
|
||||
<div>
|
||||
{ children... }
|
||||
</div>
|
||||
}
|
||||
10
internal/view/page/admin_dashboard.templ
Normal file
10
internal/view/page/admin_dashboard.templ
Normal file
@@ -0,0 +1,10 @@
|
||||
package page
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/layout"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/component/admin"
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
|
||||
templ AdminDashboard(users *db.Users) {
|
||||
@layout.AdminDashboard()
|
||||
@admin.UserList(users)
|
||||
}
|
||||
Reference in New Issue
Block a user