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>
This commit is contained in:
1 parent
ba394b8fac
commit
e33a99241e
21 files changed
+1714
-25
No files matched your search
@@ -37,10 +37,11 @@ func CurrentUser(ctx context.Context) (auth.User, bool) {
|
||||
}
|
||||
|
||||
type api struct {
|
||||
auth AuthService
|
||||
dir DirectoryService
|
||||
collab CollabHub
|
||||
log *slog.Logger
|
||||
auth AuthService
|
||||
dir DirectoryService
|
||||
settings SettingsService
|
||||
collab CollabHub
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func (a *api) requireUser(next http.HandlerFunc) http.HandlerFunc {
|
||||
@@ -140,6 +141,7 @@ func (a *api) routes(mux *routeMux) {
|
||||
|
||||
a.directoryRoutes(mux)
|
||||
a.spaceRoutes(mux)
|
||||
a.settingsRoutes(mux)
|
||||
}
|
||||
|
||||
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
|
||||
@@ -23,6 +23,7 @@ type Deps struct {
|
||||
DB Pinger
|
||||
Auth AuthService
|
||||
Directory DirectoryService
|
||||
Settings SettingsService
|
||||
// Collab serves /collab; nil disables live editing.
|
||||
Collab CollabHub
|
||||
Admin http.Handler
|
||||
@@ -51,7 +52,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, collab: d.Collab, log: d.Log}
|
||||
a := &api{auth: d.Auth, dir: d.Directory, settings: d.Settings, collab: d.Collab, log: d.Log}
|
||||
a.routes(mux)
|
||||
a.collabRoute(mux, d.CORSOrigins)
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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)))
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user