feat: Token.BAND (Wristband) — non-admin variant of PASS, admin-awarded via Django admin to any user (NOT auto-granted on signal, NO is_staff coupling, NO model-layer guard). Mirrors PASS at runtime — fills 1 gate slot, never consumed, stays equipped, no current_room tie, no expiry, no In-Use microtooltip — but separates the policy concerns so PASS stays a deliberate staff-only trinket while BAND becomes the regular-user version (promotional / play-reward / staging give-away). Tooltip prose: name "Wristband", desc "Admit All Entry" (shared w. PASS — phrasing reflects the never-depleted lifetime, not multi-slot semantics), shoptalk "Unlimited free entry (BYOB)", expiry "no expiry". fa-ring icon across all 4 surfaces (Game Kit applet #id_kit_wristband between PASS + CARTE, gk-trinkets section, kit-bag dialog Trinket slot, wallet PASS→BAND→COIN elif chain). Priority chain — PASS → BAND → COIN → FREE → TITHE — wired identically into both apps.epic.models.select_token (room gatekeeper) + apps.gameboard.models._select_my_sea_token (my-sea gatekeeper); BAND wins over consumables for any holder while PASS still wins for staff who happen to hold both. debit_token + debit_my_sea_token treat BAND same as PASS: slot marked FILLED w. debited_token_type=BAND, token row preserved, current_room untouched, equipped_trinket unchanged. View contexts (gameboard, toggle_game_applets, _game_kit_context, wallet, toggle_wallet_applets) pass a band key — universal lookup, NO is_staff filter. Migration lyric/0007_alter_token_token_type — choices-only AlterField. TDD — 5 FTs in test_trinket_wristband.py (test_band_not_auto_equipped_after_award, test_band_tooltip_renders_full_prose, test_band_uses_fa_ring_icon, test_equipped_band_shows_equipped_mini_tooltip, test_equipped_band_shows_doff_active_don_disabled); 4 tooltip UTs (BandTokenTooltipTest); 5 model ITs (BandTokenAdminAwardTest — no-auto-grant for non-staff + staff, admin-can-award to either branch, not-auto-equipped); 2 priority-chain ITs (test_returns_band_when_held_and_no_pass, test_pass_still_wins_over_band_for_staff); 1 debit IT (test_debit_band_does_not_consume_or_unequip). 1145 IT/UT + 5 FT green. A boost-pass / promo-band w. richer semantics (multi-slot admit, time-window, etc.) lands as YET-ANOTHER token_type later — keep BAND the minimal "PASS minus admin gate" trinket so the policy axis stays clean. Captured in [[sprint-band-trinket-may21]] alongside the standing auto-commit rule [[feedback-auto-commit-after-build]]
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -165,6 +165,7 @@ def wallet(request):
|
||||
return render(request, "apps/dashboard/wallet.html", {
|
||||
"wallet": request.user.wallet,
|
||||
"pass_token": request.user.tokens.filter(token_type=Token.PASS).first() if request.user.is_staff else None,
|
||||
"band": request.user.tokens.filter(token_type=Token.BAND).first(),
|
||||
"coin": request.user.tokens.filter(token_type=Token.COIN).first(),
|
||||
"free_tokens": free_tokens,
|
||||
"tithe_tokens": tithe_tokens,
|
||||
@@ -201,6 +202,7 @@ def toggle_wallet_applets(request):
|
||||
"applets": applet_context(request.user, "wallet"),
|
||||
"wallet": request.user.wallet,
|
||||
"pass_token": request.user.tokens.filter(token_type=Token.PASS).first() if request.user.is_staff else None,
|
||||
"band": request.user.tokens.filter(token_type=Token.BAND).first(),
|
||||
"coin": request.user.tokens.filter(token_type=Token.COIN).first(),
|
||||
"free_tokens": list(request.user.tokens.filter(token_type=Token.FREE)),
|
||||
"tithe_tokens": list(request.user.tokens.filter(token_type=Token.TITHE)),
|
||||
|
||||
@@ -117,6 +117,9 @@ def select_token(user):
|
||||
pass_token = user.tokens.filter(token_type=Token.PASS).first()
|
||||
if pass_token:
|
||||
return pass_token
|
||||
band = user.tokens.filter(token_type=Token.BAND).first()
|
||||
if band:
|
||||
return band
|
||||
coin = user.tokens.filter(token_type=Token.COIN, current_room__isnull=True).first()
|
||||
if coin:
|
||||
return coin
|
||||
@@ -145,7 +148,7 @@ def debit_token(user, slot, token):
|
||||
user.save(update_fields=["equipped_trinket"])
|
||||
elif token.token_type == Token.CARTE:
|
||||
pass # current_room already set in drop_token; token not consumed
|
||||
elif token.token_type != Token.PASS:
|
||||
elif token.token_type not in (Token.PASS, Token.BAND):
|
||||
slot.debited_token_expires_at = token.expires_at
|
||||
token.delete()
|
||||
slot.gamer = user
|
||||
|
||||
@@ -48,6 +48,25 @@ class DebitTokenTest(TestCase):
|
||||
self.assertEqual(self.slot.status, GateSlot.FILLED)
|
||||
self.assertEqual(self.slot.gamer, self.owner)
|
||||
|
||||
def test_debit_band_does_not_consume_or_unequip(self):
|
||||
"""BAND mirrors PASS — fills the slot, but never deleted, never
|
||||
gets `current_room` set, and stays equipped (debit_token's PASS
|
||||
branch is the model). The wallet should keep showing the BAND
|
||||
after the user enters a gate w. it."""
|
||||
band = Token.objects.create(user=self.owner, token_type=Token.BAND)
|
||||
self.owner.equipped_trinket = band
|
||||
self.owner.save(update_fields=["equipped_trinket"])
|
||||
debit_token(self.owner, self.slot, band)
|
||||
self.assertTrue(Token.objects.filter(pk=band.pk).exists())
|
||||
band.refresh_from_db()
|
||||
self.assertIsNone(band.current_room_id)
|
||||
self.owner.refresh_from_db()
|
||||
self.assertEqual(self.owner.equipped_trinket_id, band.pk)
|
||||
self.slot.refresh_from_db()
|
||||
self.assertEqual(self.slot.status, GateSlot.FILLED)
|
||||
self.assertEqual(self.slot.gamer, self.owner)
|
||||
self.assertEqual(self.slot.debited_token_type, Token.BAND)
|
||||
|
||||
def test_debit_fills_last_slot_and_opens_gate(self):
|
||||
for i in range(2, 7):
|
||||
gamer = User.objects.create(email=f"g{i}@test.io")
|
||||
@@ -138,6 +157,23 @@ class SelectTokenTest(TestCase):
|
||||
token = select_token(self.user)
|
||||
self.assertEqual(token.token_type, Token.PASS)
|
||||
|
||||
def test_returns_band_when_held_and_no_pass(self):
|
||||
"""BAND beats COIN/FREE/TITHE for non-staff (same never-consumed
|
||||
rationale as PASS — burn the cheaper consumables first)."""
|
||||
band = Token.objects.create(user=self.user, token_type=Token.BAND)
|
||||
token = select_token(self.user)
|
||||
self.assertEqual(token.pk, band.pk)
|
||||
|
||||
def test_pass_still_wins_over_band_for_staff(self):
|
||||
"""Staff holding both PASS and BAND get PASS — PASS sits at the top
|
||||
of the priority chain, BAND slots in below it."""
|
||||
self.user.is_staff = True
|
||||
self.user.save()
|
||||
pass_token = Token.objects.create(user=self.user, token_type=Token.PASS)
|
||||
Token.objects.create(user=self.user, token_type=Token.BAND)
|
||||
token = select_token(self.user)
|
||||
self.assertEqual(token.pk, pass_token.pk)
|
||||
|
||||
|
||||
class RoomTableStatusTest(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -134,6 +134,9 @@ def _select_my_sea_token(user):
|
||||
pass_token = user.tokens.filter(token_type=Token.PASS).first()
|
||||
if pass_token:
|
||||
return pass_token
|
||||
band = user.tokens.filter(token_type=Token.BAND).first()
|
||||
if band:
|
||||
return band
|
||||
coin = user.tokens.filter(
|
||||
token_type=Token.COIN, current_room__isnull=True,
|
||||
).filter(
|
||||
@@ -171,8 +174,8 @@ def debit_my_sea_token(user, token):
|
||||
if user.equipped_trinket_id == token.pk:
|
||||
user.equipped_trinket = None
|
||||
user.save(update_fields=["equipped_trinket"])
|
||||
elif token.token_type == Token.PASS:
|
||||
pass
|
||||
elif token.token_type in (Token.PASS, Token.BAND):
|
||||
pass # auto-admit trinkets — never consumed, stay equipped
|
||||
else:
|
||||
token.delete()
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ GAMEBOARD_APPLET_ORDER = [
|
||||
@login_required(login_url="/")
|
||||
def gameboard(request):
|
||||
pass_token = request.user.tokens.filter(token_type=Token.PASS).first() if request.user.is_staff else None
|
||||
band = request.user.tokens.filter(token_type=Token.BAND).first()
|
||||
coin = request.user.tokens.filter(token_type=Token.COIN).first()
|
||||
carte = request.user.tokens.filter(token_type=Token.CARTE).first()
|
||||
free_tokens = list(request.user.tokens.filter(
|
||||
@@ -47,6 +48,7 @@ def gameboard(request):
|
||||
return render(
|
||||
request, "apps/gameboard/gameboard.html", {
|
||||
"pass_token": pass_token,
|
||||
"band": band,
|
||||
"coin": coin,
|
||||
"carte": carte,
|
||||
"equipped_trinket_id": request.user.equipped_trinket_id,
|
||||
@@ -71,6 +73,7 @@ def toggle_game_applets(request):
|
||||
return render(request, "apps/gameboard/_partials/_applets.html", {
|
||||
"applets": applet_context(request.user, "gameboard"),
|
||||
"pass_token": request.user.tokens.filter(token_type=Token.PASS).first() if request.user.is_staff else None,
|
||||
"band": request.user.tokens.filter(token_type=Token.BAND).first(),
|
||||
"coin": request.user.tokens.filter(token_type=Token.COIN).first(),
|
||||
"carte": request.user.tokens.filter(token_type=Token.CARTE).first(),
|
||||
"equipped_trinket_id": request.user.equipped_trinket_id,
|
||||
@@ -133,6 +136,7 @@ def _game_kit_context(user):
|
||||
from apps.lyric.models import PRONOUN_CHOICES
|
||||
coin = user.tokens.filter(token_type=Token.COIN).first()
|
||||
pass_token = user.tokens.filter(token_type=Token.PASS).first() if user.is_staff else None
|
||||
band = user.tokens.filter(token_type=Token.BAND).first()
|
||||
carte = user.tokens.filter(token_type=Token.CARTE).first()
|
||||
free_tokens = list(user.tokens.filter(
|
||||
token_type=Token.FREE, expires_at__gt=timezone.now()
|
||||
@@ -145,6 +149,7 @@ def _game_kit_context(user):
|
||||
return {
|
||||
"coin": coin,
|
||||
"pass_token": pass_token,
|
||||
"band": band,
|
||||
"carte": carte,
|
||||
"free_tokens": free_tokens,
|
||||
"tithe_tokens": tithe_tokens,
|
||||
|
||||
18
src/apps/lyric/migrations/0007_alter_token_token_type.py
Normal file
18
src/apps/lyric/migrations/0007_alter_token_token_type.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 6.0 on 2026-05-21 15:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lyric', '0006_user_significator_user_significator_reversed'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='token',
|
||||
name='token_type',
|
||||
field=models.CharField(choices=[('coin', 'Coin-on-a-String'), ('Free', 'Free Token'), ('tithe', 'Tithe Token'), ('pass', 'Backstage Pass'), ('band', 'Wristband'), ('carte', 'Carte Blanche')], max_length=8),
|
||||
),
|
||||
]
|
||||
@@ -232,12 +232,14 @@ class Token(models.Model):
|
||||
FREE = "Free"
|
||||
TITHE = "tithe"
|
||||
PASS = "pass"
|
||||
BAND = "band"
|
||||
CARTE = "carte"
|
||||
TOKEN_TYPE_CHOICES = [
|
||||
(COIN, "Coin-on-a-String"),
|
||||
(FREE, "Free Token"),
|
||||
(TITHE, "Tithe Token"),
|
||||
(PASS, "Backstage Pass"),
|
||||
(BAND, "Wristband"),
|
||||
(CARTE, "Carte Blanche"),
|
||||
]
|
||||
|
||||
@@ -276,7 +278,7 @@ class Token(models.Model):
|
||||
def tooltip_description(self):
|
||||
if self.token_type in (self.COIN, self.FREE):
|
||||
return "Admit 1 Entry"
|
||||
if self.token_type == self.PASS:
|
||||
if self.token_type in (self.PASS, self.BAND):
|
||||
return "Admit All Entry"
|
||||
if self.token_type == self.TITHE:
|
||||
return "+ Writ bonus"
|
||||
@@ -285,7 +287,7 @@ class Token(models.Model):
|
||||
return ""
|
||||
|
||||
def tooltip_expiry(self):
|
||||
if self.token_type in (self.COIN, self.PASS, self.CARTE):
|
||||
if self.token_type in (self.COIN, self.PASS, self.BAND, self.CARTE):
|
||||
if self.token_type == self.COIN and self.next_ready_at:
|
||||
return f"Ready {self.next_ready_at.strftime('%Y-%m-%d')}"
|
||||
return "no expiry"
|
||||
@@ -306,6 +308,8 @@ class Token(models.Model):
|
||||
return "a spot of good fortune"
|
||||
if self.token_type == self.PASS:
|
||||
return "\u2018Entry fee\u2019? Pal, do you know who you\u2019re talking to?"
|
||||
if self.token_type == self.BAND:
|
||||
return "Unlimited free entry (BYOB)"
|
||||
if self.token_type == self.CARTE:
|
||||
return "No, I\u2019m afraid we\u2019ll be taking over from here."
|
||||
return None
|
||||
|
||||
@@ -360,6 +360,45 @@ class PassTokenStaffOnlyGuardTest(TestCase):
|
||||
self.assertEqual(token.token_type, Token.TITHE)
|
||||
|
||||
|
||||
class BandTokenAdminAwardTest(TestCase):
|
||||
"""BAND is the non-admin variant of PASS. Contract: NOT auto-granted by
|
||||
the post_save signal (unlike PASS for staff, or COIN/FREE for everyone),
|
||||
so admin can hand-mint it for any user via the Django admin without
|
||||
every fresh account spawning one. No `is_staff` coupling — staff or
|
||||
non-staff can hold one — so no model-layer guard either."""
|
||||
|
||||
def test_band_not_auto_granted_on_user_creation(self):
|
||||
user = User.objects.create(email="newgamer@test.io")
|
||||
self.assertFalse(user.tokens.filter(token_type=Token.BAND).exists())
|
||||
|
||||
def test_band_not_auto_granted_on_staff_creation(self):
|
||||
"""Staff get PASS, not BAND, on creation. BAND is admin-awarded
|
||||
post-hoc to either staff or non-staff (no role-coupling like PASS)."""
|
||||
staff = User.objects.create(email="admin@test.io", is_staff=True)
|
||||
self.assertFalse(staff.tokens.filter(token_type=Token.BAND).exists())
|
||||
|
||||
def test_admin_can_award_band_to_non_staff(self):
|
||||
non_staff = User.objects.create(email="gamer@test.io")
|
||||
token = Token.objects.create(user=non_staff, token_type=Token.BAND)
|
||||
self.assertEqual(token.token_type, Token.BAND)
|
||||
|
||||
def test_admin_can_award_band_to_staff(self):
|
||||
staff = User.objects.create(email="admin@test.io", is_staff=True)
|
||||
token = Token.objects.create(user=staff, token_type=Token.BAND)
|
||||
self.assertEqual(token.token_type, Token.BAND)
|
||||
|
||||
def test_band_not_auto_equipped_after_award(self):
|
||||
"""Award diverges from PASS — admin-minted BAND lands in the wallet
|
||||
but the user must DON it manually (`equipped_trinket` stays at its
|
||||
post-signal default of COIN for non-staff)."""
|
||||
non_staff = User.objects.create(email="bro@test.io")
|
||||
coin = non_staff.tokens.get(token_type=Token.COIN)
|
||||
band = Token.objects.create(user=non_staff, token_type=Token.BAND)
|
||||
non_staff.refresh_from_db()
|
||||
self.assertEqual(non_staff.equipped_trinket, coin)
|
||||
self.assertNotEqual(non_staff.equipped_trinket, band)
|
||||
|
||||
|
||||
class EquippedDeckTest(TestCase):
|
||||
def test_new_user_gets_earthman_as_default_deck(self):
|
||||
from apps.epic.models import DeckVariant
|
||||
|
||||
@@ -56,6 +56,31 @@ class PassTokenTooltipTest(SimpleTestCase):
|
||||
self.assertIn("no expiry", self.token.tooltip_text())
|
||||
|
||||
|
||||
class BandTokenTooltipTest(SimpleTestCase):
|
||||
"""Wristband mirrors PASS's "Admit All Entry" / never-expires shape but
|
||||
is non-admin (no `is_staff` gate). Tooltip prose is the only place the
|
||||
two diverge — different title + shoptalk."""
|
||||
|
||||
def setUp(self):
|
||||
self.token = Token()
|
||||
self.token.token_type = Token.BAND
|
||||
self.token.expires_at = None
|
||||
self.token.next_ready_at = None
|
||||
|
||||
def test_tooltip_contains_name(self):
|
||||
self.assertIn("Wristband", self.token.tooltip_text())
|
||||
|
||||
def test_tooltip_contains_admit_all(self):
|
||||
self.assertIn("Admit All Entry", self.token.tooltip_text())
|
||||
|
||||
def test_tooltip_contains_shoptalk(self):
|
||||
self.assertIn("Unlimited free entry", self.token.tooltip_text())
|
||||
self.assertIn("BYOB", self.token.tooltip_text())
|
||||
|
||||
def test_tooltip_contains_no_expiry(self):
|
||||
self.assertIn("no expiry", self.token.tooltip_text())
|
||||
|
||||
|
||||
class CarteTooltipTest(SimpleTestCase):
|
||||
def setUp(self):
|
||||
self.token = Token()
|
||||
|
||||
Reference in New Issue
Block a user