Add notification preferences and alternate dues payment options

Notification preferences (migration 048):
- Per-member opt-out of muteable categories (bookings, classes, forms,
  admin alerts); billing is always-on. Opt-out model, default on.
- Dispatcher reads prefs and marks muted outbox rows 'skipped' instead
  of sending; pure isMuted logic, fail-open on a prefs lookup error.
- notification_preferences table (default-deny RLS); /me toggles and
  self-view via validated service-client actions.

Alternate dues payment methods (migration 049):
- Admin sets external pay-here URLs per platform (PayPal/Zeffy/Venmo)
  in /settings; members see active ones on /me and pay off-platform;
  the treasurer reconciles manually (platform pre-tagged). https-only.
- dues_payment_methods table (SELECT space member, write admin/board).

/me visual pass:
- Restore the chip/preset profile editor (skills/interests/willing-to/
  affiliations); promote ChipInput and presets to shared modules.
- Gate the Stripe pay-dues button on whether the space has Stripe
  configured; show external links or a contact-admin note otherwise.
This commit is contained in:
Moheeb Zara
2026-05-19 20:26:32 -07:00
parent addedfdb0f
commit ab8c22ae1d
29 changed files with 1281 additions and 124 deletions
+51
View File
@@ -0,0 +1,51 @@
import { describe, it, expect } from 'vitest'
import {
DUES_LINK_PLATFORMS,
DUES_PLATFORM_LABEL,
isDuesLinkPlatform,
isSafeDuesUrl,
} from '@/lib/dues-payments-logic'
describe('DUES_LINK_PLATFORMS', () => {
it('is the url-based subset, excluding cash and stripe', () => {
expect(DUES_LINK_PLATFORMS).toEqual(['paypal', 'zeffy', 'venmo'])
expect((DUES_LINK_PLATFORMS as readonly string[]).includes('cash')).toBe(false)
expect((DUES_LINK_PLATFORMS as readonly string[]).includes('stripe')).toBe(false)
})
it('has a label for every platform', () => {
for (const p of DUES_LINK_PLATFORMS) expect(DUES_PLATFORM_LABEL[p]).toBeTruthy()
})
})
describe('isDuesLinkPlatform', () => {
it('accepts the link platforms', () => {
expect(isDuesLinkPlatform('paypal')).toBe(true)
expect(isDuesLinkPlatform('venmo')).toBe(true)
})
it('rejects cash, stripe, and junk', () => {
expect(isDuesLinkPlatform('cash')).toBe(false)
expect(isDuesLinkPlatform('stripe')).toBe(false)
expect(isDuesLinkPlatform('bogus')).toBe(false)
})
})
describe('isSafeDuesUrl', () => {
it('accepts absolute https URLs', () => {
expect(isSafeDuesUrl('https://paypal.me/myspace')).toBe(true)
expect(isSafeDuesUrl('https://www.zeffy.com/en-US/donation-form/abc')).toBe(true)
})
it('rejects http (plaintext downgrade)', () => {
expect(isSafeDuesUrl('http://paypal.me/myspace')).toBe(false)
})
it('rejects javascript:, data:, and other schemes (XSS)', () => {
expect(isSafeDuesUrl('javascript:alert(1)')).toBe(false)
expect(isSafeDuesUrl('data:text/html,<script>')).toBe(false)
expect(isSafeDuesUrl('mailto:treasurer@space.org')).toBe(false)
})
it('rejects relative or unparseable input', () => {
expect(isSafeDuesUrl('/paypal')).toBe(false)
expect(isSafeDuesUrl('paypal.me/x')).toBe(false)
expect(isSafeDuesUrl('')).toBe(false)
})
})
@@ -0,0 +1,87 @@
import { describe, it, expect } from 'vitest'
import {
MUTEABLE_CATEGORIES,
TYPE_CATEGORY,
CATEGORY_META,
categoryForType,
isMuteableCategory,
isMuted,
} from '@/lib/notifications-prefs-logic'
describe('categoryForType', () => {
it('maps every dues type to billing', () => {
expect(categoryForType('dues_renewed')).toBe('billing')
expect(categoryForType('dues_payment_failed')).toBe('billing')
expect(categoryForType('dues_lapsed')).toBe('billing')
})
it('maps booking, class, and form types to their categories', () => {
expect(categoryForType('booking_confirmed')).toBe('bookings')
expect(categoryForType('booking_cancelled')).toBe('bookings')
expect(categoryForType('class_signup_registered')).toBe('classes')
expect(categoryForType('class_signup_waitlisted')).toBe('classes')
expect(categoryForType('class_signup_promoted')).toBe('classes')
expect(categoryForType('class_session_cancelled')).toBe('classes')
expect(categoryForType('form_submission_received')).toBe('forms')
expect(categoryForType('form_submission_admin')).toBe('admin_alerts')
})
it('returns null for an unmapped type', () => {
expect(categoryForType('something_new')).toBeNull()
})
})
describe('isMuteableCategory', () => {
it('billing is never muteable', () => {
expect(isMuteableCategory('billing')).toBe(false)
})
it('bookings, classes, forms, admin_alerts are muteable', () => {
for (const c of MUTEABLE_CATEGORIES) expect(isMuteableCategory(c)).toBe(true)
})
})
describe('isMuted', () => {
it('absent pref means enabled (opt-out default): not muted', () => {
expect(isMuted({}, 'booking_confirmed')).toBe(false)
})
it('explicitly disabled muteable category: muted', () => {
expect(isMuted({ bookings: false }, 'booking_confirmed')).toBe(true)
expect(isMuted({ classes: false }, 'class_signup_registered')).toBe(true)
expect(isMuted({ forms: false }, 'form_submission_received')).toBe(true)
expect(isMuted({ admin_alerts: false }, 'form_submission_admin')).toBe(true)
})
it('explicitly enabled: not muted', () => {
expect(isMuted({ bookings: true }, 'booking_confirmed')).toBe(false)
})
it('billing is never muted even if a stray pref tries to disable it', () => {
// billing is never written, but defend the dispatcher path regardless.
expect(isMuted({ billing: false } as never, 'dues_lapsed')).toBe(false)
expect(isMuted({ billing: false } as never, 'dues_payment_failed')).toBe(false)
expect(isMuted({}, 'dues_renewed')).toBe(false)
})
it('unmapped type is never muted (fail-open)', () => {
expect(isMuted({ bookings: false }, 'brand_new_event')).toBe(false)
})
it('a pref for one category does not affect another', () => {
expect(isMuted({ classes: false }, 'booking_confirmed')).toBe(false)
})
})
describe('CATEGORY_META', () => {
it('lists exactly the muteable categories, no billing', () => {
const cats = CATEGORY_META.map(m => m.category)
expect(cats).toEqual([...MUTEABLE_CATEGORIES])
expect(cats).not.toContain('billing')
})
it('every emitted type maps to a known category', () => {
for (const cat of Object.values(TYPE_CATEGORY)) {
expect(['billing', ...MUTEABLE_CATEGORIES]).toContain(cat)
}
})
})