admin page updates

This commit is contained in:
2026-02-14 14:54:06 +11:00
parent 55f79176cc
commit 0fc3bb0c94
22 changed files with 2136 additions and 318 deletions

View File

@@ -21,12 +21,22 @@ import (
// AdminRoles renders the full admin dashboard page with roles section
func AdminRoles(s *hws.Server, conn *bun.DB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var rolesList []*db.Role
var pageOpts *db.PageOpts
if r.Method == "GET" {
pageOpts = pageOptsFromQuery(s, w, r)
} else {
pageOpts = pageOptsFromForm(s, w, r)
}
if pageOpts == nil {
return
}
var rolesList *db.List[db.Role]
if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
rolesList, err = db.ListAllRoles(ctx, tx)
rolesList, err = db.GetRoles(ctx, tx, pageOpts)
if err != nil {
return false, errors.Wrap(err, "db.ListAllRoles")
return false, errors.Wrap(err, "db.GetRoles")
}
return true, nil
}); !ok {
@@ -64,7 +74,12 @@ func AdminRoleCreate(s *hws.Server, conn *bun.DB, audit *auditlog.Logger) http.H
return
}
var rolesList []*db.Role
pageOpts := pageOptsFromForm(s, w, r)
if pageOpts == nil {
return
}
var rolesList *db.List[db.Role]
var newRole *db.Role
if ok := db.WithNotifyTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
newRole = &db.Role{
@@ -80,9 +95,9 @@ func AdminRoleCreate(s *hws.Server, conn *bun.DB, audit *auditlog.Logger) http.H
return false, errors.Wrap(err, "db.Insert")
}
rolesList, err = db.ListAllRoles(ctx, tx)
rolesList, err = db.GetRoles(ctx, tx, pageOpts)
if err != nil {
return false, errors.Wrap(err, "db.ListAllRoles")
return false, errors.Wrap(err, "db.GetRoles")
}
return true, nil
@@ -162,7 +177,12 @@ func AdminRoleDelete(s *hws.Server, conn *bun.DB, audit *auditlog.Logger) http.H
return
}
var rolesList []*db.Role
pageOpts := pageOptsFromForm(s, w, r)
if pageOpts == nil {
return
}
var rolesList *db.List[db.Role]
if ok := db.WithNotifyTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
// First check if role exists and get its details
role, err := db.GetRoleByID(ctx, tx, roleID)
@@ -185,9 +205,9 @@ func AdminRoleDelete(s *hws.Server, conn *bun.DB, audit *auditlog.Logger) http.H
}
// Reload roles
rolesList, err = db.ListAllRoles(ctx, tx)
rolesList, err = db.GetRoles(ctx, tx, pageOpts)
if err != nil {
return false, errors.Wrap(err, "db.ListAllRoles")
return false, errors.Wrap(err, "db.GetRoles")
}
return true, nil
@@ -289,7 +309,12 @@ func AdminRolePermissionsUpdate(s *hws.Server, conn *bun.DB, audit *auditlog.Log
selectedPermIDs[id] = true
}
var rolesList []*db.Role
pageOpts := pageOptsFromForm(s, w, r)
if pageOpts == nil {
return
}
var rolesList *db.List[db.Role]
if ok := db.WithWriteTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
// Get role with current permissions
role, err := db.GetRoleWithPermissions(ctx, tx, roleID)
@@ -356,9 +381,9 @@ func AdminRolePermissionsUpdate(s *hws.Server, conn *bun.DB, audit *auditlog.Log
}
// Reload roles
rolesList, err = db.ListAllRoles(ctx, tx)
rolesList, err = db.GetRoles(ctx, tx, pageOpts)
if err != nil {
return false, errors.Wrap(err, "db.ListAllRoles")
return false, errors.Wrap(err, "db.GetRoles")
}
return true, nil