From 320f31086d0189b952f30cb782d08b345d6cd0d6 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Tue, 13 Oct 2026 18:25:56 -0400 Subject: [PATCH] fix(web): field-mapping + fragile-hx-vals sweep across profile and library surfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Field-by-field audit of the profile surface (set → save → reopen → read back, driven through the emulator browser via CDP): - getTemplateUserWithTheme (every SSR page + the /profile self-edit form) never mapped FirstName/LastName/CreatedAt — stored names rendered as empty inputs. Now mapped (timezone was already mapped). - Admin profile-modal Timezone mapping fixed earlier this round held: all seven fields verified set → 200 + HX-Refresh → reopen → correct values, DB cross-checked. - Role promote/demote via the card select verified against the DB (the PUT answers HX-Refresh, so the page reload shows the new role). - Admin password reset verified end-to-end: new password logs in, old one 401s, original restored. - admin_library folder-remove hx-vals was string-concatenated JSON — a folder path containing a quote or backslash made it invalid and the remove button silently died under htmx 2 (the same class as the profile-save bug). Now built with json.Marshal behind the js: prefix. Verified the generated attribute on the live page. - Other hx-vals/hx-headers sites audited: constants and uuids only (safe charset), left alone. --- internal/router/helpers.go | 17 ++++++++++------- templates/admin_library.templ | 2 +- templates/admin_library_templ.go | 4 ++-- templates/utils.go | 11 +++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/internal/router/helpers.go b/internal/router/helpers.go index 7eabf64d..9e463177 100644 --- a/internal/router/helpers.go +++ b/internal/router/helpers.go @@ -52,13 +52,16 @@ func getTemplateUserWithTheme(c *echo.Context, cfg *Config) (templates.User, err } return templates.User{ - ID: userID, - Email: userEmail, - Username: userUsername, - Role: userRole, - Theme: userTheme, - Token: token, - Timezone: userTimezone, + ID: userID, + Email: userEmail, + Username: userUsername, + Role: userRole, + Theme: userTheme, + Token: token, + Timezone: userTimezone, + FirstName: getText(userDB.FirstName), + LastName: getText(userDB.LastName), + CreatedAt: userDB.CreatedAt.Time, }, nil } diff --git a/templates/admin_library.templ b/templates/admin_library.templ index ef9587cf..603812f1 100644 --- a/templates/admin_library.templ +++ b/templates/admin_library.templ @@ -307,7 +307,7 @@ templ LibraryPanel(user User, libraryID string, library LibraryData, folders []F