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): return all calls you have access to in soup (#2621)
Will Hutchinson6dd80d5e607a
diff --git a/rust/cloud-storage/call/.sqlx/query-4fbbbf3257ecffd107a3d848ab980c51f5a28b25de618cd976b9871b0d6bcdec.json b/rust/cloud-storage/call/.sqlx/query-ff145480985a4aa38e3b7c9394dfb9eb8724cdab4a668bc88f1d5fdcae4fa689.jsonsimilarity index 59%rename from rust/cloud-storage/call/.sqlx/query-4fbbbf3257ecffd107a3d848ab980c51f5a28b25de618cd976b9871b0d6bcdec.jsonrename to rust/cloud-storage/call/.sqlx/query-ff145480985a4aa38e3b7c9394dfb9eb8724cdab4a668bc88f1d5fdcae4fa689.jsonindex aac1f77fbe..1c9bfc5c7c 100644--- a/rust/cloud-storage/call/.sqlx/query-4fbbbf3257ecffd107a3d848ab980c51f5a28b25de618cd976b9871b0d6bcdec.json+++ b/rust/cloud-storage/call/.sqlx/query-ff145480985a4aa38e3b7c9394dfb9eb8724cdab4a668bc88f1d5fdcae4fa689.json@@ -1,6 +1,6 @@{"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 true as \"is_active!\"\n FROM calls c\n WHERE EXISTS (\n SELECT 1 FROM call_participants cp\n WHERE cp.call_id = c.id AND cp.user_id = $1 AND cp.left_at IS NULL\n )\n AND ($3::bool IS FALSE OR c.channel_id = ANY($4))\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 false as \"is_active!\"\n FROM call_records cr\n WHERE EXISTS (\n SELECT 1 FROM call_record_participants crp\n WHERE crp.call_record_id = cr.id AND crp.user_id = $1\n )\n AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))\n ORDER BY \"started_at!\" DESC\n LIMIT $2\n ",+ "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 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 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 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 ORDER BY \"started_at!\" DESC\n LIMIT $2\n ","describe": {"columns": [{@@ -75,5 +75,5 @@null]},- "hash": "4fbbbf3257ecffd107a3d848ab980c51f5a28b25de618cd976b9871b0d6bcdec"+ "hash": "ff145480985a4aa38e3b7c9394dfb9eb8724cdab4a668bc88f1d5fdcae4fa689"}diff --git a/rust/cloud-storage/call/fixtures/call_repo.sql b/rust/cloud-storage/call/fixtures/call_repo.sqlindex 83345a444e..43e48bef02 100644--- a/rust/cloud-storage/call/fixtures/call_repo.sql+++ b/rust/cloud-storage/call/fixtures/call_repo.sql@@ -13,6 +13,12 @@ INSERT INTO comms_channels (id, name, channel_type, org_id, owner_id, created_at('00000000-0000-0000-0000-000000000c02', 'empty-channel', 'public', NULL, 'macro|[email protected]','2024-01-01 00:00:00+00', '2024-01-01 00:00:00+00');+-- channel members for ch1 (user-c is a member but never joins a call)+INSERT INTO comms_channel_participants (channel_id, user_id, role, joined_at) VALUES+ ('00000000-0000-0000-0000-000000000c01', 'macro|[email protected]', 'owner', '2024-01-01 00:00:00+00'),+ ('00000000-0000-0000-0000-000000000c01', 'macro|[email protected]', 'member', '2024-01-01 00:00:00+00'),+ ('00000000-0000-0000-0000-000000000c01', 'macro|[email protected]', 'member', '2024-01-01 00:00:00+00');+-- share permission for call1INSERT INTO "SharePermission" (id, "isPublic", "publicAccessLevel", "createdAt", "updatedAt") VALUES('00000000-0000-0000-0000-00000000sp01', false, NULL, '2024-01-01 00:00:00+00', '2024-01-01 00:00:00+00');diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rsindex 9ad631fe19..b0907fa687 100644--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs@@ -702,8 +702,10 @@ impl CallRepository for PgCallRepo {true as "is_active!"FROM calls cWHERE EXISTS (- SELECT 1 FROM call_participants cp- WHERE cp.call_id = c.id AND cp.user_id = $1 AND cp.left_at IS NULL+ 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)AND ($3::bool IS FALSE OR c.channel_id = ANY($4))UNION ALL@@ -720,8 +722,10 @@ impl CallRepository for PgCallRepo {false as "is_active!"FROM call_records crWHERE EXISTS (- SELECT 1 FROM call_record_participants crp- WHERE crp.call_record_id = cr.id AND crp.user_id = $1+ 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)AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))ORDER BY "started_at!" DESCdiff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rsindex dc9595628f..49efb7bc93 100644--- a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs@@ -618,3 +618,35 @@ async fn get_call_record_returns_none_for_unknown(pool: Pool<Postgres>) -> anyhoassert!(record.is_none());Ok(())}++// -- get_call_records_by_user ------------------------------------------------++#[sqlx::test(+ fixtures(path = "../../../fixtures", scripts("call_repo")),+ migrator = "MACRO_DB_MIGRATIONS"+)]+async fn get_call_records_by_user_includes_channel_member_not_in_call(+ pool: Pool<Postgres>,+) -> anyhow::Result<()> {+ let repo = repo(pool);++ // user-c is a member of CH1 (fixture) but is NOT in call_participants+ // for CALL1 or call_record_participants for CALL_ARCHIVED. Visibility+ // should now come from channel membership, so both calls should appear.+ let records = repo+ .get_call_records_by_user(USER_C.deref().copied(), 10, &None)+ .await?;++ assert_eq!(+ records.len(),+ 2,+ "expected active + archived call for channel member"+ );+ assert!(records.iter().any(|r| r.call_id == CALL1 && r.is_active));+ assert!(+ records+ .iter()+ .any(|r| r.call_id == CALL_ARCHIVED && !r.is_active)+ );+ Ok(())+}