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
{
"db_name": "PostgreSQL",
"query": "\n WITH thread_owner AS (\n SELECT el.macro_id\n FROM email_threads t\n JOIN email_links el ON el.id = t.link_id\n WHERE t.id = $1::uuid\n ),\n shared_teams AS (\n -- Teams the requester shares with the owner that have CRM enabled.\n SELECT tcs.team_id, requester.team_role\n FROM team_user requester\n JOIN team_user owner_member ON owner_member.team_id = requester.team_id\n JOIN thread_owner o ON o.macro_id = owner_member.user_id\n JOIN team_crm_settings tcs ON tcs.team_id = requester.team_id\n WHERE requester.user_id = $2\n AND tcs.crm_enabled\n ),\n participants AS (\n -- Distinct addresses across from + to/cc/bcc on the thread.\n SELECT DISTINCT LOWER(ec.email_address) AS email\n FROM email_messages m\n JOIN email_contacts ec ON ec.id = m.from_contact_id\n WHERE m.thread_id = $1::uuid\n UNION\n SELECT DISTINCT LOWER(ec.email_address)\n FROM email_messages m\n JOIN email_message_recipients r ON r.message_id = m.id\n JOIN email_contacts ec ON ec.id = r.contact_id\n WHERE m.thread_id = $1::uuid\n )\n SELECT EXISTS (\n SELECT 1\n FROM shared_teams st\n -- Require at least one *external* participant (outside the\n -- requester's own email domain). A purely-internal thread\n -- shouldn't grant CRM access.\n WHERE EXISTS (\n SELECT 1\n FROM participants p\n WHERE split_part(p.email, '@', 2) <> split_part(LOWER($2), '@', 2)\n )\n AND NOT EXISTS (\n -- An external participant flagged for opt-out on this\n -- team. email_sync=false blocks everyone; hidden flags\n -- only block plain members.\n SELECT 1\n FROM participants p\n JOIN crm_contacts ct ON ct.email = p.email\n -- Contacts without a company opt out through their own\n -- hidden flag; email_sync is a company setting.\n LEFT JOIN crm_companies c ON c.id = ct.company_id\n WHERE ct.team_id = st.team_id\n AND split_part(p.email, '@', 2) <> split_part(LOWER($2), '@', 2)\n AND (\n NOT COALESCE(c.email_sync, TRUE)\n OR (\n (ct.hidden OR COALESCE(c.hidden, FALSE))\n AND st.team_role = 'member'\n )\n )\n )\n ) AS \"granted!\"\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "granted!",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Uuid",
"Text"
]
},
"nullable": [
null
]
},
"hash": "7b6ed1f5c16cb312ee16e61275744c94dae291af6960f63b1e3b4f36bc9f9234"
}