fixed relationship issues

This commit is contained in:
2026-02-05 00:10:10 +11:00
parent 6a058ab636
commit 59ee880b63
22 changed files with 236 additions and 254 deletions

View File

@@ -46,8 +46,8 @@ func ensureUserHasAdminRole(ctx context.Context, tx bun.Tx, user *db.User) error
return errors.New("admin role not found in database")
}
// Grant admin role (nil grantedBy = system granted)
err = db.AssignRole(ctx, tx, user.ID, adminRole.ID, nil)
// Grant admin role
err = db.AssignRole(ctx, tx, user.ID, adminRole.ID)
if err != nil {
return errors.Wrap(err, "db.AssignRole")
}

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)))
})
}