hammer-editor/base
Adam Brown 70d902894c
Add optional Terms of Service gate for account creation (#742)
* Add optional Terms of Service gate for account creation

Self-hosters can set an undocumented `termsOfService` path in ServerConfig
pointing at a plaintext file. When set, account creation is gated: the server
answers POST /api/account/create with 451 + the TOS text and a content-hash
version. The client shows a scrollable dialog; accepting resubmits with the
accepted version, declining discards the provisional server settings.

Disabled by default (null path); existing servers are unaffected.

* Cover TOS repository and 451 client handling; harden error-body parsing

Adds direct tests for TermsOfServiceRepository (FakeFileSystem: absent/missing/
blank/populated file, stable and content-derived version) and ServerAccountApi
(201 success, 451 -> TermsOfServiceRequiredException, malformed 451 -> default
failure).

Also broadens error-body parse handling: ktor raises ContentConvertException
(not kotlinx SerializationException) on malformed JSON, so both the create-account
451 path and the shared defaultFailureHandler now catch it and fall back to a
graceful failure instead of letting it escape as an unhandled coroutine exception.

* Fail fast when termsOfService points at a missing or blank file

A configured but unreadable/empty TOS path previously made challenge() return
null, silently disabling the terms gate and letting accounts be created with no
terms at all. resolveServerConfig now validates the path at startup and aborts
(as it already does for unparseable config), so a misconfiguration can't quietly
drop the legal gate.

* Resolve a relative termsOfService path against the config file's directory

A bare `termsOfService = "tos.txt"` previously resolved against the server's
working directory, so a terms file sitting next to config.toml wasn't found.
Relative paths now resolve against the config file's own directory; absolute
paths are unchanged.
2026-07-16 21:02:48 -07:00
..
src Add optional Terms of Service gate for account creation (#742) 2026-07-16 21:02:48 -07:00
build.gradle.kts Migrate :common DI to Koin compiler plugin DSL with compile-time safety 2026-07-14 23:37:54 -07:00