fixed relationship issues

This commit is contained in:
2026-02-05 00:10:10 +11:00
parent 20308fe35c
commit 4c31c24069
22 changed files with 236 additions and 254 deletions

View File

@@ -0,0 +1,24 @@
package handlers
import (
"net/http"
"strconv"
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/internal/roles"
"github.com/uptrace/bun"
)
func PermTester(s *hws.Server, conn *bun.DB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user := db.CurrentUser(r.Context())
tx, _ := conn.BeginTx(r.Context(), nil)
isAdmin, err := user.HasRole(r.Context(), tx, roles.Admin)
tx.Rollback()
if err != nil {
throwInternalServiceError(s, w, r, "Error", err)
}
_, _ = w.Write([]byte(strconv.FormatBool(isAdmin)))
})
}