Files
Docwell/Server/internal/httpapi/settings.go
T
tajniak81andClaude Opus 5.5 e33a99241e Add instance settings and mail delivery through PocketBase
Superadmins can now change signup rules (on/off and the domain allow-list)
and branding at runtime; the environment variables only seed the defaults.
Mail and S3 storage settings pass through to PocketBase's own settings, and
docwell-server sends its own emails through a PocketBase hook so there is a
single SMTP configuration. The boot hook no longer wipes SMTP settings that
were not set from the environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 16:22:53 +01:00

53 lines
1.9 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
"context"
"net/http"
"docwell/server/internal/access"
"docwell/server/internal/settings"
)
// SettingsService is the part of settings.Service the HTTP layer uses.
type SettingsService interface {
Public(ctx context.Context) (settings.Public, error)
Get(ctx context.Context, c access.Caller) (settings.Instance, error)
Apply(ctx context.Context, c access.Caller, in settings.Update) (settings.Instance, error)
TestEmail(ctx context.Context, c access.Caller, to string) error
TestStorage(ctx context.Context, c access.Caller) error
}
func (a *api) settingsRoutes(mux *routeMux) {
// Branding and signup availability, for the login and signup pages.
mux.HandleFunc("GET /api/v1/settings/public", func(w http.ResponseWriter, r *http.Request) {
p, err := a.settings.Public(r.Context())
a.respond(w, p, err)
})
// Instance settings (superadmins; the service checks the role).
mux.HandleFunc("GET /api/v1/admin/settings", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
s, err := a.settings.Get(r.Context(), caller(r))
a.respond(w, s, err)
}))
mux.HandleFunc("PATCH /api/v1/admin/settings", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
var in settings.Update
if !a.decode(w, r, &in) {
return
}
s, err := a.settings.Apply(r.Context(), caller(r), in)
a.respond(w, s, err)
}))
mux.HandleFunc("POST /api/v1/admin/settings/test-email", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
var in struct{ To string }
if !a.decode(w, r, &in) {
return
}
a.respondNoContent(w, a.settings.TestEmail(r.Context(), caller(r), in.To))
}))
mux.HandleFunc("POST /api/v1/admin/settings/test-storage", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
a.respondNoContent(w, a.settings.TestStorage(r.Context(), caller(r)))
}))
}