Build out the admin panel
- Overview: users, organizations, workspaces, spaces, pages, files and storage (org admins see their organization), plus pages open right now, the search index size, and version, uptime and database health. - Users: invite people by email (with resend, revoke and a copyable link when mail fails) and send a password-reset email. - Authentication: sign-up on or off, the email-domain allow-list, and sign-in links by email. - Branding: instance name, accent colour and logo. The web app shows them on the sign-in pages and applies the accent colour everywhere. - Email and Storage: SMTP and S3 settings with test buttons. - Maintenance: create, download and delete database backups, and a view of the background jobs with their last run, duration and errors. On the server, a small jobs registry records each search-indexing pass, and "search.rebuild" replaces the separate reindex endpoint. A new instance package serves the dashboard numbers, health and backups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
92cd81fd96
commit
ffc6cc4fbc
31 files changed
+2326
-134
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/instance"
|
||||
"docwell/server/internal/jobs"
|
||||
)
|
||||
|
||||
// InstanceService is the admin panel's view of the server (instance.Service).
|
||||
type InstanceService interface {
|
||||
Stats(ctx context.Context, c access.Caller) (instance.Stats, error)
|
||||
Health(ctx context.Context, c access.Caller) (instance.Health, error)
|
||||
Jobs(c access.Caller) ([]jobs.Job, error)
|
||||
RunJob(c access.Caller, name string) error
|
||||
ListBackups(ctx context.Context, c access.Caller) ([]instance.Backup, error)
|
||||
CreateBackup(ctx context.Context, c access.Caller) error
|
||||
DeleteBackup(ctx context.Context, c access.Caller, key string) error
|
||||
OpenBackup(ctx context.Context, c access.Caller, key string) (*http.Response, error)
|
||||
}
|
||||
|
||||
func (a *api) adminRoutes(mux *routeMux) {
|
||||
mux.HandleFunc("GET /api/v1/admin/stats", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
st, err := a.instance.Stats(r.Context(), caller(r))
|
||||
a.respond(w, st, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/admin/health", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
h, err := a.instance.Health(r.Context(), caller(r))
|
||||
a.respond(w, h, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/admin/jobs", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := a.instance.Jobs(caller(r))
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/admin/jobs/{name}/run", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := a.instance.RunJob(caller(r), r.PathValue("name")); err != nil {
|
||||
a.writeError(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}))
|
||||
|
||||
mux.HandleFunc("GET /api/v1/admin/backups", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := a.instance.ListBackups(r.Context(), caller(r))
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/admin/backups", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.instance.CreateBackup(r.Context(), caller(r)))
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/admin/backups/{key}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.instance.DeleteBackup(r.Context(), caller(r), r.PathValue("key")))
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/admin/backups/{key}", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := a.instance.OpenBackup(r.Context(), caller(r), r.PathValue("key"))
|
||||
if err != nil {
|
||||
a.writeError(w, err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
h := w.Header()
|
||||
h.Set("Content-Type", "application/zip")
|
||||
h.Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{"filename": r.PathValue("key")}))
|
||||
if n := resp.Header.Get("Content-Length"); n != "" {
|
||||
h.Set("Content-Length", n)
|
||||
}
|
||||
_, _ = io.Copy(w, resp.Body)
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user