fix(legal): make the gate reachable from every route, and stop About lying after a bump
Found by the Phase 4 adversarial review; four of six lenses filed it independently. The gate rendered only on #import/#export/#edit, and TabBar rendered exactly those three tabs `disabled` while it was up. But they are the only in-app navigation to a gated route, and the footer only offers #settings and #about. So a first-run user who reached #settings -- the flow docs/14 §2 explicitly prescribes, "so a VI/JA user can switch language and theme first" -- had no enabled control that led back to the accept UI. Worst path, introduced by the popup gear this same phase: fresh profile, no Manager tab, click ⚙. openManager creates a NEW tab at #settings, so there is no history entry to go Back to. Reopening from the popup does not rescue it either -- open-manager deliberately focuses the existing tab without touching its hash (docs/02 §6). The only escapes were editing the URL fragment or closing the tab. The fix is that disabling was never what blocked anything: App.svelte already substitutes <LegalGate> for the tab body on any gated route, which is what keeps Import/Export/Edit from mounting pre-acceptance. So the tabs are now clickable and clicking one shows the gate. They carry legal.blocked as their title -- a key that was translated into all three locales and rendered nowhere, which is its own half of the same defect: the dead tabs gave no reason at all. Separately: decideLegalStatus dropped the stored record on the `updated` path, so the first time LEGAL_VERSION is bumped, About would tell a user who accepted v1 that they have never accepted anything. It now carries the superseded acceptance. Dead code today (LEGAL_VERSION is 1), a wrong statement about consent the day it is not. Also clears LegalGate's close timer before setting a new one; repeated clicks stacked timers and only the last was ever cleaned up. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
432645ca43
commit
02817bdfe0
5 files changed
+69
-9
No files matched your search
+1
-1
@@ -41,5 +41,5 @@ inside the Extension.
|
||||
|
||||
## Contact
|
||||
|
||||
⚠️ contact email — or open an issue at
|
||||
Email: contact@poli0981.dev — or open an issue at
|
||||
<https://github.com/poli0981/bookmarkmagic/issues>
|
||||
@@ -55,6 +55,9 @@
|
||||
* permission, which docs/08 §2 forbids.
|
||||
*/
|
||||
function closeTab(): void {
|
||||
// Clear first: repeated clicks would otherwise stack timers, and only the
|
||||
// last one would ever be cleaned up.
|
||||
if (closeTimer !== undefined) clearTimeout(closeTimer);
|
||||
globalThis.close();
|
||||
closeTimer = setTimeout(() => {
|
||||
closeTimer = undefined;
|
||||
|
||||
@@ -4,7 +4,15 @@
|
||||
import { getRoute, navigate, type Route } from '../stores/route.svelte';
|
||||
|
||||
interface Props {
|
||||
/** Routes the legal gate is currently blocking (docs/14 §2). */
|
||||
/**
|
||||
* Routes the legal gate is currently blocking (docs/14 §2).
|
||||
*
|
||||
* These stay CLICKABLE. What blocks them is App.svelte rendering the gate
|
||||
* in place of the tab body, so the tab never mounts pre-acceptance. Making
|
||||
* the buttons inert instead was a dead end: they are the only in-app
|
||||
* navigation to a gated route, so a first-run user who reached #settings —
|
||||
* the flow docs/14 §2 explicitly wants — had no way back to the accept UI.
|
||||
*/
|
||||
blocked?: readonly Route[];
|
||||
}
|
||||
|
||||
@@ -22,8 +30,13 @@
|
||||
<button
|
||||
class:active={getRoute() === tab.route}
|
||||
aria-current={getRoute() === tab.route ? 'page' : undefined}
|
||||
disabled={blocked.includes(tab.route) || (isWriting() && getRoute() !== tab.route)}
|
||||
title={isWriting() && getRoute() !== tab.route ? t('common.busy') : undefined}
|
||||
class:locked={blocked.includes(tab.route)}
|
||||
disabled={isWriting() && getRoute() !== tab.route}
|
||||
title={blocked.includes(tab.route)
|
||||
? t('legal.blocked')
|
||||
: isWriting() && getRoute() !== tab.route
|
||||
? t('common.busy')
|
||||
: undefined}
|
||||
onclick={() => navigate(tab.route)}
|
||||
>
|
||||
{t(tab.key)}
|
||||
@@ -56,6 +69,16 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Reachable, but visibly not yet usable — clicking shows the gate. */
|
||||
.locked {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.locked::after {
|
||||
content: ' 🔒';
|
||||
font-size: var(--fs-0);
|
||||
}
|
||||
|
||||
.active {
|
||||
background: var(--bg-raised);
|
||||
border-color: var(--border);
|
||||
|
||||
@@ -15,7 +15,12 @@ import type { SaveOutcome } from './settings.svelte';
|
||||
export type LegalStatus =
|
||||
| { kind: 'loading' }
|
||||
| { kind: 'accepted'; acceptance: LegalAcceptance }
|
||||
| { kind: 'required'; reason: 'first-run' | 'updated' };
|
||||
/**
|
||||
* `previous` carries the superseded record on the `updated` path. Without it
|
||||
* the About tab would tell a user who accepted v1 that they have never
|
||||
* accepted anything, the moment LEGAL_VERSION is bumped to 2.
|
||||
*/
|
||||
| { kind: 'required'; reason: 'first-run' | 'updated'; previous?: LegalAcceptance };
|
||||
|
||||
/**
|
||||
* The three routes the gate blocks.
|
||||
@@ -43,7 +48,7 @@ export function decideLegalStatus(
|
||||
): LegalStatus {
|
||||
if (acceptance === null) return { kind: 'required', reason: 'first-run' };
|
||||
if (acceptance.acceptedVersion < currentVersion) {
|
||||
return { kind: 'required', reason: 'updated' };
|
||||
return { kind: 'required', reason: 'updated', previous: acceptance };
|
||||
}
|
||||
return { kind: 'accepted', acceptance };
|
||||
}
|
||||
@@ -56,8 +61,16 @@ export function isGateRequired(): boolean {
|
||||
return status.kind === 'required';
|
||||
}
|
||||
|
||||
/**
|
||||
* The most recent acceptance on record, current or superseded.
|
||||
*
|
||||
* About renders this, so it must survive a `LEGAL_VERSION` bump — the user did
|
||||
* accept the older terms, and saying otherwise is simply false.
|
||||
*/
|
||||
export function getAcceptance(): LegalAcceptance | undefined {
|
||||
return status.kind === 'accepted' ? status.acceptance : undefined;
|
||||
if (status.kind === 'accepted') return status.acceptance;
|
||||
if (status.kind === 'required') return status.previous;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** `[]` unless the gate is up. Never `undefined`, so the TabBar prop is simple. */
|
||||
|
||||
@@ -26,10 +26,14 @@ describe('decideLegalStatus', () => {
|
||||
expect(decideLegalStatus(null, 1)).toEqual({ kind: 'required', reason: 'first-run' });
|
||||
});
|
||||
|
||||
it('gates an older acceptance as an update', () => {
|
||||
expect(decideLegalStatus({ acceptedVersion: 0, acceptedAt: ACCEPTED_AT }, 1)).toEqual({
|
||||
it('gates an older acceptance as an update, KEEPING the superseded record', () => {
|
||||
// Without `previous`, the About tab tells a user who accepted v1 that they
|
||||
// have never accepted anything the moment LEGAL_VERSION becomes 2.
|
||||
const previous = { acceptedVersion: 0, acceptedAt: ACCEPTED_AT };
|
||||
expect(decideLegalStatus(previous, 1)).toEqual({
|
||||
kind: 'required',
|
||||
reason: 'updated',
|
||||
previous,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -85,6 +89,23 @@ describe('loadLegal', () => {
|
||||
expect(getLegalStatus()).toEqual({ kind: 'required', reason: 'first-run' });
|
||||
});
|
||||
|
||||
it('still reports the superseded acceptance after a version bump', async () => {
|
||||
await fakeBrowser.storage.local.set({
|
||||
legal: { acceptedVersion: LEGAL_VERSION - 1, acceptedAt: ACCEPTED_AT },
|
||||
});
|
||||
await loadLegal();
|
||||
expect(isGateRequired()).toBe(true);
|
||||
expect(getAcceptance()).toEqual({
|
||||
acceptedVersion: LEGAL_VERSION - 1,
|
||||
acceptedAt: ACCEPTED_AT,
|
||||
});
|
||||
});
|
||||
|
||||
it('reports no acceptance at all on a fresh profile', async () => {
|
||||
await loadLegal();
|
||||
expect(getAcceptance()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('exposes the stored acceptance for the About tab', async () => {
|
||||
await fakeBrowser.storage.local.set({
|
||||
legal: { acceptedVersion: LEGAL_VERSION, acceptedAt: ACCEPTED_AT },
|
||||
|
||||
Reference in new issue
Block a user