feat: show the user menu as an avatar in the navbar #67
No reviewers
Labels
No labels
bug
critical
ebook-branch
high
low
main
medium
release-blocker
security
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jfro/fuzzy_catalog!67
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/navbar-avatar"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The navbar user menu is now an avatar instead of the email.
users.avatar_urlcolumn (migration20261018220000_add_avatar_url_to_users).pictureclaim: set, changed, or cleared when the IdP stops sending it. Only absolute http(s) URLs up to 2048 chars are kept (User.avatar_changeset/2), since it's used as an img src; anything else (javascript:,data:, relative) is dropped with a warning and never blocks the login. Changes are logged with the user id.Layouts.user_avatar/1: a daisyUIavatar-placeholdercircle with the first letter of the email, with the picture layered on top when there is one (so the letter still shows if the image fails). The img usesreferrerpolicy="no-referrer". Users without OIDC get the letter.Tests: picture sync (set, update, clear), bad picture claims, the avatar component with and without a picture, and the navbar rendering it. I checked the markup in tests but haven't looked at it in a browser, so it's worth a quick look on a dev server.
Fixes #49
Review from Nye (changes requested)
I did a static review of
b66657fplus a render check: I rebuilt the avatar markup with the same classes against daisyUI 5 + Tailwind 4 in headless Chromium. CI is green.Safety, all fine: avatar_changeset only keeps absolute http(s) URLs with a host, ≤ 2048 chars. javascript:, data:, relative paths and non-strings are dropped, and tests cover them. HEEx escapes the src attribute, so a URL can't inject markup. referrerpolicy=no-referrer is set. The avatar only shows in the user's own navbar, so a hostile picture claim can only make that user's own browser fetch it. The browser pipeline has no CSP, so external images load, and an http:// picture gets auto-upgraded by current browsers or falls back to the letter. The OIDC flow change is clean: sync_avatar runs only after a match or create, never blocks login, writes only when the value changed, and logs the id and set/cleared without the URL.
MEDIUM (blocking): the avatar doesn't render as a circle. daisyUI's
.avatar > divrule (aspect-ratio 1/1, overflow hidden) and.avatar-placeholder > divrule (flex centering) only match aLOW: if the IdP later sends an invalid picture, sync_avatar logs it and keeps the OLD avatar_url. It should probably clear it to nil instead. The 'drops a bad claim' test only covers new users, so add a case where a user already has an avatar.
NIT: the new '# Keeps the avatar in step…' comment went in under the existing '# The role is always "user" here…' comment, so that create_oidc_user comment now sits above sync_avatar. Reorder them so each comment sits above its own function.
Checklist: conventional title, Fixes #49, tests, Logger context, no version bump, nullable text migration: all ok.
Review from Nye (approved) at
c82cf45Covers
1ed3ff3(span classes match the circle fix verified in headless Chromium; img classes add clipping;sync_avatar(user, nil)on an invalid claim can't loop since validate_change skips nil) and the main mergec82cf45. Resolution checked againstgit merge-treeof1ed3ff3vs main2688fff: user.ex keeps both avatar_changeset and oidc_link_changeset with main's oidc_user? doc; accounts_test drops "never links to a local account" in favour of main's verified-email linking test. New test "a linked local account picks up the picture claim" is valid: every{:ok, user}from find_oidc_user (incl. link_oidc_identity) goes through sync_avatar. CI green.