Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
refactor(email): converge primary-inbox checks on email_links.is_primary (#4001)
gbirman7c8e429f0d83
diff --git a/js/app/packages/app/component/settings/Account.tsx b/js/app/packages/app/component/settings/Account.tsxindex 9d7bf17d6e..8b8ff7d1ed 100644--- a/js/app/packages/app/component/settings/Account.tsx+++ b/js/app/packages/app/component/settings/Account.tsx@@ -299,13 +299,13 @@ export function Account() {new Set());- // The primary inbox is the one matching the account email; it sorts to the top+ // The primary inbox is the user's own is_primary link; it sorts to the top// and is labelled. Everything else (other own inboxes + delegated/shared) follows.const inboxes = createMemo(() => {const links = emailLinksQuery.data?.links ?? [];- const primaryEmail = email()?.toLowerCase();+ const uid = userId();const primary = links.find(- (link) => link.email_address.toLowerCase() === primaryEmail+ (link) => link.is_primary && link.macro_id === uid);const others = links.filter((link) => link !== primary);return { primary, others };diff --git a/js/app/packages/core/user/inboxOnly.ts b/js/app/packages/core/user/inboxOnly.tsindex d9dfe698b4..5628a2370e 100644--- a/js/app/packages/core/user/inboxOnly.ts+++ b/js/app/packages/core/user/inboxOnly.ts@@ -4,9 +4,9 @@ import { macroIdToEmail, tryMacroId } from './macroId';/*** Predicate: is this macro id a connected secondary inbox (an extra mailbox the- * current user attached to their own account, flagged `is_inbox_only`) rather than- * a real user. Not to be confused with a delegated/shared inbox, which is a separate- * loggable user (its own macro id) and reports `is_inbox_only = false`.+ * current user attached to their own account, `!is_primary`) rather than a real+ * user. Not to be confused with a delegated/shared inbox, which is a separate+ * loggable user (its own macro id) and reports `is_primary = true`.*/export function useIsConnectedSecondaryInbox() {const linksQuery = useEmailLinksQuery();@@ -14,7 +14,7 @@ export function useIsConnectedSecondaryInbox() {const inboxOnlyEmails = createMemo(() => {const set = new Set<string>();for (const link of linksQuery.data?.links ?? []) {- if (link.is_inbox_only) set.add(link.email_address.toLowerCase());+ if (!link.is_primary) set.add(link.email_address.toLowerCase());}return set;});diff --git a/js/app/packages/queries/email/link.ts b/js/app/packages/queries/email/link.tsindex 7c8b0c911d..24906c6664 100644--- a/js/app/packages/queries/email/link.ts+++ b/js/app/packages/queries/email/link.ts@@ -1,4 +1,4 @@-import { useEmail } from '@core/context/user';+import { useUserId } from '@core/context/user';import { throwOnErr } from '@core/util/result';import { invalidateUserInfo } from '@queries/auth/user-info';import { queryClient } from '@queries/client';@@ -32,17 +32,18 @@ export function useEmailLinksQuery() {}/**- * The link id of the user's primary inbox — the linked inbox whose address- * matches the account email. `undefined` until links/email load or if none match.+ * The link id of the user's primary inbox — their own `is_primary` link.+ * Delegated inboxes are primary for their own account, hence the macro_id+ * guard. `undefined` until links load or if none match.*/export function usePrimaryEmailLinkId() {const linksQuery = useEmailLinksQuery();- const email = useEmail();+ const userId = useUserId();return createMemo(() => {- const primaryEmail = email()?.toLowerCase();- if (!primaryEmail) return undefined;+ const uid = userId();+ if (!uid) return undefined;return linksQuery.data?.links.find(- (link) => link.email_address.toLowerCase() === primaryEmail+ (link) => link.is_primary && link.macro_id === uid)?.id;});}diff --git a/js/app/packages/service-clients/service-email/generated/schemas/link.ts b/js/app/packages/service-clients/service-email/generated/schemas/link.tsindex 0fe9090a5d..6028b9de7b 100644--- a/js/app/packages/service-clients/service-email/generated/schemas/link.ts+++ b/js/app/packages/service-clients/service-email/generated/schemas/link.ts@@ -15,7 +15,7 @@ export interface Link {email_address: string;fusionauth_user_id: string;id: string;- is_inbox_only: boolean;+ is_primary: boolean;is_sync_active: boolean;macro_id: string;/** The inbox's own profile photo (its self-contact's SFS photo), if synced. */diff --git a/js/app/packages/service-clients/service-email/openapi.json b/js/app/packages/service-clients/service-email/openapi.jsonindex 1f04f95320..c10ff0d7f2 100644--- a/js/app/packages/service-clients/service-email/openapi.json+++ b/js/app/packages/service-clients/service-email/openapi.json@@ -4153,7 +4153,7 @@"is_sync_active","sync_status","settings",- "is_inbox_only",+ "is_primary","created_at","updated_at"],@@ -4172,7 +4172,7 @@"type": "string","format": "uuid"},- "is_inbox_only": {+ "is_primary": {"type": "boolean"},"is_sync_active": {diff --git a/rust/cloud-storage/.sqlx/query-50318d6d13fb931307f2115b33d277b5298c45ed798719e792e722bd30615a95.json b/rust/cloud-storage/.sqlx/query-08d035b4ba64e5c981db5899f59dd65c406184ebcfe92ee3fecd979dc7da2f3f.jsonsimilarity index 79%rename from rust/cloud-storage/.sqlx/query-50318d6d13fb931307f2115b33d277b5298c45ed798719e792e722bd30615a95.jsonrename to rust/cloud-storage/.sqlx/query-08d035b4ba64e5c981db5899f59dd65c406184ebcfe92ee3fecd979dc7da2f3f.jsonindex 7a4d0490be..fb114d4c60 100644--- a/rust/cloud-storage/.sqlx/query-50318d6d13fb931307f2115b33d277b5298c45ed798719e792e722bd30615a95.json+++ b/rust/cloud-storage/.sqlx/query-08d035b4ba64e5c981db5899f59dd65c406184ebcfe92ee3fecd979dc7da2f3f.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE macro_id = $1\n LIMIT 1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at \n FROM email_links\n WHERE macro_id = $1\n ORDER BY created_at DESC\n LIMIT 1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -66,8 +71,9 @@false,false,false,+ false,false]},- "hash": "50318d6d13fb931307f2115b33d277b5298c45ed798719e792e722bd30615a95"+ "hash": "08d035b4ba64e5c981db5899f59dd65c406184ebcfe92ee3fecd979dc7da2f3f"}diff --git a/rust/cloud-storage/.sqlx/query-f4dd3bd30a64a7fd82d9a254a0fb0ea36e8607ebd4c272509afba882a3e0b572.json b/rust/cloud-storage/.sqlx/query-11dd667e0b2f95f4d43191cc1ad971ce1816b260b7e8b529f1a39f284fecc9c7.jsonsimilarity index 82%rename from rust/cloud-storage/.sqlx/query-f4dd3bd30a64a7fd82d9a254a0fb0ea36e8607ebd4c272509afba882a3e0b572.jsonrename to rust/cloud-storage/.sqlx/query-11dd667e0b2f95f4d43191cc1ad971ce1816b260b7e8b529f1a39f284fecc9c7.jsonindex 3cdb5b9433..f06d3a25ec 100644--- a/rust/cloud-storage/.sqlx/query-f4dd3bd30a64a7fd82d9a254a0fb0ea36e8607ebd4c272509afba882a3e0b572.json+++ b/rust/cloud-storage/.sqlx/query-11dd667e0b2f95f4d43191cc1ad971ce1816b260b7e8b529f1a39f284fecc9c7.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE id = $1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE id = $1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -66,8 +71,9 @@false,false,false,+ false,false]},- "hash": "f4dd3bd30a64a7fd82d9a254a0fb0ea36e8607ebd4c272509afba882a3e0b572"+ "hash": "11dd667e0b2f95f4d43191cc1ad971ce1816b260b7e8b529f1a39f284fecc9c7"}diff --git a/rust/cloud-storage/.sqlx/query-c8569a737734eab039a3ca9759478b203596330442305a6f3925edf67a8b52a3.json b/rust/cloud-storage/.sqlx/query-1461ac950007fab2c5dcf5aa9e5e583a21feaad513778f6f419e046a8a630f11.jsonsimilarity index 81%rename from rust/cloud-storage/.sqlx/query-c8569a737734eab039a3ca9759478b203596330442305a6f3925edf67a8b52a3.jsonrename to rust/cloud-storage/.sqlx/query-1461ac950007fab2c5dcf5aa9e5e583a21feaad513778f6f419e046a8a630f11.jsonindex dec05aa8a8..1d697dc4c3 100644--- a/rust/cloud-storage/.sqlx/query-c8569a737734eab039a3ca9759478b203596330442305a6f3925edf67a8b52a3.json+++ b/rust/cloud-storage/.sqlx/query-1461ac950007fab2c5dcf5aa9e5e583a21feaad513778f6f419e046a8a630f11.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1 AND macro_id = $2 AND provider = $3\n LIMIT 1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1 AND macro_id = $2 AND provider = $3\n LIMIT 1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -77,8 +82,9 @@false,false,false,+ false,false]},- "hash": "c8569a737734eab039a3ca9759478b203596330442305a6f3925edf67a8b52a3"+ "hash": "1461ac950007fab2c5dcf5aa9e5e583a21feaad513778f6f419e046a8a630f11"}diff --git a/rust/cloud-storage/.sqlx/query-8942100b50a073f4f95b37246d355dc8b17c5a105492901ad72da89438ec6601.json b/rust/cloud-storage/.sqlx/query-3438cbfd6a3d2354c38bfb1eda314caaf7a8f149d1b20385ab990f4c32c406fe.jsonsimilarity index 77%rename from rust/cloud-storage/.sqlx/query-8942100b50a073f4f95b37246d355dc8b17c5a105492901ad72da89438ec6601.jsonrename to rust/cloud-storage/.sqlx/query-3438cbfd6a3d2354c38bfb1eda314caaf7a8f149d1b20385ab990f4c32c406fe.jsonindex 8a954a7761..0bf8574453 100644--- a/rust/cloud-storage/.sqlx/query-8942100b50a073f4f95b37246d355dc8b17c5a105492901ad72da89438ec6601.json+++ b/rust/cloud-storage/.sqlx/query-3438cbfd6a3d2354c38bfb1eda314caaf7a8f149d1b20385ab990f4c32c406fe.json@@ -1,12 +1,17 @@{"db_name": "PostgreSQL",- "query": "\n INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active)\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (fusionauth_user_id, email_address, provider) \n DO UPDATE SET \n is_sync_active = EXCLUDED.is_sync_active,\n updated_at = NOW()\n RETURNING id\n ",+ "query": "\n INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active)\n VALUES ($1, $2, $3, $4, $5, $6)\n ON CONFLICT (fusionauth_user_id, email_address, provider) \n DO UPDATE SET \n is_sync_active = EXCLUDED.is_sync_active,\n updated_at = NOW()\n RETURNING id, is_primary\n ","describe": {"columns": [{"ordinal": 0,"name": "id","type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "is_primary",+ "type_info": "Bool"}],"parameters": {@@ -29,8 +34,9 @@]},"nullable": [+ false,false]},- "hash": "8942100b50a073f4f95b37246d355dc8b17c5a105492901ad72da89438ec6601"+ "hash": "3438cbfd6a3d2354c38bfb1eda314caaf7a8f149d1b20385ab990f4c32c406fe"}diff --git a/rust/cloud-storage/.sqlx/query-95c5d4f79e729713642efcda97838eddd466c0ec2ec9f96ae2be185ef9ff1547.json b/rust/cloud-storage/.sqlx/query-484391893f69c9fce4d47c7daeb46dca050ac95aa1f247654f6a3820f78552ee.jsonsimilarity index 80%rename from rust/cloud-storage/.sqlx/query-95c5d4f79e729713642efcda97838eddd466c0ec2ec9f96ae2be185ef9ff1547.jsonrename to rust/cloud-storage/.sqlx/query-484391893f69c9fce4d47c7daeb46dca050ac95aa1f247654f6a3820f78552ee.jsonindex 94b5b88dd8..5d325343bf 100644--- a/rust/cloud-storage/.sqlx/query-95c5d4f79e729713642efcda97838eddd466c0ec2ec9f96ae2be185ef9ff1547.json+++ b/rust/cloud-storage/.sqlx/query-484391893f69c9fce4d47c7daeb46dca050ac95aa1f247654f6a3820f78552ee.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, fusionauth_user_id, macro_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1\n ORDER BY created_at DESC\n ",+ "query": "\n SELECT id, fusionauth_user_id, macro_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1\n ORDER BY created_at DESC\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -66,8 +71,9 @@false,false,false,+ false,false]},- "hash": "95c5d4f79e729713642efcda97838eddd466c0ec2ec9f96ae2be185ef9ff1547"+ "hash": "484391893f69c9fce4d47c7daeb46dca050ac95aa1f247654f6a3820f78552ee"}diff --git a/rust/cloud-storage/.sqlx/query-7bdcbf27b9edb2a2efc0e30c83230f6400385b295a50b48776985089d6ae3c84.json b/rust/cloud-storage/.sqlx/query-70915b2ac501f2362bb6e7feeb3db3562eb6314f08ba61d5353ae13589db230b.jsonsimilarity index 59%rename from rust/cloud-storage/.sqlx/query-7bdcbf27b9edb2a2efc0e30c83230f6400385b295a50b48776985089d6ae3c84.jsonrename to rust/cloud-storage/.sqlx/query-70915b2ac501f2362bb6e7feeb3db3562eb6314f08ba61d5353ae13589db230b.jsonindex ee23701453..11664ed99c 100644--- a/rust/cloud-storage/.sqlx/query-7bdcbf27b9edb2a2efc0e30c83230f6400385b295a50b48776985089d6ae3c84.json+++ b/rust/cloud-storage/.sqlx/query-70915b2ac501f2362bb6e7feeb3db3562eb6314f08ba61d5353ae13589db230b.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id as \"id!\", macro_id as \"macro_id!\",\n fusionauth_user_id as \"fusionauth_user_id!\",\n email_address as \"email_address!\",\n provider as \"provider!: _\",\n is_sync_active as \"is_sync_active!\",\n created_at as \"created_at!\",\n updated_at as \"updated_at!\"\n FROM (\n SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,\n el.provider, el.is_sync_active, el.created_at, el.updated_at\n FROM email_links el\n WHERE el.macro_id = $1\n UNION\n SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,\n el.provider, el.is_sync_active, el.created_at, el.updated_at\n FROM email_links el\n JOIN macro_user_links mul ON el.macro_id = mul.child_macro_id\n WHERE mul.primary_macro_id = $1\n ) AS combined\n ORDER BY created_at DESC\n ",+ "query": "\n SELECT id as \"id!\", macro_id as \"macro_id!\",\n fusionauth_user_id as \"fusionauth_user_id!\",\n email_address as \"email_address!\",\n provider as \"provider!: _\",\n is_sync_active as \"is_sync_active!\",\n is_primary as \"is_primary!\",\n created_at as \"created_at!\",\n updated_at as \"updated_at!\"\n FROM (\n SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,\n el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_at\n FROM email_links el\n WHERE el.macro_id = $1\n UNION\n SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,\n el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_at\n FROM email_links el\n JOIN macro_user_links mul ON el.macro_id = mul.child_macro_id\n WHERE mul.primary_macro_id = $1\n ) AS combined\n ORDER BY created_at DESC\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary!",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at!","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at!","type_info": "Timestamptz"}@@ -66,8 +71,9 @@null,null,null,+ null,null]},- "hash": "7bdcbf27b9edb2a2efc0e30c83230f6400385b295a50b48776985089d6ae3c84"+ "hash": "70915b2ac501f2362bb6e7feeb3db3562eb6314f08ba61d5353ae13589db230b"}diff --git a/rust/cloud-storage/.sqlx/query-8a1debc8a93f83a63f33dfd12a1eb8f707e99f0a207a9b34f27848ab362a7bff.json b/rust/cloud-storage/.sqlx/query-8c27c21ce4b8a231459f68a1ecfd08a56170c1fb420a4f09ed2d997664081cb7.jsonsimilarity index 82%rename from rust/cloud-storage/.sqlx/query-8a1debc8a93f83a63f33dfd12a1eb8f707e99f0a207a9b34f27848ab362a7bff.jsonrename to rust/cloud-storage/.sqlx/query-8c27c21ce4b8a231459f68a1ecfd08a56170c1fb420a4f09ed2d997664081cb7.jsonindex d389ea18d1..c0d914f931 100644--- a/rust/cloud-storage/.sqlx/query-8a1debc8a93f83a63f33dfd12a1eb8f707e99f0a207a9b34f27848ab362a7bff.json+++ b/rust/cloud-storage/.sqlx/query-8c27c21ce4b8a231459f68a1ecfd08a56170c1fb420a4f09ed2d997664081cb7.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE email_address = $1 AND provider = $2\n LIMIT 1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE email_address = $1 AND provider = $2\n LIMIT 1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -76,8 +81,9 @@false,false,false,+ false,false]},- "hash": "8a1debc8a93f83a63f33dfd12a1eb8f707e99f0a207a9b34f27848ab362a7bff"+ "hash": "8c27c21ce4b8a231459f68a1ecfd08a56170c1fb420a4f09ed2d997664081cb7"}diff --git a/rust/cloud-storage/.sqlx/query-2c1df8ba2035cc1f63f9d566e8ac763f4d0b5e28370570971935d29237a0211a.json b/rust/cloud-storage/.sqlx/query-97c68b141af174883700c5184428b2e33f43a23f900df1a8a68acfa046af7dca.jsonsimilarity index 69%rename from rust/cloud-storage/.sqlx/query-2c1df8ba2035cc1f63f9d566e8ac763f4d0b5e28370570971935d29237a0211a.jsonrename to rust/cloud-storage/.sqlx/query-97c68b141af174883700c5184428b2e33f43a23f900df1a8a68acfa046af7dca.jsonindex 4e5c86734c..d5d0150406 100644--- a/rust/cloud-storage/.sqlx/query-2c1df8ba2035cc1f63f9d566e8ac763f4d0b5e28370570971935d29237a0211a.json+++ b/rust/cloud-storage/.sqlx/query-97c68b141af174883700c5184428b2e33f43a23f900df1a8a68acfa046af7dca.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as \"provider: _\",\n l.is_sync_active, l.created_at, l.updated_at\n FROM email_threads t\n JOIN email_links l ON l.id = t.link_id\n WHERE t.id = $1\n AND (\n l.macro_id = $2\n OR EXISTS (\n SELECT 1 FROM macro_user_links mul\n WHERE mul.child_macro_id = l.macro_id AND mul.primary_macro_id = $2\n )\n )\n ",+ "query": "\n SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as \"provider: _\",\n l.is_sync_active, l.is_primary, l.created_at, l.updated_at\n FROM email_messages m\n JOIN email_links l ON l.id = m.link_id\n WHERE m.id = $1\n AND (\n l.macro_id = $2\n OR EXISTS (\n SELECT 1 FROM macro_user_links mul\n WHERE mul.child_macro_id = l.macro_id AND mul.primary_macro_id = $2\n )\n )\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -67,8 +72,9 @@false,false,false,+ false,false]},- "hash": "2c1df8ba2035cc1f63f9d566e8ac763f4d0b5e28370570971935d29237a0211a"+ "hash": "97c68b141af174883700c5184428b2e33f43a23f900df1a8a68acfa046af7dca"}diff --git a/rust/cloud-storage/.sqlx/query-15b00cf9b57c2c077f7e55bd25c267a6cf83c9efdc10ba23981f7b85847881c3.json b/rust/cloud-storage/.sqlx/query-c709131deddbceb7a7ce6643b03bf9144b089fab54e5f4bdba5d434288d48e6d.jsonsimilarity index 81%rename from rust/cloud-storage/.sqlx/query-15b00cf9b57c2c077f7e55bd25c267a6cf83c9efdc10ba23981f7b85847881c3.jsonrename to rust/cloud-storage/.sqlx/query-c709131deddbceb7a7ce6643b03bf9144b089fab54e5f4bdba5d434288d48e6d.jsonindex ef0ebb8a40..cfd3730af2 100644--- a/rust/cloud-storage/.sqlx/query-15b00cf9b57c2c077f7e55bd25c267a6cf83c9efdc10ba23981f7b85847881c3.json+++ b/rust/cloud-storage/.sqlx/query-c709131deddbceb7a7ce6643b03bf9144b089fab54e5f4bdba5d434288d48e6d.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at \n FROM email_links\n WHERE macro_id = $1\n ORDER BY created_at DESC\n LIMIT 1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE macro_id = $1\n LIMIT 1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -66,8 +71,9 @@false,false,false,+ false,false]},- "hash": "15b00cf9b57c2c077f7e55bd25c267a6cf83c9efdc10ba23981f7b85847881c3"+ "hash": "c709131deddbceb7a7ce6643b03bf9144b089fab54e5f4bdba5d434288d48e6d"}diff --git a/rust/cloud-storage/.sqlx/query-4a8b04d2fa922cd2f007241f83d6ad7e4dbcb5e7f6b0560316ca474878971e63.json b/rust/cloud-storage/.sqlx/query-e2e0c6c7322fd239a3343b6955444f41762de3f0a32cd6fed9bbacfb86d28861.jsonsimilarity index 81%rename from rust/cloud-storage/.sqlx/query-4a8b04d2fa922cd2f007241f83d6ad7e4dbcb5e7f6b0560316ca474878971e63.jsonrename to rust/cloud-storage/.sqlx/query-e2e0c6c7322fd239a3343b6955444f41762de3f0a32cd6fed9bbacfb86d28861.jsonindex c905db25bd..dbe536553b 100644--- a/rust/cloud-storage/.sqlx/query-4a8b04d2fa922cd2f007241f83d6ad7e4dbcb5e7f6b0560316ca474878971e63.json+++ b/rust/cloud-storage/.sqlx/query-e2e0c6c7322fd239a3343b6955444f41762de3f0a32cd6fed9bbacfb86d28861.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1 AND email_address = $2 AND provider = $3\n LIMIT 1\n ",+ "query": "\n SELECT id, macro_id, fusionauth_user_id, email_address, provider as \"provider: _\",\n is_sync_active, is_primary, created_at, updated_at\n FROM email_links\n WHERE fusionauth_user_id = $1 AND email_address = $2 AND provider = $3\n LIMIT 1\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -77,8 +82,9 @@false,false,false,+ false,false]},- "hash": "4a8b04d2fa922cd2f007241f83d6ad7e4dbcb5e7f6b0560316ca474878971e63"+ "hash": "e2e0c6c7322fd239a3343b6955444f41762de3f0a32cd6fed9bbacfb86d28861"}diff --git a/rust/cloud-storage/.sqlx/query-a81b373188c98bdfa52a878a659909f73796aef0302323f7930fe4d17ccfe6af.json b/rust/cloud-storage/.sqlx/query-e5389ae52536642246f7dd1b3a856d04bef89e61515707fe7dee51dcd5733c98.jsonsimilarity index 69%rename from rust/cloud-storage/.sqlx/query-a81b373188c98bdfa52a878a659909f73796aef0302323f7930fe4d17ccfe6af.jsonrename to rust/cloud-storage/.sqlx/query-e5389ae52536642246f7dd1b3a856d04bef89e61515707fe7dee51dcd5733c98.jsonindex c03715ba1e..a952d45687 100644--- a/rust/cloud-storage/.sqlx/query-a81b373188c98bdfa52a878a659909f73796aef0302323f7930fe4d17ccfe6af.json+++ b/rust/cloud-storage/.sqlx/query-e5389ae52536642246f7dd1b3a856d04bef89e61515707fe7dee51dcd5733c98.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as \"provider: _\",\n l.is_sync_active, l.created_at, l.updated_at\n FROM email_messages m\n JOIN email_links l ON l.id = m.link_id\n WHERE m.id = $1\n AND (\n l.macro_id = $2\n OR EXISTS (\n SELECT 1 FROM macro_user_links mul\n WHERE mul.child_macro_id = l.macro_id AND mul.primary_macro_id = $2\n )\n )\n ",+ "query": "\n SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as \"provider: _\",\n l.is_sync_active, l.is_primary, l.created_at, l.updated_at\n FROM email_threads t\n JOIN email_links l ON l.id = t.link_id\n WHERE t.id = $1\n AND (\n l.macro_id = $2\n OR EXISTS (\n SELECT 1 FROM macro_user_links mul\n WHERE mul.child_macro_id = l.macro_id AND mul.primary_macro_id = $2\n )\n )\n ","describe": {"columns": [{@@ -44,11 +44,16 @@},{"ordinal": 6,+ "name": "is_primary",+ "type_info": "Bool"+ },+ {+ "ordinal": 7,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "updated_at","type_info": "Timestamptz"}@@ -67,8 +72,9 @@false,false,false,+ false,false]},- "hash": "a81b373188c98bdfa52a878a659909f73796aef0302323f7930fe4d17ccfe6af"+ "hash": "e5389ae52536642246f7dd1b3a856d04bef89e61515707fe7dee51dcd5733c98"}diff --git a/rust/cloud-storage/email/src/domain/models/link.rs b/rust/cloud-storage/email/src/domain/models/link.rsindex fc025bc3bd..85d997fb67 100644--- a/rust/cloud-storage/email/src/domain/models/link.rs+++ b/rust/cloud-storage/email/src/domain/models/link.rs@@ -24,6 +24,7 @@ pub struct Link {pub email_address: EmailStr<'static>,pub provider: UserProvider,pub is_sync_active: bool,+ pub is_primary: bool,pub created_at: DateTime<Utc>,pub updated_at: DateTime<Utc>,}diff --git a/rust/cloud-storage/email/src/inbound/axum/axum_impls.rs b/rust/cloud-storage/email/src/inbound/axum/axum_impls.rsindex dcaede14bb..aab9f7b7df 100644--- a/rust/cloud-storage/email/src/inbound/axum/axum_impls.rs+++ b/rust/cloud-storage/email/src/inbound/axum/axum_impls.rs@@ -12,6 +12,7 @@ use axum::{response::{IntoResponse, Response},};use axum_extra::extract::Cached;+use macro_user_id::user_id::MacroUserIdStr;use model_user::axum_extractor::{MacroUserExtractor, UserExtractorErr};use std::sync::Arc;use std::{marker::PhantomData, str::FromStr};@@ -117,14 +118,15 @@ impl IntoResponse for EmailLinkErr {/// Resolve the single inbox a mutating request targets from the caller's owned/// `links`. With an `X-Email-Link-Id` value, the matching owned link is used-/// (404 when it isn't one of theirs). Without a header, the primary inbox is-/// used — the link whose address matches the caller's account email,-/// case-insensitively, mirroring the client's primary-inbox rule. A caller with-/// no primary inbox (e.g. it was removed) must name an inbox explicitly.+/// (404 when it isn't one of theirs). Without a header, the caller's primary+/// inbox is used — their own `is_primary` link. The `macro_id` guard matters:+/// the links list includes delegated inboxes, which are primary for *their*+/// account. A caller with no primary inbox (e.g. it was removed) must name an+/// inbox explicitly.fn resolve_target_link(links: Vec<Link>,header_link_id: Option<Uuid>,- account_email: &str,+ caller: &MacroUserIdStr<'_>,) -> Result<Link, EmailLinkErr> {match header_link_id {Some(id) => links@@ -133,12 +135,7 @@ fn resolve_target_link(.ok_or(EmailLinkErr::NotFound),None => links.into_iter()- .find(|link| {- link.email_address- .0- .as_ref()- .eq_ignore_ascii_case(account_email)- })+ .find(|link| link.is_primary && &link.macro_id == caller).ok_or(EmailLinkErr::NoInboxSelected),}}@@ -169,12 +166,12 @@ wherelet header_link_id = parse_link_id_header(parts)?;let Cached(MacroUserExtractor { macro_user_id, .. }) =parts.extract_with_state(state).await?;- let account_email = macro_user_id.0.email_str().to_string();+ let caller = macro_user_id.clone();let links = <EmailRouterState<U>>::from_ref(state).inner.get_inboxes_for_macro_id(macro_user_id).await?;- let link = resolve_target_link(links, header_link_id, &account_email)?;+ let link = resolve_target_link(links, header_link_id, &caller)?;Ok(Self(link, PhantomData))}}diff --git a/rust/cloud-storage/email/src/inbound/axum/axum_impls/test.rs b/rust/cloud-storage/email/src/inbound/axum/axum_impls/test.rsindex 1897421971..9f60a56fa9 100644--- a/rust/cloud-storage/email/src/inbound/axum/axum_impls/test.rs+++ b/rust/cloud-storage/email/src/inbound/axum/axum_impls/test.rs@@ -4,66 +4,96 @@ use chrono::Utc;use macro_user_id::{email::EmailStr, user_id::MacroUserIdStr};use uuid::Uuid;-fn test_link(id: Uuid, email: &str) -> Link {+fn test_link(id: Uuid, owner: &str, email: &str, is_primary: bool) -> Link {Link {id,- macro_id: MacroUserIdStr::try_from_email("[email protected]").unwrap(),+ macro_id: MacroUserIdStr::try_from_email(owner).unwrap(),fusionauth_user_id: "fa-user".to_string(),email_address: EmailStr::try_from(email.to_string()).unwrap(),provider: UserProvider::Gmail,is_sync_active: true,+ is_primary,created_at: Utc::now(),updated_at: Utc::now(),}}+fn caller() -> MacroUserIdStr<'static> {+ MacroUserIdStr::try_from_email("[email protected]").unwrap()+}+#[test]fn header_selects_owned_link() {let id1 = Uuid::from_u128(1);let id2 = Uuid::from_u128(2);let links = vec![- test_link(id1, "[email protected]"),- test_link(id2, "[email protected]"),+ test_link(id1, "[email protected]", "[email protected]", true),+ test_link(id2, "[email protected]", "[email protected]", false),];- let resolved = resolve_target_link(links, Some(id2), "[email protected]").unwrap();+ let resolved = resolve_target_link(links, Some(id2), &caller()).unwrap();assert_eq!(resolved.id, id2);}#[test]fn header_for_unowned_link_is_not_found() {- let links = vec![test_link(Uuid::from_u128(1), "[email protected]")];- let result = resolve_target_link(links, Some(Uuid::from_u128(99)), "[email protected]");+ let links = vec![test_link(+ Uuid::from_u128(1),+ "[email protected]",+ "[email protected]",+ true,+ )];+ let result = resolve_target_link(links, Some(Uuid::from_u128(99)), &caller());assert!(matches!(result, Err(EmailLinkErr::NotFound)));}#[test]-fn no_header_falls_back_to_primary_email_match() {+fn no_header_falls_back_to_callers_primary() {let primary = Uuid::from_u128(1);let links = vec![- test_link(Uuid::from_u128(2), "[email protected]"),- test_link(primary, "[email protected]"),+ test_link(+ Uuid::from_u128(2),+ "[email protected]",+ "[email protected]",+ false,+ ),+ test_link(primary, "[email protected]", "[email protected]", true),];- let resolved = resolve_target_link(links, None, "[email protected]").unwrap();+ let resolved = resolve_target_link(links, None, &caller()).unwrap();assert_eq!(resolved.id, primary);}#[test]-fn primary_match_is_case_insensitive() {- let primary = Uuid::from_u128(1);- let links = vec![test_link(primary, "[email protected]")];- let resolved = resolve_target_link(links, None, "[email protected]").unwrap();- assert_eq!(resolved.id, primary);+fn delegated_primary_is_not_the_callers_primary() {+ // A delegated inbox is primary for its own account; without the macro_id+ // guard it would be picked as the caller's default target.+ let own_primary = Uuid::from_u128(1);+ let links = vec![+ test_link(+ Uuid::from_u128(2),+ "[email protected]",+ "[email protected]",+ true,+ ),+ test_link(own_primary, "[email protected]", "[email protected]", true),+ ];+ let resolved = resolve_target_link(links, None, &caller()).unwrap();+ assert_eq!(resolved.id, own_primary);}#[test]fn no_header_and_no_primary_is_rejected() {- let links = vec![test_link(Uuid::from_u128(2), "[email protected]")];- let result = resolve_target_link(links, None, "[email protected]");+ let links = vec![test_link(+ Uuid::from_u128(2),+ "[email protected]",+ "[email protected]",+ false,+ )];+ let result = resolve_target_link(links, None, &caller());assert!(matches!(result, Err(EmailLinkErr::NoInboxSelected)));}#[test]fn no_links_at_all_is_rejected() {- let result = resolve_target_link(vec![], None, "[email protected]");+ let result = resolve_target_link(vec![], None, &caller());assert!(matches!(result, Err(EmailLinkErr::NoInboxSelected)));}diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rsindex 055642f33a..a2cf3cd006 100644--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/db_types.rs@@ -160,6 +160,7 @@ pub(crate) struct DbLink {pub email_address: String,pub provider: DbUserProvider,pub is_sync_active: bool,+ pub is_primary: bool,pub created_at: DateTime<Utc>,pub updated_at: DateTime<Utc>,}@@ -475,6 +476,7 @@ impl DbLink {email_address,provider,is_sync_active,+ is_primary,created_at,updated_at,} = self;@@ -486,6 +488,7 @@ impl DbLink {email_address: EmailStr::try_from(email_address)?,provider: DbUserProvider::mirror(provider),is_sync_active,+ is_primary,created_at,updated_at,})diff --git a/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs b/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rsindex f96826c4f8..18c355d467 100644--- a/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs+++ b/rust/cloud-storage/email/src/outbound/email_pg_repo/link.rs@@ -20,7 +20,7 @@ pub(super) async fn link_by_fusionauth_and_macro_id(DbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE fusionauth_user_id = $1 AND macro_id = $2 AND provider = $3LIMIT 1@@ -53,7 +53,7 @@ pub(super) async fn link_by_fusionauth_email_provider(DbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE fusionauth_user_id = $1 AND email_address = $2 AND provider = $3LIMIT 1@@ -81,7 +81,7 @@ pub(super) async fn owned_link_for_thread(DbLink,r#"SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as "provider: _",- l.is_sync_active, l.created_at, l.updated_at+ l.is_sync_active, l.is_primary, l.created_at, l.updated_atFROM email_threads tJOIN email_links l ON l.id = t.link_idWHERE t.id = $1@@ -114,7 +114,7 @@ pub(super) async fn link_by_macro_id(DbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE macro_id = $1LIMIT 1@@ -143,16 +143,17 @@ pub(super) async fn inboxes_for_macro_id(email_address as "email_address!",provider as "provider!: _",is_sync_active as "is_sync_active!",+ is_primary as "is_primary!",created_at as "created_at!",updated_at as "updated_at!"FROM (SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,- el.provider, el.is_sync_active, el.created_at, el.updated_at+ el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_atFROM email_links elWHERE el.macro_id = $1UNIONSELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,- el.provider, el.is_sync_active, el.created_at, el.updated_at+ el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_atFROM email_links elJOIN macro_user_links mul ON el.macro_id = mul.child_macro_idWHERE mul.primary_macro_id = $1diff --git a/rust/cloud-storage/email_db_client/src/links/get.rs b/rust/cloud-storage/email_db_client/src/links/get.rsindex 9031ae1f4d..10ac329d6f 100644--- a/rust/cloud-storage/email_db_client/src/links/get.rs+++ b/rust/cloud-storage/email_db_client/src/links/get.rs@@ -24,7 +24,7 @@ pub async fn fetch_link_by_email(DbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE email_address = $1 AND provider = $2LIMIT 1@@ -52,7 +52,7 @@ pub async fn fetch_link_by_macro_id(DbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE macro_id = $1ORDER BY created_at DESC@@ -88,16 +88,17 @@ pub async fn fetch_inboxes_for_macro_id(email_address as "email_address!",provider as "provider!: _",is_sync_active as "is_sync_active!",+ is_primary as "is_primary!",created_at as "created_at!",updated_at as "updated_at!"FROM (SELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,- el.provider, el.is_sync_active, el.created_at, el.updated_at+ el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_atFROM email_links elWHERE el.macro_id = $1UNIONSELECT el.id, el.macro_id, el.fusionauth_user_id, el.email_address,- el.provider, el.is_sync_active, el.created_at, el.updated_at+ el.provider, el.is_sync_active, el.is_primary, el.created_at, el.updated_atFROM email_links elJOIN macro_user_links mul ON el.macro_id = mul.child_macro_idWHERE mul.primary_macro_id = $1@@ -131,7 +132,7 @@ pub async fn fetch_links_by_fusionauth_user_id(DbLink,r#"SELECT id, fusionauth_user_id, macro_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE fusionauth_user_id = $1ORDER BY created_at DESC@@ -166,7 +167,7 @@ pub async fn fetch_owned_link_for_thread(DbLink,r#"SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as "provider: _",- l.is_sync_active, l.created_at, l.updated_at+ l.is_sync_active, l.is_primary, l.created_at, l.updated_atFROM email_threads tJOIN email_links l ON l.id = t.link_idWHERE t.id = $1@@ -199,7 +200,7 @@ pub async fn fetch_owned_link_for_message(DbLink,r#"SELECT l.id, l.macro_id, l.fusionauth_user_id, l.email_address, l.provider as "provider: _",- l.is_sync_active, l.created_at, l.updated_at+ l.is_sync_active, l.is_primary, l.created_at, l.updated_atFROM email_messages mJOIN email_links l ON l.id = m.link_idWHERE m.id = $1@@ -228,7 +229,7 @@ pub async fn fetch_link_by_id(pool: &PgPool, link_id: Uuid) -> anyhow::Result<OpDbLink,r#"SELECT id, macro_id, fusionauth_user_id, email_address, provider as "provider: _",- is_sync_active, created_at, updated_at+ is_sync_active, is_primary, created_at, updated_atFROM email_linksWHERE id = $1"#,diff --git a/rust/cloud-storage/email_db_client/src/links/insert.rs b/rust/cloud-storage/email_db_client/src/links/insert.rsindex 943e417b44..504c2c5166 100644--- a/rust/cloud-storage/email_db_client/src/links/insert.rs+++ b/rust/cloud-storage/email_db_client/src/links/insert.rs@@ -9,6 +9,7 @@ mod test;struct LinkId {id: Uuid,+ is_primary: bool,}/// Upserts a link record with the provided Link struct.@@ -31,6 +32,7 @@ pub async fn upsert_link(email_address,provider,is_sync_active,+ is_primary: _,created_at,updated_at,} = service_link;@@ -46,7 +48,7 @@ pub async fn upsert_link(DO UPDATE SETis_sync_active = EXCLUDED.is_sync_active,updated_at = NOW()- RETURNING id+ RETURNING id, is_primary"#,id,macro_id.as_ref(),@@ -65,6 +67,7 @@ pub async fn upsert_link(email_address,provider,is_sync_active,+ is_primary: result.is_primary,created_at,updated_at,};diff --git a/rust/cloud-storage/email_db_client/src/links/insert/test.rs b/rust/cloud-storage/email_db_client/src/links/insert/test.rsindex ccb6e49890..0a6b2bc4e8 100644--- a/rust/cloud-storage/email_db_client/src/links/insert/test.rs+++ b/rust/cloud-storage/email_db_client/src/links/insert/test.rs@@ -24,6 +24,7 @@ async fn upsert_link_in_transaction_persists_divergent_ids(email_address: EmailStr::try_from(child_email.to_string())?,provider: UserProvider::Gmail,is_sync_active: true,+ is_primary: true,created_at: Default::default(),updated_at: Default::default(),};diff --git a/rust/cloud-storage/email_db_client/src/links/types.rs b/rust/cloud-storage/email_db_client/src/links/types.rsindex 8f65e69093..53fbe0af99 100644--- a/rust/cloud-storage/email_db_client/src/links/types.rs+++ b/rust/cloud-storage/email_db_client/src/links/types.rs@@ -27,6 +27,7 @@ pub struct DbLink {pub email_address: String,pub provider: DbUserProvider,pub is_sync_active: bool,+ pub is_primary: bool,pub created_at: DateTime<Utc>,pub updated_at: DateTime<Utc>,}@@ -47,6 +48,7 @@ impl From<models_email::email::service::link::Link> for DbLink {models_email::service::link::UserProvider::Gmail => DbUserProvider::Gmail,},is_sync_active: service_link.is_sync_active,+ is_primary: service_link.is_primary,created_at: service_link.created_at,updated_at: service_link.updated_at,}@@ -64,6 +66,7 @@ impl TryFrom<DbLink> for models_email::email::service::link::Link {email_address,provider,is_sync_active,+ is_primary,created_at,updated_at,} = value;@@ -76,6 +79,7 @@ impl TryFrom<DbLink> for models_email::email::service::link::Link {DbUserProvider::Gmail => UserProvider::Gmail,},is_sync_active,+ is_primary,created_at,updated_at,})diff --git a/rust/cloud-storage/email_service/src/api/email/init.rs b/rust/cloud-storage/email_service/src/api/email/init.rsindex cebf2e0bb6..7b7526c223 100644--- a/rust/cloud-storage/email_service/src/api/email/init.rs+++ b/rust/cloud-storage/email_service/src/api/email/init.rs@@ -648,13 +648,16 @@ async fn enable_gmail_sync_for(email_address: &str,history_id: &str,) -> Result<Link, InitError> {+ let email_address = EmailStr::try_from(email_address.to_string())?;+ let is_primary = link::Link::derive_is_primary(¯o_id, &email_address);let link = link::Link {id: macro_uuid::generate_uuid_v7(),macro_id,fusionauth_user_id: fusion_user_id.to_string(),- email_address: EmailStr::try_from(email_address.to_string())?,+ email_address,provider: link::UserProvider::Gmail,is_sync_active: true,+ is_primary,created_at: Default::default(),updated_at: Default::default(),};diff --git a/rust/cloud-storage/email_service/src/api/email/links/list.rs b/rust/cloud-storage/email_service/src/api/email/links/list.rsindex efe740000a..2375a0a5c6 100644--- a/rust/cloud-storage/email_service/src/api/email/links/list.rs+++ b/rust/cloud-storage/email_service/src/api/email/links/list.rs@@ -77,12 +77,6 @@ pub async fn list_links_handler(let tasks = links.into_iter().map(|link| {let ctx = ctx.clone();- // Secondary mailbox (email differs from its macro user's own) = inbox-only, not a user.- let is_inbox_only = !link- .email_address- .0- .as_ref()- .eq_ignore_ascii_case(link.macro_id.email_str());async move {let settings = email_db_client::settings::fetch_settings(&ctx.db, link.id).await@@ -132,7 +126,6 @@ pub async fn list_links_handler(api::settings::Settings::from(settings),sync_status,photo_url,- is_inbox_only,))}});diff --git a/rust/cloud-storage/email_service/src/api/middleware/link.rs b/rust/cloud-storage/email_service/src/api/middleware/link.rsindex d075bfa681..de112cbecc 100644--- a/rust/cloud-storage/email_service/src/api/middleware/link.rs+++ b/rust/cloud-storage/email_service/src/api/middleware/link.rs@@ -30,6 +30,7 @@ pub(in crate::api) async fn attach_link_context<U: EmailService>(email_address: link.email_address.clone(),provider,is_sync_active: link.is_sync_active,+ is_primary: link.is_primary,created_at: link.created_at,updated_at: link.updated_at,});diff --git a/rust/cloud-storage/macro_db_client/src/shared_inbox/test.rs b/rust/cloud-storage/macro_db_client/src/shared_inbox/test.rsindex 8194e2b541..4871795ca6 100644--- a/rust/cloud-storage/macro_db_client/src/shared_inbox/test.rs+++ b/rust/cloud-storage/macro_db_client/src/shared_inbox/test.rs@@ -72,7 +72,7 @@ async fn promote_dedups_to_single_link_with_two_edges(pool: Pool<Postgres>) -> aassert_eq!(links[0].id, link_id);assert_eq!(links[0].macro_id, mailbox_macro_id);- // is_inbox_only is computed as `link.email != macro_id's email`. The minted macro_id+ // is_primary is generated as `link.email == macro_id's email`. The minted macro_id// embeds the mailbox email, so the promoted mailbox is a real shared user, not inbox-only.let mailbox_user = sqlx::query!(r#"SELECT email FROM "User" WHERE id = $1"#,diff --git a/rust/cloud-storage/models_email/src/email/api/link.rs b/rust/cloud-storage/models_email/src/email/api/link.rsindex d5b9ea176c..79207c0254 100644--- a/rust/cloud-storage/models_email/src/email/api/link.rs+++ b/rust/cloud-storage/models_email/src/email/api/link.rs@@ -82,7 +82,7 @@ pub struct Link {pub sync_status: SyncStatus,pub signature: Option<String>,pub settings: Settings,- pub is_inbox_only: bool,+ pub is_primary: bool,pub created_at: DateTime<Utc>,pub updated_at: DateTime<Utc>,}@@ -94,7 +94,6 @@ impl Link {settings: Settings,sync_status: SyncStatus,photo_url: Option<String>,- is_inbox_only: bool,) -> Self {Link {id: source.id,@@ -107,7 +106,7 @@ impl Link {sync_status,signature,settings,- is_inbox_only,+ is_primary: source.is_primary,created_at: source.created_at,updated_at: source.updated_at,}diff --git a/rust/cloud-storage/models_email/src/email/service/link.rs b/rust/cloud-storage/models_email/src/email/service/link.rsindex c1b9891ba0..a7cfe3e336 100644--- a/rust/cloud-storage/models_email/src/email/service/link.rs+++ b/rust/cloud-storage/models_email/src/email/service/link.rs@@ -14,10 +14,22 @@ pub struct Link {pub email_address: EmailStr<'static>,pub provider: UserProvider,pub is_sync_active: bool,+ pub is_primary: bool,pub created_at: DateTime<Utc>,pub updated_at: DateTime<Utc>,}+impl Link {+ /// Client-side mirror of the `email_links.is_primary` generated column,+ /// for constructing a [`Link`] that hasn't been persisted yet.+ pub fn derive_is_primary(macro_id: &MacroUserIdStr<'_>, email_address: &EmailStr<'_>) -> bool {+ email_address+ .0+ .as_ref()+ .eq_ignore_ascii_case(macro_id.email_str())+ }+}+#[derive(Debug, Clone, Copy, ToSchema, Serialize, Deserialize, PartialEq, Eq)]pub enum UserProvider {Gmail,diff --git a/rust/cloud-storage/seed_cli/src/entity/email/mod.rs b/rust/cloud-storage/seed_cli/src/entity/email/mod.rsindex 6e201b420f..08988ffee1 100644--- a/rust/cloud-storage/seed_cli/src/entity/email/mod.rs+++ b/rust/cloud-storage/seed_cli/src/entity/email/mod.rs@@ -428,6 +428,8 @@ async fn seed(args: SeedArgs, ctx: SeedCliContext) -> anyhow::Result<()> {let email_str = macro_user_id::email::EmailStr::try_from(seed_data.email_address.clone()).context("failed to parse email address")?;+ let is_primary =+ models_email::email::service::link::Link::derive_is_primary(¯o_id, &email_str);let link = models_email::email::service::link::Link {id: Uuid::now_v7(),macro_id,@@ -435,6 +437,7 @@ async fn seed(args: SeedArgs, ctx: SeedCliContext) -> anyhow::Result<()> {email_address: email_str,provider: seed_data.provider,is_sync_active: true,+ is_primary,created_at: now,updated_at: now,};diff --git a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rsindex 8ed8edbb24..f743febfbe 100644--- a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs+++ b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs@@ -148,6 +148,7 @@ impl EmailService for MockEmail {email_address: EmailStr::try_from("[email protected]".to_string()).unwrap(),provider: UserProvider::Gmail,is_sync_active: true,+ is_primary: true,created_at: Default::default(),updated_at: Default::default(),}))