From ef55d260de01a9e83d2ff9aed22843ced59b49a0 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Mon, 12 Feb 2024 20:58:49 +0000 Subject: [PATCH] Add users button to home --- server/home.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/home.go b/server/home.go index 2959a19..6694a1b 100644 --- a/server/home.go +++ b/server/home.go @@ -1,6 +1,7 @@ package server import ( + "github.com/1f349/lavender/database" "github.com/1f349/lavender/pages" "github.com/google/uuid" "github.com/julienschmidt/httprouter" @@ -16,6 +17,13 @@ func (h *HttpServer) Home(rw http.ResponseWriter, _ *http.Request, _ httprouter. return } + var isAdmin bool + h.DbTx(rw, func(tx *database.Tx) (err error) { + roles, err := tx.GetUserRoles(auth.Data.ID) + isAdmin = HasRole(roles, "lavender:admin") + return err + }) + lNonce := uuid.NewString() auth.Session.Set("action-nonce", lNonce) if auth.Session.Save() != nil { @@ -29,5 +37,6 @@ func (h *HttpServer) Home(rw http.ResponseWriter, _ *http.Request, _ httprouter. "Subject": auth.Data.ID, "DisplayName": auth.Data.DisplayName, "Nonce": lNonce, + "IsAdmin": isAdmin, }) }