26 lines
671 B
Go
26 lines
671 B
Go
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"
|
|
"git.haelnorr.com/h/oslstats/internal/throw"
|
|
"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 {
|
|
throw.InternalServiceError(s, w, r, "Error", err)
|
|
}
|
|
_, _ = w.Write([]byte(strconv.FormatBool(isAdmin)))
|
|
})
|
|
}
|