Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(updates-consent): keep account choices with their owner

Sebastian B0e89c4ff4959
diff --git a/electron/updates-consent.mjs b/electron/updates-consent.mjs
index 4492e49f1d..b3936e6443 100644
--- a/electron/updates-consent.mjs
+++ b/electron/updates-consent.mjs
@@ -108,7 +108,7 @@ export function createUpdatesConsent({ prefs, account, available, now = Date.now
keep({ status: remote.status, version: remote.textVersion, at: now(), account: who.id, ...(local?.email ? { email: local.email } : {}), replacedReceipts: local?.replacedReceipts });
return;
}
- if (!local) return;
+ if (!local || (local.account && local.account !== who.id)) return;
await client().recordUpdatesConsent(local.status, local.version);
keep({ ...rest, account: who.id, pending: false });
}
@@ -126,7 +126,8 @@ export function createUpdatesConsent({ prefs, account, available, now = Date.now
const sync = () => running ??= settle().finally(() => { running = null; });
const snapshot = () => {
- const local = prefs.updatesConsent(), who = signedIn();
+ const saved = prefs.updatesConsent(), who = signedIn();
+ const local = who && saved?.account && saved.account !== who.id ? null : saved;
return { available: true, due: !local, status: local?.status ?? null, signedIn: Boolean(who),
email: who?.email ?? (local?.status === "opted_in" ? local.email ?? null : null), version: UPDATES_CONSENT_VERSION };
};
diff --git a/electron/updates-consent.node-test.mjs b/electron/updates-consent.node-test.mjs
index b58effc3fe..f386901857 100644
--- a/electron/updates-consent.node-test.mjs
+++ b/electron/updates-consent.node-test.mjs
@@ -344,6 +344,36 @@ test("signing in while an email opt-in is on its way: an answer given on the acc
assert.equal(f.saved.updatesConsent.pending, undefined);
});
+test("an account without a choice never inherits another account's answer", async t => {
+ for (const status of ["opted_in", "declined", "withdrawn"]) for (const pending of [false, true])
+ await t.test(`${status}, pending=${pending}`, async t => {
+ const f = await world(t);
+ await f.signInNow();
+ f.down = pending;
+ await f.consent.choose({ status });
+ f.down = false;
+ const accountAnswer = structuredClone(f.saved.updatesConsent);
+ await f.client.signOut();
+ f.accountId = "account-2";
+ f.accessToken = `omc_${"B".repeat(43)}`;
+ f.account = null;
+ await f.signInNow();
+ const first = f.requests.length;
+ for (const restart of [false, true]) {
+ if (restart) f.launch();
+ const state = await f.consent.state();
+ assert.equal(f.account, null, "no answer is posted on behalf of the new account");
+ assert.equal(state.due, true);
+ assert.equal(state.status, null);
+ assert.deepEqual(f.saved.updatesConsent, accountAnswer, "the other account's answer is preserved");
+ }
+ assert.deepEqual(f.requests.slice(first).map(({ method }) => method), ["GET", "GET"]);
+ await f.consent.choose({ status: "withdrawn" });
+ assert.equal(f.account.status, "withdrawn");
+ assert.equal(f.saved.updatesConsent.account, "account-2");
+ });
+});
+
test("a slow account A consent read cannot overwrite account B's withdrawal", async t => {
const f = await world(t);
f.saved = { updatesConsent: { status: "opted_in", version: UPDATES_CONSENT_VERSION, at: f.now, pending: true } };