Rework the sidebar "All accounts" section into a "Unified Mailbox" that, by default, stays within the active login account and its shared/group folders. Merging across multiple logged-in accounts becomes an opt-in sub-option instead of the default, and the standalone per-account "All Mail" virtual folder is folded into the unified All mail / Unread / Starred entries (its folder selection now narrows those lists). Scope: - lib/unified-mailbox.ts: UnifiedAccountClient.crossIncludedMailboxIds; the cross views honor the per-account folder selection (union across accounts = the sum of each account's selection), falling back to inbox+custom when unset. - stores/email-store.ts: buildUnifiedAccountClients gains scopeToClientAccountId (the account boundary) and populates crossIncludedMailboxIds from allMailFolderIds; remove the standalone __all_mail__ fetch/search/load-more branches. - page.tsx: scope to the active account unless cross-account is active (per-user opt-in AND admin gate); the per-role unified mailboxes obey the same scope. Folding: - Drop ALL_MAIL_MAILBOX_ID (lib/jmap/types.ts); thread-list source-folder column now keys on isUnifiedView only; settings folder picker moves under the unified group and shows once any unified entry is enabled. Config: - User: new unifiedCrossAccount (default false); includeGroupInUnified default flips to true; enableAllMailView retired; the three cross-view toggles now gate the unified Unread/Starred/All mail entries. - Admin: new unifiedCrossAccountEnabled gate, default FALSE (cross-account is an admin opt-in; when off the per-user toggle is hidden and the scope is forced account-bounded at runtime). allMailViewEnabled deprecated and normalized forward into crossAllViewEnabled on policy load; cross-view gate labels reworded to "Unified Mailbox: ...". Header: the sidebar section shows "All accounts" when cross-account is active (opt-in AND admin gate AND >1 connected account), else "Unified Mailbox". Migration: - Settings persist v5 -> v6 (exported migrateSettings) - cross-active users keep cross-account; All-Mail-only users get the account-bounded unified All mail entry with folder ids preserved; includeGroupInUnified enabled for every migrated config; fresh installs are account-bounded. - Admin policy: one-shot, marker-guarded migratePolicyUnifiedMailbox (run before configManager.load) enables unifiedCrossAccountEnabled when a cross view was active, so existing cross-account installs keep the behaviour despite the default-false gate. Skipped on read-only config dirs. Locales: sidebar all_accounts (original label) + unified_mailbox (translated, per locale) keys; dead standalone all_mail strings removed across all 20 locales. Docs: FEATURES.md updated to the account-bounded model, the cross-account gate, and the folder-narrowed aggregate entries. Verification: tsc clean, eslint clean, full vitest suite green (incl. translations completeness, cross-view/migration coverage, and the admin policy migration test).
96 lines
4.1 KiB
TypeScript
96 lines
4.1 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { useSettingsStore, migrateSettings } from '../settings-store';
|
|
|
|
describe('settings-store per-account allMailFolderIds', () => {
|
|
beforeEach(() => {
|
|
useSettingsStore.setState({ allMailFolderIds: {} });
|
|
});
|
|
|
|
it('defaults to an empty record (every account "not configured")', () => {
|
|
expect(useSettingsStore.getState().allMailFolderIds).toEqual({});
|
|
});
|
|
|
|
it('keeps each account selection independent', () => {
|
|
useSettingsStore.setState({
|
|
allMailFolderIds: { 'acct-1': ['inbox', 'archive'], 'acct-2': ['sent'] },
|
|
});
|
|
const map = useSettingsStore.getState().allMailFolderIds;
|
|
expect(map['acct-1']).toEqual(['inbox', 'archive']);
|
|
expect(map['acct-2']).toEqual(['sent']);
|
|
// A third account remains unconfigured (no entry).
|
|
expect(map['acct-3']).toBeUndefined();
|
|
});
|
|
|
|
it('distinguishes explicit-empty ([] = no folders) from not-configured (undefined)', () => {
|
|
useSettingsStore.setState({ allMailFolderIds: { 'acct-1': [] } });
|
|
const map = useSettingsStore.getState().allMailFolderIds;
|
|
expect(map['acct-1']).toEqual([]); // explicit "no folders"
|
|
expect(map['acct-2']).toBeUndefined(); // never configured
|
|
});
|
|
|
|
describe('importSettings legacy-shape guard', () => {
|
|
it('ignores a legacy global array shape', () => {
|
|
useSettingsStore.setState({ allMailFolderIds: { 'acct-1': ['inbox'] } });
|
|
const ok = useSettingsStore.getState().importSettings(
|
|
JSON.stringify({ allMailFolderIds: ['inbox', 'sent'] }),
|
|
);
|
|
expect(ok).toBe(true);
|
|
// unchanged - the array shape was rejected
|
|
expect(useSettingsStore.getState().allMailFolderIds).toEqual({ 'acct-1': ['inbox'] });
|
|
});
|
|
|
|
it('ignores a null legacy value', () => {
|
|
useSettingsStore.setState({ allMailFolderIds: { 'acct-1': ['inbox'] } });
|
|
useSettingsStore.getState().importSettings(JSON.stringify({ allMailFolderIds: null }));
|
|
expect(useSettingsStore.getState().allMailFolderIds).toEqual({ 'acct-1': ['inbox'] });
|
|
});
|
|
|
|
it('accepts a proper per-account record', () => {
|
|
useSettingsStore.getState().importSettings(
|
|
JSON.stringify({ allMailFolderIds: { 'acct-9': ['inbox', 'spam'] } }),
|
|
);
|
|
expect(useSettingsStore.getState().allMailFolderIds).toEqual({ 'acct-9': ['inbox', 'spam'] });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('migrateSettings v5 -> v6 (Unified Mailbox rework)', () => {
|
|
it('keeps cross-account users cross-account when any cross view was on, and enables shared', () => {
|
|
const out = migrateSettings(
|
|
{ allMailFolderIds: {}, enableCrossUnreadView: true, enableAllMailView: false, includeGroupInUnified: false },
|
|
5,
|
|
) as unknown as Record<string, unknown>;
|
|
expect(out.unifiedCrossAccount).toBe(true);
|
|
// shared inclusion is enabled for every migrated config, even if it was off
|
|
expect(out.includeGroupInUnified).toBe(true);
|
|
expect(out.enableAllMailView).toBeUndefined();
|
|
});
|
|
|
|
it('folds a standalone All-Mail user into the account-bounded unified "All mail" entry', () => {
|
|
const out = migrateSettings(
|
|
{
|
|
allMailFolderIds: { 'acct-1': ['inbox', 'projects'] },
|
|
enableAllMailView: true,
|
|
enableUnifiedMailbox: false,
|
|
enableCrossUnreadView: false,
|
|
enableCrossStarredView: false,
|
|
enableCrossAllView: false,
|
|
},
|
|
5,
|
|
) as unknown as Record<string, unknown>;
|
|
expect(out.enableUnifiedMailbox).toBe(true);
|
|
expect(out.enableCrossAllView).toBe(true);
|
|
expect(out.unifiedCrossAccount).toBe(false); // new account-bounded default
|
|
expect(out.includeGroupInUnified).toBe(true);
|
|
// folder selection carries over unchanged -> narrows the unified lists
|
|
expect(out.allMailFolderIds).toEqual({ 'acct-1': ['inbox', 'projects'] });
|
|
expect(out.enableAllMailView).toBeUndefined();
|
|
});
|
|
|
|
it('a fresh user gets account-bounded defaults', () => {
|
|
const out = migrateSettings({ allMailFolderIds: {} }, 5) as unknown as Record<string, unknown>;
|
|
expect(out.unifiedCrossAccount).toBe(false);
|
|
expect(out.includeGroupInUnified).toBe(true);
|
|
});
|
|
});
|