mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-01 05:39:09 +08:00
## Summary
The Patreon plugin maintains a synthetic `rewards[\"0\"]` tier ("All
Patrons") that catches every patron, including paying patrons whose
pledge doesn't map to any predefined tier. It's supposed to appear as
`\$0 - All Patrons` in the admin dropdown where group filters are
configured.
In affected campaigns, this option silently disappeared and was replaced
by `\$0 - Free` (Patreon's real default free tier, with its own numeric
id). Admins lost the ability to filter on "any patron".
### Root cause
`rewards[\"0\"] ||= {}` in `lib/campaign.rb` relied on Patreon's payload
having already populated `rewards[\"0\"][\"id\"] = \"0\"` via the
adapter's `parse_campaigns`. For campaigns where Patreon no longer
returns a reward keyed on `\"0\"` (e.g. when the campaign has a real
"Free" tier), the pseudo-tier ended up stored with only `title` and
`amount_cents` — no `id`.
The admin dropdown filters rewards client-side with `r.id >= 0` (in
`assets/javascripts/discourse/controllers/admin-plugins/patreon.js`).
Since `undefined >= 0` evaluates to `false`, "All Patrons" was dropped
from the options. Existing filter rules keyed on `\"0\"` continued to
work on the backend, but admins could no longer create or edit them.
### Fix
Assign `rewards[\"0\"][\"id\"] = \"0\"` explicitly so the pseudo-tier is
always selectable. Confirmed against a live v1 site:
`reward-users[\"0\"]` still tracked all 946 patrons, the backend state
was healthy, only the UI was broken. Applies equally to v1 and v2 since
the assignment runs adapter-agnostic.
Existing filter rules keyed on `\"0\"` keep working and start matching
again on the next sync — no data migration needed.
## Test plan
- [x] `bin/rspec plugins/discourse-patreon/spec/lib/campaign_spec.rb`
passes under both v1 and v2 shared examples, asserting `rewards[\"0\"]`
includes `id: \"0\"`
- [x] `bin/lint` clean
- [ ] On the affected site, run \`Patreon::Campaign.update!\` (or click
*Update Data*) and verify \`\$0 - All Patrons\` reappears in the admin
dropdown and can be assigned to a group
|
||
|---|---|---|
| .. | ||
| fixtures | ||
| integration | ||
| jobs | ||
| lib | ||
| requests | ||
| services/problem_check | ||
| system | ||
| spec_helper.rb | ||