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
fix(call): use entity access for soup query (#2917)
Will Hutchinson89bca119dec9
diff --git a/rust/cloud-storage/.sqlx/query-7ca2625f94aef2b7062954af797b72725b7ae867499427329ef036d7d4df8e38.json b/rust/cloud-storage/.sqlx/query-7ca2625f94aef2b7062954af797b72725b7ae867499427329ef036d7d4df8e38.jsondeleted file mode 100644index b70fd661f5..0000000000--- a/rust/cloud-storage/.sqlx/query-7ca2625f94aef2b7062954af797b72725b7ae867499427329ef036d7d4df8e38.json+++ /dev/null@@ -1,86 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n room_name as \"room_name!\",\n created_by as \"created_by!\",\n created_at as \"started_at!\",\n NULL::timestamptz as \"ended_at\",\n NULL::bigint as \"duration_ms\",\n egress_id,\n recording_key,\n NULL::text as \"custom_name\",\n true as \"is_active!\"\n FROM calls c\n WHERE EXISTS (\n SELECT 1 FROM comms_channel_participants ccp\n WHERE ccp.channel_id = c.channel_id\n AND ccp.user_id = $1\n AND ccp.left_at IS NULL\n )\n AND ($3::bool IS FALSE OR c.channel_id = ANY($4))\n AND ($5::bool IS NULL OR EXISTS (\n SELECT 1 FROM call_participants cp\n WHERE cp.call_id = c.id AND cp.user_id = $1\n ) = $5)\n UNION ALL\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n room_name as \"room_name!\",\n created_by as \"created_by!\",\n started_at as \"started_at!\",\n ended_at as \"ended_at\",\n duration_ms as \"duration_ms\",\n egress_id,\n recording_key,\n custom_name,\n false as \"is_active!\"\n FROM call_records cr\n WHERE EXISTS (\n SELECT 1 FROM comms_channel_participants ccp\n WHERE ccp.channel_id = cr.channel_id\n AND ccp.user_id = $1\n AND ccp.left_at IS NULL\n )\n AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))\n AND ($5::bool IS NULL OR EXISTS (\n SELECT 1 FROM call_record_participants crp\n WHERE crp.call_record_id = cr.id AND crp.user_id = $1\n ) = $5)\n ORDER BY \"started_at!\" DESC\n LIMIT $2\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "call_id!",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "channel_id!",- "type_info": "Uuid"- },- {- "ordinal": 2,- "name": "room_name!",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "created_by!",- "type_info": "Text"- },- {- "ordinal": 4,- "name": "started_at!",- "type_info": "Timestamptz"- },- {- "ordinal": 5,- "name": "ended_at",- "type_info": "Timestamptz"- },- {- "ordinal": 6,- "name": "duration_ms",- "type_info": "Int8"- },- {- "ordinal": 7,- "name": "egress_id",- "type_info": "Text"- },- {- "ordinal": 8,- "name": "recording_key",- "type_info": "Text"- },- {- "ordinal": 9,- "name": "custom_name",- "type_info": "Text"- },- {- "ordinal": 10,- "name": "is_active!",- "type_info": "Bool"- }- ],- "parameters": {- "Left": [- "Text",- "Int8",- "Bool",- "UuidArray",- "Bool"- ]- },- "nullable": [- null,- null,- null,- null,- null,- null,- null,- null,- null,- null,- null- ]- },- "hash": "7ca2625f94aef2b7062954af797b72725b7ae867499427329ef036d7d4df8e38"-}diff --git a/rust/cloud-storage/.sqlx/query-f32009fa2fba59b598040e667eb240d0f0bef98666123d4f27fb2c3599ae6bd4.json b/rust/cloud-storage/.sqlx/query-f32009fa2fba59b598040e667eb240d0f0bef98666123d4f27fb2c3599ae6bd4.jsonnew file mode 100644index 0000000000..482dad4c2d--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-f32009fa2fba59b598040e667eb240d0f0bef98666123d4f27fb2c3599ae6bd4.json@@ -0,0 +1,86 @@+{+ "db_name": "PostgreSQL",+ "query": "\n WITH user_source_ids AS (\n SELECT cp.channel_id::text AS source_id\n FROM comms_channel_participants cp\n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n UNION ALL\n SELECT t.team_id::text AS source_id\n FROM team_user t\n WHERE t.user_id = $1\n UNION ALL\n SELECT $1 AS source_id\n )\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n room_name as \"room_name!\",\n created_by as \"created_by!\",\n created_at as \"started_at!\",\n NULL::timestamptz as \"ended_at\",\n NULL::bigint as \"duration_ms\",\n egress_id,\n recording_key,\n NULL::text as \"custom_name\",\n true as \"is_active!\"\n FROM calls c\n WHERE EXISTS (\n SELECT 1 FROM entity_access ea\n JOIN user_source_ids u ON u.source_id = ea.source_id\n WHERE ea.entity_id = c.id\n AND ea.entity_type = 'call'\n )\n AND ($3::bool IS FALSE OR c.channel_id = ANY($4))\n AND ($5::bool IS NULL OR EXISTS (\n SELECT 1 FROM call_participants cp\n WHERE cp.call_id = c.id AND cp.user_id = $1\n ) = $5)\n UNION ALL\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n room_name as \"room_name!\",\n created_by as \"created_by!\",\n started_at as \"started_at!\",\n ended_at as \"ended_at\",\n duration_ms as \"duration_ms\",\n egress_id,\n recording_key,\n custom_name,\n false as \"is_active!\"\n FROM call_records cr\n WHERE EXISTS (\n SELECT 1 FROM entity_access ea\n JOIN user_source_ids u ON u.source_id = ea.source_id\n WHERE ea.entity_id = cr.id\n AND ea.entity_type = 'call'\n )\n AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))\n AND ($5::bool IS NULL OR EXISTS (\n SELECT 1 FROM call_record_participants crp\n WHERE crp.call_record_id = cr.id AND crp.user_id = $1\n ) = $5)\n ORDER BY \"started_at!\" DESC\n LIMIT $2\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "call_id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "room_name!",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "created_by!",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "started_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 5,+ "name": "ended_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "duration_ms",+ "type_info": "Int8"+ },+ {+ "ordinal": 7,+ "name": "egress_id",+ "type_info": "Text"+ },+ {+ "ordinal": 8,+ "name": "recording_key",+ "type_info": "Text"+ },+ {+ "ordinal": 9,+ "name": "custom_name",+ "type_info": "Text"+ },+ {+ "ordinal": 10,+ "name": "is_active!",+ "type_info": "Bool"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ "Int8",+ "Bool",+ "UuidArray",+ "Bool"+ ]+ },+ "nullable": [+ null,+ null,+ null,+ null,+ null,+ null,+ null,+ null,+ null,+ null,+ null+ ]+ },+ "hash": "f32009fa2fba59b598040e667eb240d0f0bef98666123d4f27fb2c3599ae6bd4"+}diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rsindex ab28fe3a7d..2222a252de 100644--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs@@ -1025,12 +1025,29 @@ impl CallRepository for PgCallRepo {// Fetch call headers from both active and archived tables, ordered by// start time descending. We intentionally exclude transcripts (too// large for the soup feed).+ //+ // Visibility is derived from the `entity_access` table: a call is+ // visible to the user if there's an entity_access row whose+ // `source_id` matches one of the user's source ids (their+ // channel memberships, team memberships, or their own user id).+ // This mirrors `entity_access::pg_access_repo::queries::call_access`.let channel_ids = extract_channel_ids(filter);let has_channel_filter = !channel_ids.is_empty();let attended = extract_attended(filter);let rows = sqlx::query!(r#"+ WITH user_source_ids AS (+ SELECT cp.channel_id::text AS source_id+ FROM comms_channel_participants cp+ WHERE cp.user_id = $1 AND cp.left_at IS NULL+ UNION ALL+ SELECT t.team_id::text AS source_id+ FROM team_user t+ WHERE t.user_id = $1+ UNION ALL+ SELECT $1 AS source_id+ )SELECTid as "call_id!",channel_id as "channel_id!",@@ -1045,10 +1062,10 @@ impl CallRepository for PgCallRepo {true as "is_active!"FROM calls cWHERE EXISTS (- SELECT 1 FROM comms_channel_participants ccp- WHERE ccp.channel_id = c.channel_id- AND ccp.user_id = $1- AND ccp.left_at IS NULL+ SELECT 1 FROM entity_access ea+ JOIN user_source_ids u ON u.source_id = ea.source_id+ WHERE ea.entity_id = c.id+ AND ea.entity_type = 'call')AND ($3::bool IS FALSE OR c.channel_id = ANY($4))AND ($5::bool IS NULL OR EXISTS (@@ -1070,10 +1087,10 @@ impl CallRepository for PgCallRepo {false as "is_active!"FROM call_records crWHERE EXISTS (- SELECT 1 FROM comms_channel_participants ccp- WHERE ccp.channel_id = cr.channel_id- AND ccp.user_id = $1- AND ccp.left_at IS NULL+ SELECT 1 FROM entity_access ea+ JOIN user_source_ids u ON u.source_id = ea.source_id+ WHERE ea.entity_id = cr.id+ AND ea.entity_type = 'call')AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))AND ($5::bool IS NULL OR EXISTS (