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:
tajniak81andClaude Opus 5.5 committed 2026-10-31 17:34:48 +01:00
1 parent 92cd81fd96
commit ffc6cc4fbc
31 files changed
+2326 -134

No files matched your search

+74
View File
@@ -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)
}))
}
+2 -1
View File
@@ -42,7 +42,7 @@ type api struct {
dir DirectoryService
settings SettingsService
files *auth.FileTokens
index SearchIndex
instance InstanceService
collab CollabHub
log *slog.Logger
}
@@ -152,6 +152,7 @@ func (a *api) routes(mux *routeMux) {
a.transferRoutes(mux)
a.shareRoutes(mux)
a.commentRoutes(mux)
a.adminRoutes(mux)
}
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
+3 -3
View File
@@ -28,8 +28,8 @@ type Deps struct {
Settings SettingsService
// FileTokens signs the ?token= of file links; nil allows only bearer tokens.
FileTokens *auth.FileTokens
// Search is the full-text index (admin reindex); nil disables it.
Search SearchIndex
// Instance serves the admin dashboard, health, jobs and backups.
Instance InstanceService
// MaxUpload caps one attachment in bytes.
MaxUpload int64
// Collab serves /collab; nil disables live editing.
@@ -60,7 +60,7 @@ func NewRouter(d Deps) http.Handler {
func newMux(d Deps) *routeMux {
mux := &routeMux{ServeMux: http.NewServeMux()}
a := &api{auth: d.Auth, dir: d.Directory, settings: d.Settings, files: d.FileTokens, index: d.Search, collab: d.Collab, log: d.Log}
a := &api{auth: d.Auth, dir: d.Directory, settings: d.Settings, files: d.FileTokens, instance: d.Instance, collab: d.Collab, log: d.Log}
a.routes(mux)
a.fileRoutes(mux, max(d.MaxUpload, 1<<20))
a.collabRoute(mux, d.CORSOrigins)
-23
View File
@@ -16,12 +16,6 @@ type SearchService interface {
Search(ctx context.Context, c access.Caller, wsID, text string, limit int) (directory.SearchResult, error)
}
// SearchIndex is the index maintenance the admin panel can trigger.
type SearchIndex interface {
Rebuild(ctx context.Context) error
Count() (uint64, error)
}
func (a *api) searchRoutes(mux *routeMux) {
mux.HandleFunc("GET /api/v1/workspaces/{id}/search", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
@@ -29,21 +23,4 @@ func (a *api) searchRoutes(mux *routeMux) {
res, err := a.dir.Search(r.Context(), caller(r), r.PathValue("id"), q.Get("q"), min(max(limit, 0), 50))
a.respond(w, res, err)
}))
mux.HandleFunc("POST /api/v1/admin/search/reindex", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
if err := access.ManageInstance(caller(r)); err != nil {
a.writeError(w, err)
return
}
if a.index == nil {
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": "unavailable"})
return
}
// Rebuilding can take a while; it runs on after the response.
go func() {
if err := a.index.Rebuild(context.WithoutCancel(r.Context())); err != nil {
a.log.Error("search: rebuild failed", "err", err)
}
}()
w.WriteHeader(http.StatusAccepted)
}))
}