fix(auth): new users inherit the system-wide default timezone

default_timezone existed as a system setting (admin-editable, exposed
via SettingsRegistry.DefaultTimezone) but nothing read it at user
creation — the CreateUser query didn't even carry the column, so every
new user got the DB default UTC regardless. Both creation paths
(public register + admin create) now seed the user's timezone from the
setting, validated with time.LoadLocation and falling back to UTC when
unwired/empty/invalid.

Test-infra fixes surfaced by the run: TestUpdateProfileSelfEdit was
self-editing the SHARED admin (renaming it past the harness cleanup's
preserve-list, leaking a second admin row that broke the last-admin
tests) — it now edits a dedicated user with a unique name; the
last-admin tests get an ensureSingleAdmin precondition helper; the
websocket collection name is run-unique (non-test names persist in the
shared DB and UNIQUE(user_id,name) 409s on rerun).
This commit is contained in:
John O'Keefe committed 2026-10-13 13:17:12 -04:00
1 parent bc6ce41762
commit 740213f0a4
9 files changed
+108 -14

No files matched your search

+7 -3
View File
@@ -2003,9 +2003,9 @@ func (q *Queries) CreateUnlinkedBook(ctx context.Context, arg CreateUnlinkedBook
}
const CreateUser = `-- name: CreateUser :one
INSERT INTO users (email, username, password_hash, first_name, last_name, theme, role)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, email, username, theme, first_name, last_name, role, created_at, updated_at
INSERT INTO users (email, username, password_hash, first_name, last_name, theme, role, timezone)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, email, username, theme, first_name, last_name, role, timezone, created_at, updated_at
`
type CreateUserParams struct {
@@ -2016,6 +2016,7 @@ type CreateUserParams struct {
LastName pgtype.Text `db:"last_name" json:"last_name"`
Theme pgtype.Text `db:"theme" json:"theme"`
Role string `db:"role" json:"role"`
Timezone pgtype.Text `db:"timezone" json:"timezone"`
}
type CreateUserRow struct {
@@ -2026,6 +2027,7 @@ type CreateUserRow struct {
FirstName pgtype.Text `db:"first_name" json:"first_name"`
LastName pgtype.Text `db:"last_name" json:"last_name"`
Role string `db:"role" json:"role"`
Timezone pgtype.Text `db:"timezone" json:"timezone"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
}
@@ -2039,6 +2041,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
arg.LastName,
arg.Theme,
arg.Role,
arg.Timezone,
)
var i CreateUserRow
err := row.Scan(
@@ -2049,6 +2052,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
&i.FirstName,
&i.LastName,
&i.Role,
&i.Timezone,
&i.CreatedAt,
&i.UpdatedAt,
)