diff --git a/.changeset/37182-checklist-not-shown-memo.md b/.changeset/37182-checklist-not-shown-memo.md new file mode 100644 index 00000000000..87cd6310bc9 --- /dev/null +++ b/.changeset/37182-checklist-not-shown-memo.md @@ -0,0 +1,10 @@ +--- +'@object-ui/console': patch +--- + +fix(console): a session the server answered "not shown" sends no first-run checklist reads on its next console opens + +Clause-②: no +Metadata-protocol: none + +Since the first-run checklist's reads moved above every app route, every session holding any capability sent `GET /api/settings` after the first paint on every console open, only to learn it may not write `localization` and is never shown the checklist: a plain member, and an ordinary organization owner on the cloud control plane (it holds `setup.write`, but that plane's `localization` manifest asks `manage_platform_settings`). The provider now remembers that answer on the device, per organization, user and capability set, for one day, and asks nothing while it stands. An administrator's reads are unchanged; a changed capability set, another user or organization, an expired record, or a failed read reads again. diff --git a/ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx b/ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx index 7cc35b7f765..d31688cafa1 100644 --- a/ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx +++ b/ui/apps/console/src/pages/settings/__tests__/FirstRunChecklist.test.tsx @@ -352,6 +352,88 @@ describe('only an administrator sees it', () => { }); }); +describe('a session answered "not shown" asks nothing again on this device (objectstack#37182)', () => { + const listCalls = () => calls('GET', '/api/settings'); + + /** Opens the console again, as a new tab of the same browser does: the provider remounts, the device storage stays. */ + async function reopen(systemPermissions: string[]) { + cleanup(); + renderChecklist(systemPermissions); + await settle(); + } + + it('a member: the list is read on the first open and not on the next', async () => { + renderChecklist(MEMBER); + await settle(); + expect(listCalls()).toHaveLength(1); + await reopen(MEMBER); + expect(listCalls()).toHaveLength(1); + expect(fetchMock).toHaveBeenCalledTimes(1); + expect(screen.queryByTestId('first-run-checklist')).toBeNull(); + }); + + it('an owner who holds setup.write where localization asks more (the cloud control plane): one read, then none', async () => { + const OWNER = ['manage_org_users', 'setup.access', 'setup.write']; + const routed = fetchMock.getMockImplementation()!; + fetchMock.mockImplementation(async (url: string, init?: RequestInit) => + url === '/api/settings' && (init?.method ?? 'GET') === 'GET' + ? ok({ manifests: [{ ...LOCALIZATION_MANIFEST, writePermission: 'manage_platform_settings' }, MAIL_MANIFEST] }) + : routed(url, init), + ); + renderChecklist(OWNER); + await settle(); + expect(listCalls()).toHaveLength(1); + expect(calls('GET', '/api/settings/localization')).toHaveLength(0); + await reopen(OWNER); + await reopen(OWNER); + expect(fetchMock).toHaveBeenCalledTimes(1); + expect(screen.queryByTestId('first-run-checklist')).toBeNull(); + }); + + it('an administrator reads on every open, and is shown the checklist each time', async () => { + renderChecklist(ADMIN); + expect(await screen.findByTestId('first-run-checklist')).toBeTruthy(); + await reopen(ADMIN); + expect(await screen.findByTestId('first-run-checklist')).toBeTruthy(); + expect(listCalls()).toHaveLength(2); + expect(calls('GET', '/api/settings/localization')).toHaveLength(2); + }); + + it('a changed capability set reads again: a member made an administrator is shown it at once', async () => { + renderChecklist(MEMBER); + await settle(); + await reopen(ADMIN); + expect(listCalls()).toHaveLength(2); + expect(await screen.findByTestId('first-run-checklist')).toBeTruthy(); + }); + + it('a list read that fails is no answer: the next open reads again', async () => { + const routed = fetchMock.getMockImplementation()!; + fetchMock.mockImplementation(async (url: string, init?: RequestInit) => + url === '/api/settings' + ? ({ ok: false, status: 503, statusText: 'Service Unavailable', headers: new Headers(), json: async () => ({}) } as unknown as Response) + : routed(url, init), + ); + renderChecklist(MEMBER); + await settle(); + fetchMock.mockImplementation(routed); + await reopen(MEMBER); + expect(listCalls()).toHaveLength(2); + }); + + it('another user in the same browser reads for themself', async () => { + renderChecklist(MEMBER); + await settle(); + AUTH.user = { id: 'u_other' }; + try { + await reopen(MEMBER); + } finally { + AUTH.user = { id: 'u_admin' }; + } + expect(listCalls()).toHaveLength(2); + }); +}); + describe('one required row, the basics; every other platform row optional (objectstack#36739)', () => { it('a fresh workspace: the basics first and required, then mail and invite, optional, each with its way in', async () => { renderChecklist(ADMIN); diff --git a/ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts b/ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts index 9e67f3eef87..af5bf8b9139 100644 --- a/ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts +++ b/ui/apps/console/src/pages/settings/__tests__/firstRunChecklistLogic.test.ts @@ -25,6 +25,10 @@ import { organizationBasics, markDismissed, wasDismissed, + NOT_SHOWN_RECORD_TTL_MS, + markAnsweredNotShown, + notShownRecordKey, + wasAnsweredNotShown, type ChecklistStorage, } from '../firstRunChecklistLogic'; import type { ResolvedSettingValue, SettingsManifest, Specifier } from '../types'; @@ -236,6 +240,62 @@ describe('hiding the checklist is a per-device record, per workspace and user', }); }); +describe('"not shown" is a per-device answer, per workspace, user and capability set, for a day (objectstack#37182)', () => { + function memory(): ChecklistStorage & { data: Map } { + const data = new Map(); + return { data, getItem: (k) => data.get(k) ?? null, setItem: (k, v) => void data.set(k, v) }; + } + const HELD = 'setup.access\nsetup.write'; + const T0 = Date.UTC(2026, 10, 25, 2, 0, 0); + + it('keys the record on both ids, apart from the dismiss record, and reads it back for the same capability set', () => { + const storage = memory(); + const key = notShownRecordKey('org_1', 'u_owner'); + expect(key).toBe('os:first-run-checklist-not-shown:org_1:u_owner'); + expect(key).not.toBe(dismissRecordKey('org_1', 'u_owner')); + expect(wasAnsweredNotShown(storage, key, HELD, T0)).toBe(false); + expect(markAnsweredNotShown(storage, key, HELD, T0)).toBe(true); + expect(wasAnsweredNotShown(storage, key, HELD, T0 + 1000)).toBe(true); + expect(wasAnsweredNotShown(storage, notShownRecordKey('org_2', 'u_owner'), HELD, T0 + 1000)).toBe(false); + }); + + it('a changed capability set reads again', () => { + const storage = memory(); + const key = notShownRecordKey('org_1', 'u_owner'); + markAnsweredNotShown(storage, key, HELD, T0); + expect(wasAnsweredNotShown(storage, key, `${HELD}\nmanage_platform_settings`, T0 + 1000)).toBe(false); + expect(wasAnsweredNotShown(storage, key, 'setup.access', T0 + 1000)).toBe(false); + }); + + it('stands for a day, then reads again; a record dated in the future reads again', () => { + const storage = memory(); + const key = notShownRecordKey('org_1', 'u_owner'); + markAnsweredNotShown(storage, key, HELD, T0); + expect(wasAnsweredNotShown(storage, key, HELD, T0 + NOT_SHOWN_RECORD_TTL_MS - 1)).toBe(true); + expect(wasAnsweredNotShown(storage, key, HELD, T0 + NOT_SHOWN_RECORD_TTL_MS)).toBe(false); + expect(wasAnsweredNotShown(storage, key, HELD, T0 - 1)).toBe(false); + }); + + it('storage that cannot be read, or a record that does not parse, reads again', () => { + const broken: ChecklistStorage = { + getItem: () => { + throw new Error('denied'); + }, + setItem: () => { + throw new Error('denied'); + }, + }; + expect(wasAnsweredNotShown(broken, 'k', HELD, T0)).toBe(false); + expect(wasAnsweredNotShown(undefined, 'k', HELD, T0)).toBe(false); + expect(markAnsweredNotShown(broken, 'k', HELD, T0)).toBe(false); + const storage = memory(); + for (const raw of ['not json', 'null', '2026-11-25T00:00:00.000Z', JSON.stringify({ held: HELD }), JSON.stringify({ held: HELD, at: 'x' })]) { + storage.data.set('k', raw); + expect(wasAnsweredNotShown(storage, 'k', HELD, T0)).toBe(false); + } + }); +}); + describe('completion: the basics are required; mail, invite and both AI rows are optional (objectstack#32643, objectstack#36739)', () => { it('only the basics done, every optional row not: complete, and the progress counts every row', () => { const rows = [ diff --git a/ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts b/ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts index d678abf5a0f..82d6163e1f6 100644 --- a/ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts +++ b/ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts @@ -252,6 +252,88 @@ export function markDismissed(storage: ChecklistStorage | undefined, key: string } } +/** + * Where "the server answered that this session is not shown the checklist" + * lives, per workspace and per user: `os:first-run-checklist-not-shown::` + * (objectstack#37182). + * + * The checklist's provider is mounted above every app route, and the only way + * it learns that a session may not write `localization` is to ask: the first + * request of `readChecklistSettings` lists the settings manifests. For a + * session that is never shown the checklist that request bought nothing, on + * every console open: a plain member, and an ordinary organization owner on the + * cloud's control plane, which holds `setup.write` but whose `localization` + * manifest asks `manage_platform_settings`. No capability check before the + * request can tell that second session apart: the permission a deployment's + * manifest asks is known only once the list answers, and naming one in the + * console would be a second copy of the manifest's declaration. + * + * So the answer is remembered on the device, beside the dismiss record and for + * the same reason (the narrowest scope the client can see that holds every tab + * of one sign-in), with what it was read for: + * + * - the capability set it was read for: any change to it (a grant, a + * revocation) is a different session as far as the checklist goes, and it + * reads again; + * - when it was read: after {@link NOT_SHOWN_RECORD_TTL_MS} it reads again, so + * a deployment that starts showing the checklist to this session (a + * manifest's `writePermission` changed by an upgrade) is followed within a + * day. + * + * Only a server's ANSWER is remembered: a read that failed, and an + * administrator's checklist, are not, so the administrator's reads are exactly + * what they were. The record fails toward reading again: storage that cannot + * be read, a record that does not parse, or one dated in the future, all read. + */ +export const NOT_SHOWN_RECORD_PREFIX = 'os:first-run-checklist-not-shown'; + +/** How long a "not shown" answer stands before the provider asks again: one day. */ +export const NOT_SHOWN_RECORD_TTL_MS = 24 * 60 * 60 * 1000; + +export function notShownRecordKey(orgId: string, userId: string): string { + return `${NOT_SHOWN_RECORD_PREFIX}:${orgId}:${userId}`; +} + +/** + * Did the server answer, within the last {@link NOT_SHOWN_RECORD_TTL_MS}, that + * this user in this workspace, holding exactly `held` (the capability list, + * newline-joined), is not shown the checklist? + */ +export function wasAnsweredNotShown( + storage: ChecklistStorage | undefined, + key: string, + held: string, + now: number = Date.now(), +): boolean { + if (!storage) return false; + try { + const raw = storage.getItem(key); + if (raw === null) return false; + const record = JSON.parse(raw) as { held?: unknown; at?: unknown } | null; + if (!record || record.held !== held || typeof record.at !== 'number') return false; + const age = now - record.at; + return age >= 0 && age < NOT_SHOWN_RECORD_TTL_MS; + } catch { + return false; + } +} + +/** Record that the server answered "not shown" for `held`. Returns `false` when it could not be written. */ +export function markAnsweredNotShown( + storage: ChecklistStorage | undefined, + key: string, + held: string, + now: number = Date.now(), +): boolean { + if (!storage) return false; + try { + storage.setItem(key, JSON.stringify({ held, at: now })); + return true; + } catch { + return false; + } +} + /** * The browser's own zone, or `undefined` when it reports none. * diff --git a/ui/apps/console/src/pages/settings/firstRunChecklistState.tsx b/ui/apps/console/src/pages/settings/firstRunChecklistState.tsx index f5fdef3f08d..10a3b4b560a 100644 --- a/ui/apps/console/src/pages/settings/firstRunChecklistState.tsx +++ b/ui/apps/console/src/pages/settings/firstRunChecklistState.tsx @@ -16,6 +16,10 @@ * answers `null` and nothing further is asked; * - after the console's first paint (`whenBootPainted`), so the reads never go * out beside the page's own first reads; + * - not at all for a session the server already answered "not shown" on this + * device, for this organization, user and capability set, within the last + * day (`wasAnsweredNotShown`, objectstack#37182): the list request that + * finds that out would otherwise go out on every console open; * - each answer is stored with the identity it was read for (organization, * user, capability set), so an answer read for another one is never drawn. * @@ -45,10 +49,13 @@ import { dismissRecordKey, hasInvitedColleagues, LOCALIZATION_NAMESPACE, + markAnsweredNotShown, markDismissed, + notShownRecordKey, organizationBasics, readBrowserAnswers, readChecklistSettings, + wasAnsweredNotShown, wasDismissed, type BrowserAnswers, type ChecklistCompletion, @@ -205,14 +212,25 @@ export function FirstRunChecklistProvider({ children }: { children: ReactNode }) }, [getAuthConfig]); useEffect(() => { - if (!identity || !orgId || heldKey === null) return; + if (!identity || !orgId || !userId || heldKey === null) return; const held = heldKey === '' ? [] : heldKey.split('\n'); + // The server already answered "not shown" for exactly this session: ask + // nothing (objectstack#37182). + const notShownKey = notShownRecordKey(orgId, userId); + if (wasAnsweredNotShown(deviceStorage(), notShownKey, heldKey)) return; + let cancelled = false; whenBootPainted() - .then(() => (cancelled ? null : readChecklistSettings(held))) + .then(() => (cancelled ? undefined : readChecklistSettings(held))) .then((found) => { - if (cancelled || !found) return; + if (cancelled || found === undefined) return; + if (!found) { + // An answer, not a failure (a failed read throws past this): keep it + // so the next open does not ask again. + markAnsweredNotShown(deviceStorage(), notShownKey, heldKey); + return; + } setLoaded({ identity, settings: found }); // Only an administrator's checklist asks who else is here. Promise.all([getMembers(orgId), listInvitations(orgId)])