Story #2558 :: Task: Show real earned badges on the v3 user profile (and honour hide_badges) - #2627
Story #2558 :: Task: Show real earned badges on the v3 user profile (and honour hide_badges)#2627herzog0 wants to merge 3 commits into
hide_badges)#2627Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
hide_badges)hide_badges)
16e9173 to
6619fe7
Compare
bf61013 to
7e32217
Compare
7e32217 to
91f238b
Compare
8d329a6 to
69c0dda
Compare
69c0dda to
92bb266
Compare
92bb266 to
c7c88d9
Compare
c7c88d9 to
d64af2b
Compare
d64af2b to
d86f82b
Compare
d86f82b to
bca9211
Compare
jlchilders11
left a comment
There was a problem hiding this comment.
This looks good to me, and satisfies the requirements. Thanks for all of the hard work!
julioest
left a comment
There was a problem hiding this comment.
Approving! ✅
Two things that came up, neither blocking:
news/services.py:_entry_to_post_cardstill emitsbadge_url, so post-card authors on the Learn page and library detail get no badge. Rendering_user_profile.htmlwith that author dict shows the badge markup simply absent. Minimal fix is swapping the inline author dict forentry.author.to_v3_profile_dict(), which I checked is field-for-field identical apart from addingbadgeandbadge_label. Delegating the whole card toto_v3_post_card_dict()also fixes the badge but changescategory, since that method derives it from the tag while services derives it from the news type. Either way_get_entry_post_cardswill wantactive_badges_prefetch("author__badges").- Featuring reads
display_badge_idwhile the ticket's AC 2 asks for the highest rank. Nothing back-fills it, so a member who never opens the picker features nothing. Either add a fallback or amend AC 2 and the PR body.
QA: real badges on the websiteUntil now every badge shown on the website was the same fake gold medal for everybody. This
What this change does
What it does not do
Before you start
Test 1: award yourself a badge
Expected: you immediately hold Library Author / Bronze. Nothing had to be pressed. Test 2: pick it, and see it on your profile
Expected:
Test 3: no pick means no badge
Expected: no badge on your profile card, but the Badges card still lists the Bronze badge Set your Display Badge back to Bronze before continuing. Test 4: the list grows as you earn more
Expected: the Badges card now lists Silver and Bronze, Silver first. Your profile card
Test 5: the badge follows you around the siteWith a badge picked, and with a published news post authored by you, open each of:
Expected: your author card carries the same badge on all four. Worth knowing: before this change the news author card showed no badge at all, even for Test 6: library contributor lists
Expected: your contributor card there carries your badge too. Note it must be the latest version - the contributor cards read the current release, not the Test 7: hiding badges works, and fails safe
Expected: you still see your own badges. Hiding only affects what other people see.
Expected: no badge on your card anywhere. Any badge of yours visible to a logged-out visitor Untick it before continuing. Test 8: a badge kept after the rules change
Expected: your Gold badge is still there, even though you now have four achievements This is intentional - please do not report it as a bug. Members keep badges they already Test 9: taking a badge away
Expected: Gold has left the Badges card. Silver and Bronze are still there. If Gold was the Test 10: it works without JavaScriptTurn JavaScript off in your browser and reload Expected: all the badges are still there. They are drawn by the server, so nothing here depends Test 11: a quick look in dark mode and on a phoneSwitch the site to dark mode and check the profile, the news list and the community page. Then look Expected: the badges are visible and legible in both. Things that look wrong but are meant to be that way
Reporting anything you findPlease include the member's email, the page URL where you saw it, whether you were logged |
bca9211 to
dd37b28
Compare
dd37b28 to
624b7a3
Compare
Not a duplicate, Github thought the previous one (#2614) was closed since the branches changed order in the PR stack, so I'm reopening this.
Issue: #2558
julia/badge-selectionSummary & Context
The user-visible half. Real badges replace the placeholder gold medal everywhere a badge is
rendered: the profile page, the profile card, news author cards, the post list and the community
page.
badges/display.pyis the whole presentation boundary. The v3 badge templates take a componenttoken and a label, never a model instance, so the rank-to-asset mapping lives there rather than on
the user model.
Changes
badges/display.pyheld_badges- the member's active badges, highest rank first, each rank once. Retiring atier keeps the badges already awarded against it, so a member who also qualifies under its
replacement holds the same rank twice; both rows are real history but only one is a badge to
show.
featured_badge/badge_cards/badge_card.TIER_TOKENS- bronze/silver/gold/platinum/diamond tobadge-tier-1..5, diamond at thetop. A test asserts the token numbers climb with the rank ladder so the pair cannot drift
apart again.
active_badges_prefetch(lookup)- the prefetch every multi-card page needs.hide_badgesfails closed.held_badgesreturns an empty list when the member has hiddentheir badges; only the owner's own views pass
include_hidden.User.featured_badgereplaces thebadge_urlplaceholder. It lives on the model onlybecause templates read it as an attribute; everything about selection and rendering is in
badges.display.users/profile_cards.py: emitsbadge/badge_label. It previously emittedbadge_urlwhile
_user_profile.htmlreadsauthor.badge, so news author cards rendered no badge atall even once real data existed. That is a defect on
develop, fixed here because it is thesame feature.
dateobjects rendered through Django'sDATE_FORMAT, taken throughtimezone.localtimeso an evening award is not dated to the next day west of UTC. There is atest under
TIME_ZONE="America/New_York"pinning it.ak/homepage.py,core/views.py(community),news/views.py(post detail),libraries/mixins.pyandlibraries/utils.py(contributor lists). Each has a constant-query regression test. Thequerysets that
select_relatedthe author ask for badges through the path(
author__badges), becausePrefetch("author", queryset=...)is silently dropped when the FKis already cached.
develop:core/views.py's v3 examples page labelledtier-4 "Diamond" and tier-5 "Platinum" on both the badge and star sets. Platinum is tier 4,
diamond is tier 5. The same inversion in the
_badge_v3.htmlheader comment and theprofile-edit mock is corrected too.
wrong badge; each call site has a
django_assert_num_queriestest, so a regression failsloudly.
featured_badgeis acached_property. A view that awards a badge and re-renders the sameuser instance in one request would show the stale value. Nothing does that today.
one. Letting them pick is a separate ticket
Separate ticket.
Separate ticket. This PR renders what a member has,
not what they could earn.
templates/v3/user_profile_page.htmlswitches from thedemo_badgesmock toprofile_badges.The
core/views.pyexamples page keeps itsdemo_*fixtures, correctly.Screenshots
(Will add them shortly)
Peer-review testing steps
Setup.
just migrate,docker compose up, and turn the v3 flag on for everyone at/admin/waffle/flag/- every template here is a v3 one. For step 8 you also needDEBUG_TOOLBAR=Truein
.envand a restart./admin/badges/userachievement/add/- your user, achievementLibrary Authoring, and a note (it is required for a manual grant). Save. Bronze is one grant, so
/admin/badges/userbadge/shows Library Author / Bronze immediately./users/me/- the placeholder gold medal is gone and Bronze is on the card. Thebadges card lists it once, with the award date. Cross-check that date against Awarded at in the
admin: they must be the same day, which is the timezone fix.
grants are intended, counts accumulate). Reload
/users/me/: the card now shows Silver, whilethe badges card lists Bronze and Silver. The card shows one badge, the list shows the ladder.
card lists Gold, Silver, Bronze in that order, highest rank first. Now raise Gold's threshold to 6 on
/admin/badges/badge/: the admin says it retired the old tier and created a replacement, and yourGold stays on the profile even though you no longer meet the new number. That is the
grandfathering working as intended, not a stale render. (One rank showing twice is the case the
dedup in
held_badgesguards; it needs rows the admin will not create for you, so it is covered bytest rather than by hand.)
/news/, the post detailpage,
/community/and the homepage. Your author card carries the same badge on all four. On thebase branch the news author card renders no badge at all even with real data, so this is a fix to
confirm, not just a check.
/admin/libraries/libraryversion/(the contributor cards read the version, not the library), thenopen
/library/<version>/<library>/: those cards carry badges too./users/me/?edit=true. Yourown profile still shows them, because the owner's view passes
include_hidden. Then open/community/,/news/and your post's detail page in a logged-out window: your card there hasno badge at all.
/community/,/news/and a postdetail page. Grant badges to several more members whose cards appear on those pages, reload, and the
count must be unchanged. A count that climbs with the number of cards is the regression these
prefetches exist to prevent.
/v3/demo/components/(staff only) - tier-4 is Platinum andtier-5 is Diamond, on both the badge set and the star set. It was inverted on the base branch.
/users/me/and/community/: badges are server-renderedand must all still be there.
/admin/badges/userbadge/(the action asksfor a note).
/users/me/falls back to Silver on the card, Gold leaves the badges list, and nothingelse moves.
Self-review Checklist
Frontend
Backend