Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions apps/api/src/services/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand 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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
206 changes: 206 additions & 0 deletions apps/api/tests/moderation-rsvps.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, number>;
signals: string[];
}
interface Detail {
footprint: { rsvps: RsvpItem[] } & Record<string, unknown>;
}

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<string, unknown> => ({ cookies: { cfp_session: staff } });

const detail = async (slug: string, auth: Record<string, unknown> = asStaff()): Promise<Detail> => {
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<string, unknown> = asStaff()): Promise<Row[]> => {
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'] },
]);
});
});

17 changes: 16 additions & 1 deletion apps/api/tests/moderation-signals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function profile(personId: string, extra: Partial<PrivateProfile> = {}): 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', () => {
Expand Down Expand Up @@ -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' }),
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/pages/AdminMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -484,6 +485,14 @@ function MemberDetailView({ slug }: { slug: string }) {
<li key={idx}>{i.role.title} on {i.project.title}, {formatAbsoluteDate(i.createdAt)}</li>
)),
)}
{section(
'Event RSVPs',
footprint.rsvps.map((r) => (
<li key={r.event.slug}>
<Link to={`/events/${r.event.slug}`} className="hover:underline">{r.event.title}</Link>, {formatAbsoluteDate(r.event.startsAt)} — RSVP'd {formatAbsoluteDate(r.createdAt)}
</li>
)),
)}
{footprint.tags.length > 0 && (
<div>
<h3 className="text-sm font-semibold">Tags</h3>
Expand Down
Loading
Loading