Add gift cards as a preview account type #4294
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #4294"
general
weight: 0.35
nielseulink
Problem
Sure has no good place for store and gift cards. People park them under "Other assets", where a card's value can't go down as it is spent, there is nowhere to keep the code or PIN, and nothing reminds them before a card expires.
What this adds
A
GiftCardaccountable, behind preview features.Account#balance_typerecords this.- remaining amount, initial amount and amount spent
- format (physical or digital)
- expiry date, with "expires in N days" or "expired" badges
- a "Card details" disclosure with copy buttons for the code and PIN, and an open link for the redeem URL. The PIN is masked (
••••) until "Show" is clicked.- "Received on", which is used as the opening date
- initial amount; leave it empty for an unspent card
- format, expiry, card number or code, PIN and redeem link
- encrypted at rest when Active Record encryption is ready, including keys derived from
SECRET_KEY_BASE(sameEncryptablepolicy as other secrets). Without encryption keys, the form shows a warning that they will be stored unencrypted.- covered by
security:backfill_encryption(BACKFILL_MANIFEST, version 14)- filtered from request logs
- excluded from
as_json, which covers the family data export- not restored by the family data import
- shown only to the account owner and
full_controlshares.read_write(annotate-only) andread_onlyshares see the balance and expiry, not the credentials.- PIN kept out of the account page. The overview shows it masked; "Show" loads it into a Turbo frame from
GET /gift_cards/:id/credentials, with the same permission check andCache-Control: no-store. The card number stays visible, since it is what tells cards apart and is needed to use them.face_value, together with the currency the card was issued in. "Spent" isface_value − balance. A balance edit rewrites a manual account's opening valuation, so the initial amount is stored separately rather than read from that valuation.Changes to shared code
AccountableResource:- Account type on create and update:
createbuilds the controller's own type instead of the submittedaccountable_type, andupdateignores a submitted type. Without this, any account form could be used to create, or switch to, a gated type such asGiftCard.PropertiesControllergets the same treatment. Shared tests inAccountableResourceInterfaceTestcover every account controller.- A rejected create form now keeps the submitted opening date instead of resetting it.
Accountable::PREVIEW_TYPESandAccountable.types_for(user): the account picker and the import account-type mapping use these to hide preview types from users without preview features. The appearance settings useAccountable.group_types_for(user), which also includes the type of any account the user can access, so turning preview features off never hides an existing account's group. Saving the form keeps the saved selection of groups it didn't show.docs/llm-guides/architecture.md: the account type inventory now includesGiftCardand preview types.Screenshots
| Overview | New gift card |
|---|---|
| !Overview | !Form |
| Account picker (preview pill) | Sidebar |
|---|---|
| !Picker | !Sidebar |
Migration notes
One new migration,
CreateGiftCards(20261016120000). It creates thegift_cardstable:face_valueandface_value_currencyexpires_onandcard_format, with a check constraint for physical/digitaltextcolumns forcard_number,pinandredeem_urlsubtypeandlocked_attributesThe migration is additive.
GiftCardis added toActiveRecordEncryptionConfig::BACKFILL_MANIFESTandCURRENT_BACKFILL_VERSIONmoves from 13 to 14, so installs that completed an earlier backfill re-run it before the plaintext fallback is turned off.Limitations and decisions
SureImport) accept anyAccountable::TYPESvalue, so a hand-crafted request can still create a gift card in the user's own family. I kept that out of scope to keep the PR focused; it only affects visibility, not authorization.Account::CurrentBalanceManagerapplies a balance delta in the account's currency to an opening valuation still in the old currency. This affects every manual account and is not addressed here.step: "any", so the amount is not rounded to the precision of the currency it was rendered with. Instead, the model rounds it on save to the precision of the card's own currency.Validation
bin/rails test(after mergingmainon 2026-11-12): 15,834 runs. The gift card and encryption backfill failures from the merge are fixed. What remains fails the same way onmainlocally:SimplefinEntry::ProcessorTest,SimplefinItem::ImporterRotatedIdsTest,Settings::HostingsControllerTestandEval::Langfuse::ExperimentRunnerTest.test/system/accounts_test.rb, which includes the PIN show/hide flow, passes.bin/rubocop,erb_lint,npm run lint(Biome) andbin/brakemanare clean.i18n-tasks check-normalizedis clean for the new locale files.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Added support for physical and digital gift card accounts, including balances, expiry details, and redemption information.
Gift card overviews show remaining, initial, and spent amounts, plus expiry status; gift cards also include overview and activity tabs.
Users with preview features enabled can create gift cards, and credential visibility follows sharing permissions.
Gift cards can be imported and categorized alongside other account types.
Demo data now includes gift cards and related spending.
Bug Fixes
Account forms can no longer override the account type assigned by the app.
* Account-group selections not shown in appearance settings are preserved when settings are updated.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->