auth: training notice at registration only, versioned; one train line per room
Login no longer shows the notice. Registration shows the ruled sentence with a
plain tick, and records {noticeVersion, acceptedAt} on submit (newcomers only;
a changed TRAINING_NOTICE_VERSION is a fresh acceptance). Each room carries one
line above the composer. The Discord sentence and "on this server" are gone.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4e2aeddb69
commit
e38ebda1c5
7 changed files with 134 additions and 32 deletions
51
src/app/utils/trainingNotice.test.ts
Normal file
51
src/app/utils/trainingNotice.test.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
TRAINING_NOTICE_TEXT,
|
||||
TRAINING_NOTICE_VERSION,
|
||||
getNoticeAcceptance,
|
||||
needsFreshAcceptance,
|
||||
recordNoticeAcceptance,
|
||||
} from './trainingNotice';
|
||||
|
||||
const memoryStorage = () => {
|
||||
const data = new Map<string, string>();
|
||||
return {
|
||||
getItem: (k: string) => data.get(k) ?? null,
|
||||
setItem: (k: string, v: string) => void data.set(k, v),
|
||||
};
|
||||
};
|
||||
|
||||
describe('training notice', () => {
|
||||
it('says exactly the ruled sentence and never mentions Discord', () => {
|
||||
expect(TRAINING_NOTICE_TEXT).toBe(
|
||||
"Everything said here may be used to train GameCult's AI stewards."
|
||||
);
|
||||
expect(TRAINING_NOTICE_TEXT.toLowerCase()).not.toContain('discord');
|
||||
});
|
||||
|
||||
it('records the current version and time on acceptance', () => {
|
||||
const storage = memoryStorage();
|
||||
recordNoticeAcceptance(storage, new Date('2026-11-06T20:00:00Z'));
|
||||
expect(getNoticeAcceptance(storage)).toEqual({
|
||||
noticeVersion: TRAINING_NOTICE_VERSION,
|
||||
acceptedAt: '2026-11-06T20:00:00.000Z',
|
||||
});
|
||||
expect(needsFreshAcceptance(storage)).toBe(false);
|
||||
});
|
||||
|
||||
it('asks again when the notice version changes', () => {
|
||||
const storage = memoryStorage();
|
||||
recordNoticeAcceptance(storage, new Date(), TRAINING_NOTICE_VERSION);
|
||||
expect(needsFreshAcceptance(storage, TRAINING_NOTICE_VERSION + 1)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not re-ask members who never registered here (no record)', () => {
|
||||
expect(needsFreshAcceptance(memoryStorage())).toBe(false);
|
||||
});
|
||||
|
||||
it('treats a corrupt record as none', () => {
|
||||
const storage = memoryStorage();
|
||||
storage.setItem('trainingNoticeAcceptance', '{nope');
|
||||
expect(getNoticeAcceptance(storage)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
43
src/app/utils/trainingNotice.ts
Normal file
43
src/app/utils/trainingNotice.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
export const TRAINING_NOTICE_TEXT =
|
||||
"Everything said here may be used to train GameCult's AI stewards.";
|
||||
|
||||
// Any change to the wording or scope is a new version, and a new version needs a fresh acceptance.
|
||||
export const TRAINING_NOTICE_VERSION = 1;
|
||||
|
||||
const ACCEPTANCE_KEY = 'trainingNoticeAcceptance';
|
||||
|
||||
export type NoticeAcceptance = { noticeVersion: number; acceptedAt: string };
|
||||
|
||||
type NoticeStorage = Pick<Storage, 'getItem' | 'setItem'>;
|
||||
|
||||
/** Written at registration only, so only newcomers have one; earlier members are never re-asked. */
|
||||
export const recordNoticeAcceptance = (
|
||||
storage: NoticeStorage,
|
||||
now: Date = new Date(),
|
||||
noticeVersion: number = TRAINING_NOTICE_VERSION
|
||||
): NoticeAcceptance => {
|
||||
const acceptance = { noticeVersion, acceptedAt: now.toISOString() };
|
||||
storage.setItem(ACCEPTANCE_KEY, JSON.stringify(acceptance));
|
||||
return acceptance;
|
||||
};
|
||||
|
||||
export const getNoticeAcceptance = (storage: NoticeStorage): NoticeAcceptance | undefined => {
|
||||
try {
|
||||
const parsed = JSON.parse(storage.getItem(ACCEPTANCE_KEY) ?? 'null');
|
||||
if (typeof parsed?.noticeVersion === 'number' && typeof parsed?.acceptedAt === 'string') {
|
||||
return parsed;
|
||||
}
|
||||
} catch {
|
||||
// unreadable record counts as none
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** True when a newcomer's recorded acceptance is for an older notice version and must be renewed. */
|
||||
export const needsFreshAcceptance = (
|
||||
storage: NoticeStorage,
|
||||
currentVersion: number = TRAINING_NOTICE_VERSION
|
||||
): boolean => {
|
||||
const accepted = getNoticeAcceptance(storage);
|
||||
return accepted !== undefined && accepted.noticeVersion !== currentVersion;
|
||||
};
|
||||
Loading…
Reference in a new issue