Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .changeset/37182-checklist-not-shown-memo.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string, string> } {
const data = new Map<string, string>();
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 = [
Expand Down
82 changes: 82 additions & 0 deletions ui/apps/console/src/pages/settings/firstRunChecklistLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:<orgId>:<userId>`
* (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.
*
Expand Down
24 changes: 21 additions & 3 deletions ui/apps/console/src/pages/settings/firstRunChecklistState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -45,10 +49,13 @@ import {
dismissRecordKey,
hasInvitedColleagues,
LOCALIZATION_NAMESPACE,
markAnsweredNotShown,
markDismissed,
notShownRecordKey,
organizationBasics,
readBrowserAnswers,
readChecklistSettings,
wasAnsweredNotShown,
wasDismissed,
type BrowserAnswers,
type ChecklistCompletion,
Expand Down Expand Up @@ -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)])
Expand Down
Loading