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(calendar): list a meeting held through Exchange once in search (#9259)
gbirman94d5387350e6
diff --git a/.sqlx/query-0654d206e896e42d6e43ce0c2c0654958a3937c0cc6d71f06a34fcc5b404d15a.json b/.sqlx/query-7400849a711418e11e6f7ee24ad84446bc71a0e0cfe5d6b379e191d1be1f831e.jsonsimilarity index 57%rename from .sqlx/query-0654d206e896e42d6e43ce0c2c0654958a3937c0cc6d71f06a34fcc5b404d15a.jsonrename to .sqlx/query-7400849a711418e11e6f7ee24ad84446bc71a0e0cfe5d6b379e191d1be1f831e.jsonindex 2b64ab9e8f..d1ecbc0bfe 100644--- a/.sqlx/query-0654d206e896e42d6e43ce0c2c0654958a3937c0cc6d71f06a34fcc5b404d15a.json+++ b/.sqlx/query-7400849a711418e11e6f7ee24ad84446bc71a0e0cfe5d6b379e191d1be1f831e.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT DISTINCT event.id AS \"id!\"\n FROM comms_channel_participants participant\n JOIN entity_access grant_row\n ON grant_row.source_id = participant.channel_id::text\n AND grant_row.source_type = 'channel'\n AND grant_row.entity_type = 'calendar_event'\n JOIN calendar_events event ON event.id = grant_row.entity_id\n WHERE participant.user_id = $1\n AND participant.left_at IS NULL\n AND event.status <> 'cancelled'\n AND event.visibility IN ('default', 'public')\n AND NOT EXISTS (\n SELECT 1\n FROM calendar_events held\n WHERE held.ical_uid = event.ical_uid\n AND held.status <> 'cancelled'\n AND (\n held.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = held.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n )\n ",+ "query": "\n SELECT DISTINCT event.id AS \"id!\"\n FROM comms_channel_participants participant\n JOIN entity_access grant_row\n ON grant_row.source_id = participant.channel_id::text\n AND grant_row.source_type = 'channel'\n AND grant_row.entity_type = 'calendar_event'\n JOIN calendar_events event ON event.id = grant_row.entity_id\n WHERE participant.user_id = $1\n AND participant.left_at IS NULL\n AND event.status <> 'cancelled'\n AND event.visibility IN ('default', 'public')\n AND NOT EXISTS (\n SELECT 1\n FROM calendar_events held\n WHERE calendar_meeting_uid(held.ical_uid)\n = calendar_meeting_uid(event.ical_uid)\n AND held.status <> 'cancelled'\n AND (\n held.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = held.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n )\n ","describe": {"columns": [{@@ -18,5 +18,5 @@false]},- "hash": "0654d206e896e42d6e43ce0c2c0654958a3937c0cc6d71f06a34fcc5b404d15a"+ "hash": "7400849a711418e11e6f7ee24ad84446bc71a0e0cfe5d6b379e191d1be1f831e"}diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.mdindex f73e5f8304..29891c5be3 100644--- a/crates/calendar_events/AGENTS.md+++ b/crates/calendar_events/AGENTS.md@@ -318,9 +318,10 @@ reminder dispatch, team availability, and provider/Postgres persistence.UID: Exchange gives a meeting it imports from an invitation its own UID thatwraps the original after `vCal-Uid`, and the SQL function unwraps it, so anOutlook copy of a Google meeting pairs with its Google copies in- `meeting_copies`, the mention preview, `event_export` and email invitation- matching (`pg/invitations.rs`), where an Outlook inbox's invitation card- resolves to that inbox's own copy and answers as it.+ `meeting_copies`, the mention preview, `event_export`, the channel-shared+ search scope and email invitation matching (`pg/invitations.rs`), where an+ Outlook inbox's invitation card resolves to that inbox's own copy and answers+ as it.- Preserve the conservative OOO refresh hint on write outcomes and sync reports;its contract is in [team sharing](../../docs/design/calendar-team-sharing.md).- The team out-of-office overlay (`src/outbound/pg_team/ooo.rs`) starts fromdiff --git a/crates/macro_db_client/src/calendar_event/get_events_for_search.rs b/crates/macro_db_client/src/calendar_event/get_events_for_search.rsindex f4606a850a..681c922867 100644--- a/crates/macro_db_client/src/calendar_event/get_events_for_search.rs+++ b/crates/macro_db_client/src/calendar_event/get_events_for_search.rs@@ -69,11 +69,11 @@ pub struct CalendarEventSearchInfo {/// during enrichment.////// A row can be the sharer's copy of a meeting the requester also holds: an-/// id named in the own scope reaches it, and the shared scope does when the-/// copies' raw UIDs differ. `holds_meeting` therefore pairs copies the way the-/// mention preview does, by `calendar_meeting_uid`, except that a preview-/// resolves to the requester's own copy while a search row stays on the hit,-/// so a snapshot, which never had the link, must not unlock the sharer's.+/// id named in the own scope reaches it. `holds_meeting` therefore pairs+/// copies the way the mention preview does, by `calendar_meeting_uid`, except+/// that a preview resolves to the requester's own copy while a search row+/// stays on the hit, so a snapshot, which never had the link, must not unlock+/// the sharer's.////// A recurring series is indexed once, as its master, so the instance a row/// should display is decided here rather than baked into the index. The@@ -246,7 +246,14 @@ pub async fn get_calendar_events_for_search(/// A grant counts only under the event's access check (live, neither private/// nor confidential). A meeting the requester also holds, owned or through a/// delegated inbox, is left out: a mention of it resolves to their own copy,-/// which their own scope already finds.+/// which their own scope finds under the title that copy carries. This runs+/// before the search matches titles, so a held copy titled differently keeps+/// the share out of a search for the share's title.+///+/// Copies pair by `calendar_meeting_uid`, as `holds_meeting` does, but this+/// asks which row to list rather than who may read the link, so a snapshot+/// counts: it is a row of their own scope, though not a seat. A cancelled copy+/// does not, since the share is then the only row that still opens.#[tracing::instrument(skip(db, requester_id), fields(shared_event_count), err)]pub async fn get_channel_shared_calendar_event_ids(db: &Pool<Postgres>,@@ -268,7 +275,8 @@ pub async fn get_channel_shared_calendar_event_ids(AND NOT EXISTS (SELECT 1FROM calendar_events held- WHERE held.ical_uid = event.ical_uid+ WHERE calendar_meeting_uid(held.ical_uid)+ = calendar_meeting_uid(event.ical_uid)AND held.status <> 'cancelled'AND (held.owner_id = $1diff --git a/crates/macro_db_client/src/calendar_event/get_events_for_search/test.rs b/crates/macro_db_client/src/calendar_event/get_events_for_search/test.rsindex d7736989a7..36f90f6435 100644--- a/crates/macro_db_client/src/calendar_event/get_events_for_search/test.rs+++ b/crates/macro_db_client/src/calendar_event/get_events_for_search/test.rs@@ -178,6 +178,81 @@ fn exchange_uid(uid: &str) -> String {)}+#[sqlx::test]+async fn shared_ids_leave_out_a_meeting_held_under_a_wrapped_uid(pool: Pool<Postgres>) {+ const MEETING: &str = "[email protected]";+ const OUTLOOK_MEETING: &str = "[email protected]";+ let shared = insert_event(&pool, OWNER, MEETING, "default").await;+ let shared_from_outlook =+ insert_event(&pool, OWNER, &exchange_uid(OUTLOOK_MEETING), "default").await;+ let channel_id = insert_channel(&pool).await;+ share_with_channel(&pool, shared, channel_id).await;+ share_with_channel(&pool, shared_from_outlook, channel_id).await;+ let read = |user: &'static str| {+ let pool = pool.clone();+ async move {+ let mut ids = get_channel_shared_calendar_event_ids(&pool, user)+ .await+ .unwrap();+ ids.sort();+ ids+ }+ };++ // Exchange wraps the UID, but both copies are the one meeting, which the+ // holder's own scope already lists.+ let held = insert_event(&pool, ATTENDEE, &exchange_uid(MEETING), "default").await;+ insert_event(&pool, ATTENDEE, OUTLOOK_MEETING, "default").await;+ assert!(+ read(ATTENDEE).await.is_empty(),+ "a holder sees each meeting once, whichever copy wraps the UID"+ );+ assert_eq!(+ read(MEMBER).await,+ vec![shared, shared_from_outlook],+ "a member who holds no copy keeps both shares"+ );++ // A wrapped UID of some other meeting is not a copy of this one.+ sqlx::query("UPDATE calendar_events SET ical_uid = $2 WHERE id = $1")+ .bind(held)+ .bind(exchange_uid("[email protected]"))+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(ATTENDEE).await,+ vec![shared],+ "another meeting hides nothing"+ );++ // A snapshot is no seat, but it is a row of the holder's own scope.+ sqlx::query("UPDATE calendar_events SET ical_uid = $2, is_snapshot = true WHERE id = $1")+ .bind(held)+ .bind(exchange_uid(MEETING))+ .execute(&pool)+ .await+ .unwrap();+ assert!(+ read(ATTENDEE).await.is_empty(),+ "a snapshot already lists the meeting"+ );++ // A cancelled copy leaves the share as the only row that still opens.+ sqlx::query(+ "UPDATE calendar_events SET is_snapshot = false, status = 'cancelled' WHERE id = $1",+ )+ .bind(held)+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(ATTENDEE).await,+ vec![shared],+ "a cancelled copy leaves the share listed"+ );+}+#[sqlx::test]async fn only_a_seat_on_the_meeting_keeps_a_shared_row_join_link(pool: Pool<Postgres>) {const MEETING: &str = "[email protected]";diff --git a/crates/search_service/AGENTS.md b/crates/search_service/AGENTS.mdindex 574b5906f0..0550172c7b 100644--- a/crates/search_service/AGENTS.md+++ b/crates/search_service/AGENTS.md@@ -61,13 +61,16 @@ per-entity-type search plus a unified search across them — mounted intorequest): `own` matches the caller's own and delegated calendars byowner and inbox link; `shared_with_you` resolves the events shared with thecaller's channels in Postgres and searches by id, leaving out meetings the- caller holds a copy of. Enrichment re-checks every hit against the event's- access rule. A caller who does not hold the meeting gets no conference link,- and `calendar_events`' `content_without_macro_call` takes the Macro call out- of the description; a provider's own join text in the body stays, as it does- in a mention preview. Enrichment is the only gate: an id named in the `own`- scope reaches a share as well. The index stores titles, never the description- or location, so hits and highlights cannot carry the link.+ caller holds a live copy of, paired by `calendar_meeting_uid`. A snapshot+ counts there, since the `own` scope lists it, though it never counts as+ holding the meeting for the conference link. Enrichment re-checks every hit+ against the event's access rule. A caller who does not hold the meeting gets+ no conference link, and `calendar_events`' `content_without_macro_call` takes+ the Macro call out of the description; a provider's own join text in the body+ stays, as it does in a mention preview. Enrichment is the only gate: an id+ named in the `own` scope reaches a share as well. The index stores titles,+ never the description or location, so hits and highlights cannot carry the+ link.## Related