diff --git a/apps/api/src/services/moderation.ts b/apps/api/src/services/moderation.ts index 9a78a44..fccec0d 100644 --- a/apps/api/src/services/moderation.ts +++ b/apps/api/src/services/moderation.ts @@ -33,7 +33,7 @@ import { } from '@cfp/shared/schemas'; import { agentHasActiveGrant, isAgentAccount, isGrantActive } from '../auth/agent-grant.js'; import { agentTextProblem } from './agent-text.js'; -import { projectBySlug, type InMemoryState } from '../store/memory/state.js'; +import { eventBySlug, projectBySlug, type InMemoryState } from '../store/memory/state.js'; import type { PrivateStore } from '../store/private/interface.js'; import type { DualStoreTx } from '../store/store.js'; import { StateApply } from '../store/state-apply.js'; @@ -102,6 +102,8 @@ export interface FootprintCounts { readonly blogPosts: number; readonly helpWantedInterest: number; readonly tags: number; + /** Event RSVPs on record, past and upcoming events alike. */ + readonly rsvps: number; } export type MemberOrigin = 'imported' | 'signed-up'; @@ -160,6 +162,14 @@ export interface MemberFootprint { readonly blogPosts: Array<{ slug: string; title: string; postedAt: string }>; readonly helpWantedInterest: Array<{ project: ProjectRef; role: { title: string }; createdAt: string }>; readonly tags: Array<{ handle: string; type: string }>; + /** Event RSVPs, newest RSVP first (specs/api/moderation.md → GET /api/admin/members/:slug). */ + readonly rsvps: Array<{ event: EventRef; createdAt: string }>; +} + +export interface EventRef { + readonly slug: string; + readonly title: string; + readonly startsAt: string; } interface AuthoredCounts { @@ -552,6 +562,7 @@ export class ModerationService { blogPosts: authored.blogPosts.get(p.id) ?? 0, helpWantedInterest: authored.interest.get(p.slug) ?? 0, tags: this.#state.tagAssignmentsByTaggable.get(p.id)?.size ?? 0, + rsvps: this.#state.rsvpsByPerson.get(p.slug)?.size ?? 0, }; const email = profile?.email ?? null; const lastSlackSsoAt = profile?.lastSlackSsoAt ?? null; @@ -647,7 +658,18 @@ export class ModerationService { return tag ? [{ handle: `${tag.namespace}.${tag.slug}`, type: tag.namespace }] : []; }); - return { memberships, updates, buzz, blogPosts, helpWantedInterest, tags }; + // RSVPs reference the person by slug (event-rsvps/${year}/${eventSlug}/${personSlug}). + const rsvps = [...(s.rsvpsByPerson.get(slug) ?? [])] + .map((rid) => s.eventRsvps.get(rid)) + .flatMap((r) => { + const event = r ? eventBySlug(s, r.eventSlug) : undefined; + return r && event + ? [{ event: { slug: event.slug, title: event.title, startsAt: event.startsAt }, createdAt: r.createdAt }] + : []; + }) + .sort((a, b) => b.createdAt.localeCompare(a.createdAt)); + + return { memberships, updates, buzz, blogPosts, helpWantedInterest, tags, rsvps }; } #voteView(rec: PersonEvaluation): VoteView { diff --git a/apps/api/tests/moderation-rsvps.test.ts b/apps/api/tests/moderation-rsvps.test.ts new file mode 100644 index 0000000..c075698 --- /dev/null +++ b/apps/api/tests/moderation-rsvps.test.ts @@ -0,0 +1,206 @@ +/** + * Event RSVPs in the moderation footprint — specs/api/moderation.md → + * GET /api/admin/members (footprint.rsvps) and GET /api/admin/members/:slug + * (footprint.rsvps); issue #266. + * + * Covers: + * - the detail lists a member's RSVPs, newest first, past and cancelled events included + * - a member with no RSVPs gets an empty list, and another member's RSVP never shows + * - each item carries only the event's slug, title and startsAt, and createdAt + * - an agent caller with moderation:read sees the same list as staff + * - the roster row counts RSVPs, and RSVPs alone do not set `has-footprint` + * - a new RSVP shows on the roster and in the detail at once (in-memory index) + * + * Every name here is invented; none is a real member's. + */ +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; + +import { + bearer, + createAgent, + daysAgo, + fid, + personRecord, + privateProfile, + startAgentTestEnv, + type AgentTestEnv, + type Rec, +} from './helpers/agent-fixtures.js'; + +const ADMIN = 1; +const STAFF = 2; +const VOLUNTEER = 10; +const EMPTY = 11; +const OTHER = 12; +const LATE = 13; + +const DAY = 86_400_000; +const daysFromNow = (d: number): string => new Date(Date.now() + d * DAY).toISOString(); +const yearOf = (iso: string): string => String(new Date(iso).getUTCFullYear()); + +function event(n: number, slug: string, title: string, startsAt: string, over: Rec = {}): Rec { + const endsAt = new Date(Date.parse(startsAt) + 2 * 60 * 60 * 1000).toISOString(); + return { + id: fid(n), + slug, + title, + startsAt, + endsAt, + status: 'scheduled', + icsSequence: 0, + createdAt: daysAgo(90), + updatedAt: daysAgo(90), + ...over, + }; +} + +function rsvp(n: number, ev: Rec, personSlug: string, createdAt: string, over: Rec = {}): Rec { + return { + id: fid(n), + year: yearOf(ev['startsAt'] as string), + eventSlug: ev['slug'], + personSlug, + createdAt, + updatedAt: createdAt, + ...over, + }; +} + +interface RsvpItem { + event: { slug: string; title: string; startsAt: string }; + createdAt: string; +} +interface Row { + slug: string; + footprint: Record; + signals: string[]; +} +interface Detail { + footprint: { rsvps: RsvpItem[] } & Record; +} + +describe('moderation footprint: event RSVPs', () => { + let env: AgentTestEnv; + let staff: string; + let reader: { token: string }; + + const past = event(100, 'june-hack-night', 'June Hack Night', '2025-06-10T22:00:00.000Z'); + const cancelled = event(101, 'cancelled-workshop', 'Cancelled Workshop', '2025-09-15T22:00:00.000Z', { + status: 'cancelled', + cancelledAt: '2025-09-01T00:00:00.000Z', + }); + const upcoming = event(102, 'next-hack-night', 'Next Hack Night', daysFromNow(7)); + const later = event(103, 'later-hack-night', 'Later Hack Night', daysFromNow(14)); + const upcomingRsvpAt = daysAgo(3); + + beforeAll(async () => { + env = await startAgentTestEnv({ + records: { + people: [ + personRecord(ADMIN, 'boss', { accountLevel: 'administrator' }), + personRecord(STAFF, 'staffer', { accountLevel: 'staff' }), + personRecord(VOLUNTEER, 'quiet-volunteer', { createdAt: daysAgo(20), bio: 'Here for hack nights.' }), + personRecord(EMPTY, 'empty-account', { createdAt: daysAgo(2) }), + personRecord(OTHER, 'other-member', { createdAt: daysAgo(300) }), + personRecord(LATE, 'late-rsvper', { createdAt: daysAgo(1) }), + ], + events: [past, cancelled, upcoming, later], + 'event-rsvps': [ + rsvp(200, past, 'quiet-volunteer', '2025-06-01T12:00:00.000Z', { plan: 'newcomer' }), + rsvp(201, cancelled, 'quiet-volunteer', '2025-08-20T12:00:00.000Z'), + rsvp(202, upcoming, 'quiet-volunteer', upcomingRsvpAt), + rsvp(203, upcoming, 'other-member', daysAgo(4)), + ], + }, + profiles: [privateProfile(fid(VOLUNTEER), 'quiet.volunteer@example.org')], + }); + const admin = await env.cookie(ADMIN, 'administrator'); + staff = await env.cookie(STAFF, 'staff'); + reader = await createAgent(env, admin, { slug: 'reader-bot', scopes: ['moderation:read'] }); + }, 90_000); + + afterAll(async () => { + await env.close(); + }); + + const asStaff = (): Record => ({ cookies: { cfp_session: staff } }); + + const detail = async (slug: string, auth: Record = asStaff()): Promise => { + const res = await env.app.inject({ method: 'GET', url: `/api/admin/members/${slug}`, ...auth }); + expect(res.statusCode, res.body).toBe(200); + return res.json<{ data: Detail }>().data; + }; + + const roster = async (auth: Record = asStaff()): Promise => { + const res = await env.app.inject({ method: 'GET', url: '/api/admin/members?perPage=200', ...auth }); + expect(res.statusCode, res.body).toBe(200); + return res.json<{ data: Row[] }>().data; + }; + + it('lists a member\'s RSVPs newest first, past and cancelled events included', async () => { + const d = await detail('quiet-volunteer'); + expect(d.footprint.rsvps).toEqual([ + { event: { slug: 'next-hack-night', title: 'Next Hack Night', startsAt: upcoming['startsAt'] }, createdAt: upcomingRsvpAt }, + { event: { slug: 'cancelled-workshop', title: 'Cancelled Workshop', startsAt: '2025-09-15T22:00:00.000Z' }, createdAt: '2025-08-20T12:00:00.000Z' }, + { event: { slug: 'june-hack-night', title: 'June Hack Night', startsAt: '2025-06-10T22:00:00.000Z' }, createdAt: '2025-06-01T12:00:00.000Z' }, + ]); + }); + + it('carries only the event reference and when the RSVP was made', async () => { + const d = await detail('quiet-volunteer'); + for (const item of d.footprint.rsvps) { + expect(Object.keys(item).sort()).toEqual(['createdAt', 'event']); + expect(Object.keys(item.event).sort()).toEqual(['slug', 'startsAt', 'title']); + } + // The follow-up answer and the RSVP id stay out of it. + const body = JSON.stringify(d.footprint.rsvps); + expect(body).not.toContain('newcomer'); + expect(body).not.toContain(fid(200)); + }); + + it('gives a member with no RSVPs an empty list, and never shows another member\'s RSVP', async () => { + expect((await detail('empty-account')).footprint.rsvps).toEqual([]); + const other = await detail('other-member'); + expect(other.footprint.rsvps.map((r) => r.event.slug)).toEqual(['next-hack-night']); + }); + + it('shows an agent caller with moderation:read the same RSVPs as staff, without the email', async () => { + const asAgent = await detail('quiet-volunteer', bearer(reader.token)); + const asStaffMember = await detail('quiet-volunteer'); + expect(asAgent.footprint.rsvps).toEqual(asStaffMember.footprint.rsvps); + expect(JSON.stringify(asAgent)).not.toContain('quiet.volunteer@example.org'); + + const agentRow = (await roster(bearer(reader.token))).find((r) => r.slug === 'quiet-volunteer')!; + expect(agentRow.footprint['rsvps']).toBe(3); + }); + + it('counts RSVPs on the roster row; RSVPs alone do not set has-footprint', async () => { + const rows = await roster(); + const bySlug = new Map(rows.map((r) => [r.slug, r])); + expect(bySlug.get('quiet-volunteer')!.footprint['rsvps']).toBe(3); + expect(bySlug.get('other-member')!.footprint['rsvps']).toBe(1); + expect(bySlug.get('empty-account')!.footprint['rsvps']).toBe(0); + expect(bySlug.get('quiet-volunteer')!.signals).not.toContain('has-footprint'); + }); + + it('shows a new RSVP on the roster and in the detail at once', async () => { + const lateCookie = await env.cookie(LATE, 'user'); + const before = (await roster()).find((r) => r.slug === 'late-rsvper')!; + expect(before.footprint['rsvps']).toBe(0); + + const put = await env.app.inject({ + method: 'PUT', + url: '/api/events/later-hack-night/rsvp', + cookies: { cfp_session: lateCookie }, + }); + expect(put.statusCode, put.body).toBeLessThan(300); + + const after = (await roster()).find((r) => r.slug === 'late-rsvper')!; + expect(after.footprint['rsvps']).toBe(1); + const d = await detail('late-rsvper'); + expect(d.footprint.rsvps.map((r) => r.event)).toEqual([ + { slug: 'later-hack-night', title: 'Later Hack Night', startsAt: later['startsAt'] }, + ]); + }); +}); + diff --git a/apps/api/tests/moderation-signals.test.ts b/apps/api/tests/moderation-signals.test.ts index c6e3d7b..c94ef4e 100644 --- a/apps/api/tests/moderation-signals.test.ts +++ b/apps/api/tests/moderation-signals.test.ts @@ -51,7 +51,7 @@ function profile(personId: string, extra: Partial = {}): Private }; } -const NO_FOOTPRINT = { memberships: 0, updates: 0, buzz: 0, blogPosts: 0, helpWantedInterest: 0, tags: 0 }; +const NO_FOOTPRINT = { memberships: 0, updates: 0, buzz: 0, blogPosts: 0, helpWantedInterest: 0, tags: 0, rsvps: 0 }; describe('emailMatchesName', () => { it('matches when the local part contains a name token', () => { @@ -102,6 +102,21 @@ describe('computeSignals', () => { expect(established.attention).toBe(0); }); + it('does not count RSVPs (or tags) toward has-footprint', () => { + // specs/api/moderation.md → signals: an RSVP is shown, not scored (issue #266). + const r = computeSignals({ + person: person({ id: '01951a3c-0000-7000-8000-000000000104', slug: 'rsvp-only', bio: 'hi', avatarKey: 'x' }), + email: 'rsvp-only@example.org', + signInCount: 1, + github: null, + emailBounce: null, + lastSlackSsoAt: null, + footprint: { ...NO_FOOTPRINT, rsvps: 2, tags: 1 }, + }); + expect(r.signals).not.toContain('has-footprint'); + expect(r.attention).toBe(0); + }); + it('flags gone, new, and inactive GitHub accounts and bounced email', () => { const r = computeSignals({ person: person({ id: '01951a3c-0000-7000-8000-000000000103', slug: 'newgh', bio: 'hi', avatarKey: 'x' }), diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 5013485..f861973 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -820,6 +820,8 @@ export interface MemberRow { readonly blogPosts: number; readonly helpWantedInterest: number; readonly tags: number; + /** Event RSVPs on record, past and upcoming events alike. */ + readonly rsvps: number; }; readonly latestVote: VoteView | null; readonly stagedVote?: StagedVoteView | null; @@ -855,6 +857,8 @@ export interface MemberFootprint { readonly blogPosts: Array<{ slug: string; title: string; postedAt: string }>; readonly helpWantedInterest: Array<{ project: ProjectRef; role: { title: string }; createdAt: string }>; readonly tags: Array<{ handle: string; type: string }>; + /** Event RSVPs, newest RSVP first. */ + readonly rsvps: Array<{ event: { slug: string; title: string; startsAt: string }; createdAt: string }>; } export interface MemberDetail { diff --git a/apps/web/src/pages/AdminMembers.tsx b/apps/web/src/pages/AdminMembers.tsx index c91c50b..aee5f3d 100644 --- a/apps/web/src/pages/AdminMembers.tsx +++ b/apps/web/src/pages/AdminMembers.tsx @@ -333,6 +333,7 @@ function MemberRowView({ fp.buzz ? `${fp.buzz} buzz` : null, fp.blogPosts ? `${fp.blogPosts} post${fp.blogPosts === 1 ? '' : 's'}` : null, fp.helpWantedInterest ? `${fp.helpWantedInterest} help-wanted` : null, + fp.rsvps ? `${fp.rsvps} RSVP${fp.rsvps === 1 ? '' : 's'}` : null, `${fp.tags} tag${fp.tags === 1 ? '' : 's'}`, ].filter(Boolean); const signIns = @@ -484,6 +485,14 @@ function MemberDetailView({ slug }: { slug: string }) {
  • {i.role.title} on {i.project.title}, {formatAbsoluteDate(i.createdAt)}
  • )), )} + {section( + 'Event RSVPs', + footprint.rsvps.map((r) => ( +
  • + {r.event.title}, {formatAbsoluteDate(r.event.startsAt)} — RSVP'd {formatAbsoluteDate(r.createdAt)} +
  • + )), + )} {footprint.tags.length > 0 && (

    Tags

    diff --git a/apps/web/tests/AdminMembers.test.tsx b/apps/web/tests/AdminMembers.test.tsx new file mode 100644 index 0000000..d5716ff --- /dev/null +++ b/apps/web/tests/AdminMembers.test.tsx @@ -0,0 +1,150 @@ +/** + * /admin/members — event RSVPs in the roster row and the detail panel + * (specs/screens/admin-members.md; issue #266). + * + * Every name here is invented; none is a real member's. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { screen, within } from '@testing-library/react'; +import { Route, Routes } from 'react-router'; +import { mockOk, mockPaginated, renderScreen } from './test-utils.js'; +import { AdminMembers } from '../src/pages/AdminMembers.js'; +import { AuthProvider } from '../src/hooks/useAuth.js'; +import type { MemberDetail, MemberRow } from '../src/lib/api.js'; +import { STAFF_ME, json } from './event-fixtures.js'; + +const NO_FOOTPRINT: MemberRow['footprint'] = { + memberships: 0, + updates: 0, + buzz: 0, + blogPosts: 0, + helpWantedInterest: 0, + tags: 0, + rsvps: 0, +}; + +function makeRow(over: Partial = {}): MemberRow { + return { + id: `id-${over.slug ?? 'member'}`, + slug: 'member', + fullName: 'Test Member', + avatarUrl: null, + createdAt: '2026-11-10T12:00:00Z', + deletedAt: null, + origin: 'signed-up', + email: null, + emailDomain: null, + hasGitHubLink: false, + github: null, + lastLoginAt: null, + signInCount: 1, + lastSlackSsoAt: null, + emailBounce: null, + bioExcerpt: '', + footprint: NO_FOOTPRINT, + latestVote: null, + stagedVote: null, + purgeAfter: null, + signals: [], + attention: 0, + ...over, + }; +} + +function makeDetail(rsvps: MemberDetail['footprint']['rsvps']): MemberDetail { + return { + person: { slug: 'quiet-volunteer', fullName: 'Quiet Volunteer', bioHtml: '' } as unknown as MemberDetail['person'], + footprint: { memberships: [], updates: [], buzz: [], blogPosts: [], helpWantedInterest: [], tags: [], rsvps }, + votes: [], + earlierVotes: [], + earlierPurges: [], + }; +} + +function mockFetch(opts: { rows: MemberRow[]; details?: Record }) { + vi.spyOn(globalThis, 'fetch').mockImplementation(((input: string) => { + if (input.startsWith('/api/auth/me')) return json(STAFF_ME); + if (input.startsWith('/api/admin/members?') || input === '/api/admin/members') { + return json(mockPaginated(opts.rows, { perPage: 50 })); + } + const m = /^\/api\/admin\/members\/([^/?]+)$/.exec(input); + if (m) { + const d = opts.details?.[decodeURIComponent(m[1]!)]; + return d ? json(mockOk(d)) : json({ success: false, error: { code: 'not_found', message: 'Not found' } }, 404); + } + // The recent agent purges banner and anything else the page asks for: empty. + if (input.startsWith('/api/admin/')) return json(mockPaginated([])); + return json({ success: false, error: { code: 'not_found', message: 'Not found' } }, 404); + }) as typeof fetch); +} + +function render(path = '/admin/members') { + return renderScreen( + + + } /> + } /> + + , + { initialEntries: [path] }, + ); +} + +describe('AdminMembers: event RSVPs', () => { + // The detail route selects its row, which scrolls it into view; jsdom has no layout. + beforeEach(() => { + Element.prototype.scrollIntoView = vi.fn(); + }); + afterEach(() => vi.restoreAllMocks()); + + it('shows an RSVP count on the roster row only when the member has RSVPs', async () => { + mockFetch({ + rows: [ + makeRow({ slug: 'quiet-volunteer', fullName: 'Quiet Volunteer', footprint: { ...NO_FOOTPRINT, rsvps: 3 } }), + makeRow({ slug: 'one-rsvp', fullName: 'One Rsvp', footprint: { ...NO_FOOTPRINT, rsvps: 1, tags: 2 } }), + makeRow({ slug: 'empty-account', fullName: 'Empty Account' }), + ], + }); + render(); + + const rowOf = async (name: string) => (await screen.findByRole('link', { name })).closest('li')!; + expect(within(await rowOf('Quiet Volunteer')).getByText('0 projects · 3 RSVPs · 0 tags')).toBeInTheDocument(); + expect(within(await rowOf('One Rsvp')).getByText('0 projects · 1 RSVP · 2 tags')).toBeInTheDocument(); + const empty = await rowOf('Empty Account'); + expect(within(empty).getByText('0 projects · 0 tags')).toBeInTheDocument(); + expect(within(empty).queryByText(/RSVP/)).not.toBeInTheDocument(); + }); + + it('lists the RSVPs in the detail panel, past events included, each linking to its event', async () => { + mockFetch({ + rows: [makeRow({ slug: 'quiet-volunteer', fullName: 'Quiet Volunteer', footprint: { ...NO_FOOTPRINT, rsvps: 2 } })], + details: { + 'quiet-volunteer': makeDetail([ + { event: { slug: 'next-hack-night', title: 'Next Hack Night', startsAt: '2026-11-24T23:00:00Z' }, createdAt: '2026-11-14T12:00:00Z' }, + { event: { slug: 'june-hack-night', title: 'June Hack Night', startsAt: '2025-06-10T11:00:00Z' }, createdAt: '2025-06-01T11:00:00Z' }, + ]), + }, + }); + render('/admin/members/quiet-volunteer'); + + const heading = await screen.findByRole('heading', { name: 'Event RSVPs' }); + const list = within(heading.parentElement!).getByRole('list'); + const items = within(list).getAllByRole('listitem'); + expect(items).toHaveLength(2); + expect(within(items[0]!).getByRole('link', { name: 'Next Hack Night' })).toHaveAttribute('href', '/events/next-hack-night'); + expect(within(items[1]!).getByRole('link', { name: 'June Hack Night' })).toHaveAttribute('href', '/events/june-hack-night'); + expect(items[1]!).toHaveTextContent(/June 10, 2025/); + expect(items[1]!).toHaveTextContent(/RSVP'd June 1, 2025/); + }); + + it('leaves the RSVP section out when the member has none', async () => { + mockFetch({ + rows: [makeRow({ slug: 'quiet-volunteer', fullName: 'Quiet Volunteer' })], + details: { 'quiet-volunteer': makeDetail([]) }, + }); + render('/admin/members/quiet-volunteer'); + + expect(await screen.findByText('No votes yet.')).toBeInTheDocument(); + expect(screen.queryByRole('heading', { name: 'Event RSVPs' })).not.toBeInTheDocument(); + }); +}); diff --git a/plans/moderation-footprint-rsvps.md b/plans/moderation-footprint-rsvps.md new file mode 100644 index 0000000..78e47c4 --- /dev/null +++ b/plans/moderation-footprint-rsvps.md @@ -0,0 +1,119 @@ +--- +status: done +depends: [admin-members-moderation, events-core] +specs: + - specs/api/moderation.md + - specs/screens/admin-members.md + - specs/behaviors/person-lifecycle.md + - specs/behaviors/spam-exclusion.md +issues: [266] +pr: 267 +--- + +# Plan: Event RSVPs in the moderation footprint + +## Scope + +Issue [#266](https://github.com/CodeForPhilly/codeforphilly-ng/issues/266): +staff reviewing new accounts on `/admin/members` see a member's memberships, +updates, buzz, blog posts, help-wanted interest and tags, but not their event +RSVPs. An RSVP to a hack night can be the only sign that an otherwise empty +new account is a real volunteer, and a purge deletes the RSVP with the +account, so staff should see it before they vote. + +**In:** + +- `rsvps` in the detail footprint of `GET /api/admin/members/:slug`: per RSVP, + the event's `slug`, `title` and `startsAt`, and the RSVP's `createdAt`; + newest RSVP first; past and cancelled events included; agent callers with + `moderation:read` see the same list. +- `rsvps` in the roster row's `footprint` counts (`GET /api/admin/members`). +- `/admin/members`: an `{n} RSVP(s)` count on the row (only when non-zero, like + updates and buzz) and an **Event RSVPs** list in the detail panel. +- Spec lines that were missing for existing behavior: the purge cascade and + the offline prune both already delete the person's `event-rsvps`, but + `person-lifecycle.md` and `spam-exclusion.md` did not say so. + +**Out:** + +- Spam scoring: RSVPs do not count toward `has-footprint` or `attention`, the + roster's default review filter is unchanged, and the agent vote and purge + rules are unchanged. The spec now says so explicitly for `has-footprint`. +- Purge behavior (unchanged; it already deletes RSVPs). +- The offline batch cleanup (#265). +- Any data-repo sheet contract: this is a response-shape change only. + +## Implements + +- [api/moderation.md](../specs/api/moderation.md) — `footprint.rsvps` on the + roster row and the detail; the `has-footprint` definition. +- [screens/admin-members.md](../specs/screens/admin-members.md) — the row's + count and the detail's Event RSVPs list. +- [behaviors/person-lifecycle.md](../specs/behaviors/person-lifecycle.md) and + [behaviors/spam-exclusion.md](../specs/behaviors/spam-exclusion.md) — the + purge and prune cascades name `event-rsvps` (documenting what the code does). + +## Approach + +1. Specs first (above). +2. `services/moderation.ts`: `FootprintCounts.rsvps` from the existing + `rsvpsByPerson` index (`Map>`, already documented in + `data-model.md#eventrsvp`); `MemberFootprint.rsvps` resolves each RSVP's + event through `eventBySlug` and drops an RSVP whose event is not in memory, + the way the other lists drop a missing project. No new index; no route + change (the route already spreads the footprint). +3. Web: the `MemberRow` / `MemberFootprint` types in `lib/api.ts`; the row's + count and the detail's section in `AdminMembers.tsx`, using the page's + existing `section()` helper and `formatAbsoluteDate`. +4. Tests: API detail and roster (`moderation-rsvps.test.ts`), the signal rule + (`moderation-signals.test.ts`), and the first component test for the page + (`apps/web/tests/AdminMembers.test.tsx`). + +## Validation + +- [x] `npm run type-check && npm run lint && npm test` clean. +- [x] Detail: a member with RSVPs lists them newest first, a past event and a + cancelled event included; each item is exactly `{ event: { slug, title, + startsAt }, createdAt }` (no `plan`, `projectId` or id). +- [x] Detail: a member with no RSVPs gets `[]`; another member's RSVP to the + same event never shows. +- [x] An agent with `moderation:read` sees the same `rsvps` as staff, and no + email anywhere in the response. +- [x] Roster: `footprint.rsvps` counts each member's RSVPs, for staff and agent + callers; RSVPs alone do not set `has-footprint`. +- [x] A new RSVP (`PUT /api/events/:slug/rsvp`) shows on the roster count and + in the detail at once. +- [x] Web: the row shows `3 RSVPs` / `1 RSVP` and nothing for zero; the detail + lists Event RSVPs linking to `/events/` with the event date and when + they RSVP'd; no section when there are none. +- [x] No sheet contract changed: `packages/shared` and `contracts/` untouched; + `npm run -w packages/shared check-contracts` clean. + +## Risks / unknowns + +- None of note. The per-row count is an index lookup, so the roster's cost is + unchanged; the detail walks only the member's own RSVPs. + +## Notes + +- The purge cascade already deletes RSVPs: + `apps/api/src/services/person-purge.ts` → `purgePersonRecords` (step "3b", + through `rsvpsByPerson`), covered by `apps/api/tests/events.test.ts` → + "person purge removes the purged person's RSVPs". The offline prune + (`apps/api/scripts/prune-spam.ts`) deletes them too (`eventRsvpsDeleted`). +- RSVPs reference the person by slug (`event-rsvps/${year}/${eventSlug}/${personSlug}`), + so the lookup is by slug, like help-wanted interest and memberships. +- Dates in the detail are shown in the viewer's local zone, like the other + footprint dates on the page, not the event's `America/New_York` wall clock. +- Not browser-tested on the devbox; the component test covers the row and the + detail panel. + +## Follow-ups + +- Tracked as: issue #266's question of whether an RSVP should count as a "not + spam" signal in the roster's default review view (e.g. toward + `has-footprint`, or a positive signal of its own). Left out on purpose; a + spec decision for the operators. +- Tracked as: issue #265 (offline batch cleanup) should count an RSVP as a + contribution, or at least never remove an account with one automatically. + Belongs to that issue's plan. diff --git a/specs/api/moderation.md b/specs/api/moderation.md index 4151d85..143563b 100644 --- a/specs/api/moderation.md +++ b/specs/api/moderation.md @@ -93,7 +93,7 @@ vote nobody had cast on it.) "lastSlackSsoAt": "2026-09-18T01:15:00Z", "emailBounce": null, "bioExcerpt": "first ~160 chars of bio, markdown stripped", - "footprint": { "memberships": 2, "updates": 1, "buzz": 0, "blogPosts": 0, "helpWantedInterest": 1, "tags": 3 }, + "footprint": { "memberships": 2, "updates": 1, "buzz": 0, "blogPosts": 0, "helpWantedInterest": 1, "tags": 3, "rsvps": 1 }, "latestVote": { "verdict": "legit", "voter": { "slug": "chris", "fullName": "Chris Alfano" }, "evaluatedAt": "…" }, "stagedVote": null, "purgeAfter": null, @@ -124,7 +124,12 @@ Field notes: `github-new-account` (< 30 days), `github-no-activity` (0 repos and 0 followers), `slug-purged-before` (a [`spam-purges`](../data-model.md#spampurge) record names this slug: an earlier account under it was purged as spam). - Informational: `slack-sso`, `has-footprint`. + Informational: `slack-sso`, `has-footprint` (any membership, update, buzz + item, blog post or help-wanted interest; tags and RSVPs do not count toward + it). +- `footprint` counts the member's records of each kind in the detail's + `footprint` lists below; `rsvps` counts every event RSVP on record for the + member, past and upcoming events alike. `purgeAfter` is when the [scheduled spam purge](../behaviors/person-lifecycle.md#scheduled-spam-purge) will take the member — three days after the newest **deciding** vote, when every deciding vote is `spam` and the member is still deactivated and not staff — or `null`. The deciding votes are the human votes; when there are none, the votes of agents that still hold an active grant. @@ -166,7 +171,8 @@ The row above, plus the full footprint and vote history: "buzz": [ { "project": { "slug", "title" }, "slug", "title", "postedAt" } ], "blogPosts": [ { "slug", "title", "postedAt" } ], "helpWantedInterest": [ { "project": { "slug", "title" }, "role": { "title" }, "createdAt" } ], - "tags": [ { "handle", "type" } ] + "tags": [ { "handle", "type" } ], + "rsvps": [ { "event": { "slug", "title", "startsAt" }, "createdAt" } ] }, "votes": [ { "kind": "human", "verdict": "spam", "reasoning": "…", "flags": ["manual-override"], "voter": { "slug", "fullName" }, "evaluatedAt": "…" }, @@ -178,6 +184,14 @@ The row above, plus the full footprint and vote history: } ``` +`rsvps` lists the member's [event RSVPs](../data-model.md#eventrsvp) (looked +up by the RSVP's `personSlug`), newest RSVP first: the event's `slug`, `title` +and `startsAt`, and `createdAt`, when the member RSVP'd. Every RSVP on record is +listed, whether the event is upcoming, past or cancelled; an RSVP is often the +only thing a new volunteer has done on the site. The follow-up answer (`plan`, +`projectId`) is not included. RSVPs are public records, so an agent caller sees +the same list. + `votes` is newest first, human and agent votes together; `kind` tells them apart (from the `evaluator` prefix — [spam-exclusion.md](../behaviors/spam-exclusion.md#where-verdicts-come-from)). `earlierVotes` (same shape) are votes on an earlier account under this slug, diff --git a/specs/behaviors/person-lifecycle.md b/specs/behaviors/person-lifecycle.md index 3cab005..93ff666 100644 --- a/specs/behaviors/person-lifecycle.md +++ b/specs/behaviors/person-lifecycle.md @@ -25,7 +25,7 @@ The privacy / self-removal path — members should be able to remove themselves; The garbage-collection path for spam — the runtime sibling of the offline spam-prune (behaviors/spam-exclusion.md). - **Who:** administrators; the [scheduled spam purge](#scheduled-spam-purge); and, for a new member who posted spam only, an agent holding `moderation:purge` ([Agent purge](#agent-purge)). (The heading keeps its old name so links to it hold.) -- **Mechanism:** one write-mutex transaction that hard-deletes: the `people` record; their `project-membership`; their `help-wanted-interest`; their person `tag-assignment`; AND their authored `project-update`, `project-buzz`, and `blog-post` records (unlike the prune which nulls authorId — purge DELETES the content, it's garbage). Their **private** data goes in the same transaction: private profile, legacy password credential, password-reset tokens, account-claim requests naming them, and their session metadata. A purged person leaves nothing behind in either store. +- **Mechanism:** one write-mutex transaction that hard-deletes: the `people` record; their `project-membership`; their `help-wanted-interest`; their `event-rsvps`; their person `tag-assignment`; AND their authored `project-update`, `project-buzz`, and `blog-post` records (unlike the prune which nulls authorId — purge DELETES the content, it's garbage). Their **private** data goes in the same transaction: private profile, legacy password credential, password-reset tokens, account-claim requests naming them, and their session metadata. A purged person leaves nothing behind in either store. - **Projects only they touched go too.** In the same transaction, purge hard-deletes every project the person created that nobody else has touched — spam accounts create spam projects, and a project left behind with no members is a soft-deleted husk an admin can't clear. A project qualifies when both hold: 1. **Created by the person:** `createdById` is the person; for a project with no `createdById` (imported from laddr, or created before the field existed), the person is its `maintainerId`. 2. **No one else touched it:** every membership is the person's, every update was authored by them, every buzz posted by them, every help-wanted role posted by them with no interest from anyone else, and no RSVP from anyone else names the project. diff --git a/specs/behaviors/spam-exclusion.md b/specs/behaviors/spam-exclusion.md index bdff65b..70a6abe 100644 --- a/specs/behaviors/spam-exclusion.md +++ b/specs/behaviors/spam-exclusion.md @@ -123,6 +123,7 @@ Applied to `published`, re-runnably. For each pruned person: 2. Cascade-delete records that belong to that person: - `project-membership` where `personId` matches - `help-wanted-interest` where `personId` matches + - `event-rsvps` where `personSlug` matches - `tag-assignment` where `taggableType = "person"` and the taggable is that person 3. Unlink (do **not** delete) `project-update` records whose `authorId` is the pruned person: set `authorId = null` so project history is preserved with an diff --git a/specs/screens/admin-members.md b/specs/screens/admin-members.md index ab97544..3c84891 100644 --- a/specs/screens/admin-members.md +++ b/specs/screens/admin-members.md @@ -61,7 +61,8 @@ See [api/moderation.md](../api/moderation.md). (`signed in 4× · last 2h ago` or `never signed in`), email (staff-visible; the domain is a button that searches `@domain` across the whole roster, so one throwaway address leads to every account from that domain), - bio excerpt, compact footprint counts (`2 projects · 1 update · 3 tags`), and + bio excerpt, compact footprint counts (`2 projects · 1 update · 1 RSVP · 3 tags`; + updates, buzz, posts, help-wanted interest and RSVPs only when non-zero), and the vote state: - no vote → two buttons **Spam** / **Not spam** - voted → a badge `Spam · by {voter} · {when}` or `Not spam · …` with a @@ -103,7 +104,8 @@ See [api/moderation.md](../api/moderation.md). Full bio (rendered markdown, server-side), then the footprint as lists with links: project memberships (role, joined), authored updates, buzz, blog posts, -help-wanted interest, tags. Then the vote history, newest first, each with +help-wanted interest, event RSVPs (the event linked, its date, and when they +RSVP'd; past events included), tags. Then the vote history, newest first, each with voter, verdict, reasoning, and time; an agent's vote is marked "AI agent" and shows its flags, and once a human has voted the agent's votes read "overruled" or "confirmed". When the slug was used before, an **Earlier account** block