added admin page and audit log viewing
This commit is contained in:
@@ -11,19 +11,34 @@ import (
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
// AdminUsersList shows all users
|
||||
// AdminUsersPage renders the full admin dashboard page with users section
|
||||
func AdminUsersPage(s *hws.Server, conn *bun.DB) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var users *db.List[db.User]
|
||||
if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
var err error
|
||||
users, err = db.GetUsersWithRoles(ctx, tx, nil)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "db.GetUsersWithRoles")
|
||||
}
|
||||
return true, nil
|
||||
}); !ok {
|
||||
return
|
||||
}
|
||||
renderSafely(adminview.DashboardPage(users), s, r, w)
|
||||
})
|
||||
}
|
||||
|
||||
// AdminUsersList shows all users (HTMX content replacement)
|
||||
func AdminUsersList(s *hws.Server, conn *bun.DB) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var users *db.List[db.User]
|
||||
pageOpts := pageOptsFromForm(s, w, r)
|
||||
if pageOpts == nil {
|
||||
return
|
||||
}
|
||||
if ok := db.WithReadTx(s, w, r, conn, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
var err error
|
||||
users, err = db.GetUsers(ctx, tx, pageOpts)
|
||||
// Get users with their roles
|
||||
users, err = db.GetUsersWithRoles(ctx, tx, nil)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "db.GetUsers")
|
||||
return false, errors.Wrap(err, "db.GetUsersWithRoles")
|
||||
}
|
||||
return true, nil
|
||||
}); !ok {
|
||||
|
||||
Reference in New Issue
Block a user