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): strip the Macro call from channel-shared search rows (#9255)
gbirmanc7e979b5a252
diff --git a/.sqlx/query-300fac63e0381a1cec1e2f171ac872c39a081468a1e77b91e547ce0e10d75fb0.json b/.sqlx/query-300fac63e0381a1cec1e2f171ac872c39a081468a1e77b91e547ce0e10d75fb0.jsonnew file mode 100644index 0000000000..a2775dbd99--- /dev/null+++ b/.sqlx/query-300fac63e0381a1cec1e2f171ac872c39a081468a1e77b91e547ce0e10d75fb0.json@@ -0,0 +1,156 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n event.id AS \"id!\",\n event.owner_id AS \"owner_id!\",\n event.title AS \"title!\",\n event.status AS \"status!\",\n event.starts_at,\n event.ends_at,\n event.start_date,\n event.end_date,\n event.time_zone,\n (cardinality(event.recurrence_lines) > 0) AS \"is_recurring!\",\n CASE WHEN meeting.holds_meeting THEN event.conference_url END AS conference_url,\n event.organizer_email,\n event.organizer_name,\n event.description,\n meeting.holds_meeting AS \"holds_meeting!\",\n event.is_read_only AS \"is_read_only!\",\n event.created_at AS \"created_at!\",\n event.updated_at AS \"updated_at!\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\"\n FROM calendar_events event\n CROSS JOIN LATERAL (\n SELECT (\n event.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = event.source_link_id\n AND link.primary_macro_id = $1\n )\n ) AS on_calendar\n ) viewer\n CROSS JOIN LATERAL (\n SELECT (\n viewer.on_calendar\n OR 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 NOT held.is_snapshot\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 ) AS holds_meeting\n ) meeting\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance_start.at >= $3) DESC,\n CASE WHEN instance_start.at >= $3 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n WHERE event.id = ANY($2)\n AND (\n viewer.on_calendar\n OR (\n event.status <> 'cancelled'\n AND event.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = event.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n )\n )\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "owner_id!",+ "type_info": "Text"+ },+ {+ "ordinal": 2,+ "name": "title!",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "status!",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "starts_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 5,+ "name": "ends_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "start_date",+ "type_info": "Date"+ },+ {+ "ordinal": 7,+ "name": "end_date",+ "type_info": "Date"+ },+ {+ "ordinal": 8,+ "name": "time_zone",+ "type_info": "Text"+ },+ {+ "ordinal": 9,+ "name": "is_recurring!",+ "type_info": "Bool"+ },+ {+ "ordinal": 10,+ "name": "conference_url",+ "type_info": "Text"+ },+ {+ "ordinal": 11,+ "name": "organizer_email",+ "type_info": "Text"+ },+ {+ "ordinal": 12,+ "name": "organizer_name",+ "type_info": "Text"+ },+ {+ "ordinal": 13,+ "name": "description",+ "type_info": "Text"+ },+ {+ "ordinal": 14,+ "name": "holds_meeting!",+ "type_info": "Bool"+ },+ {+ "ordinal": 15,+ "name": "is_read_only!",+ "type_info": "Bool"+ },+ {+ "ordinal": 16,+ "name": "created_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 17,+ "name": "updated_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 18,+ "name": "occurrence_key?",+ "type_info": "Text"+ },+ {+ "ordinal": 19,+ "name": "occurrence_starts_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 20,+ "name": "occurrence_ends_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 21,+ "name": "occurrence_start_date?",+ "type_info": "Date"+ },+ {+ "ordinal": 22,+ "name": "occurrence_end_date?",+ "type_info": "Date"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ "UuidArray",+ "Timestamptz"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ false,+ true,+ true,+ true,+ true,+ true,+ null,+ null,+ true,+ true,+ true,+ null,+ false,+ false,+ false,+ true,+ true,+ true,+ true,+ true+ ]+ },+ "hash": "300fac63e0381a1cec1e2f171ac872c39a081468a1e77b91e547ce0e10d75fb0"+}diff --git a/.sqlx/query-e37f4ad26cedd8187256b56fe295ccb90bee8396e070a7c535b8a6350c539a3d.json b/.sqlx/query-e37f4ad26cedd8187256b56fe295ccb90bee8396e070a7c535b8a6350c539a3d.jsondeleted file mode 100644index 5002b6702a..0000000000--- a/.sqlx/query-e37f4ad26cedd8187256b56fe295ccb90bee8396e070a7c535b8a6350c539a3d.json+++ /dev/null@@ -1,150 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n event.id AS \"id!\",\n event.owner_id AS \"owner_id!\",\n event.title AS \"title!\",\n event.status AS \"status!\",\n event.starts_at,\n event.ends_at,\n event.start_date,\n event.end_date,\n event.time_zone,\n (cardinality(event.recurrence_lines) > 0) AS \"is_recurring!\",\n CASE WHEN viewer.on_calendar THEN event.conference_url END AS conference_url,\n event.organizer_email,\n event.organizer_name,\n event.description,\n event.is_read_only AS \"is_read_only!\",\n event.created_at AS \"created_at!\",\n event.updated_at AS \"updated_at!\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\"\n FROM calendar_events event\n CROSS JOIN LATERAL (\n SELECT (\n event.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = event.source_link_id\n AND link.primary_macro_id = $1\n )\n ) AS on_calendar\n ) viewer\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance_start.at >= $3) DESC,\n CASE WHEN instance_start.at >= $3 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n WHERE event.id = ANY($2)\n AND (\n viewer.on_calendar\n OR (\n event.status <> 'cancelled'\n AND event.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = event.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n )\n )\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "id!",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "owner_id!",- "type_info": "Text"- },- {- "ordinal": 2,- "name": "title!",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "status!",- "type_info": "Text"- },- {- "ordinal": 4,- "name": "starts_at",- "type_info": "Timestamptz"- },- {- "ordinal": 5,- "name": "ends_at",- "type_info": "Timestamptz"- },- {- "ordinal": 6,- "name": "start_date",- "type_info": "Date"- },- {- "ordinal": 7,- "name": "end_date",- "type_info": "Date"- },- {- "ordinal": 8,- "name": "time_zone",- "type_info": "Text"- },- {- "ordinal": 9,- "name": "is_recurring!",- "type_info": "Bool"- },- {- "ordinal": 10,- "name": "conference_url",- "type_info": "Text"- },- {- "ordinal": 11,- "name": "organizer_email",- "type_info": "Text"- },- {- "ordinal": 12,- "name": "organizer_name",- "type_info": "Text"- },- {- "ordinal": 13,- "name": "description",- "type_info": "Text"- },- {- "ordinal": 14,- "name": "is_read_only!",- "type_info": "Bool"- },- {- "ordinal": 15,- "name": "created_at!",- "type_info": "Timestamptz"- },- {- "ordinal": 16,- "name": "updated_at!",- "type_info": "Timestamptz"- },- {- "ordinal": 17,- "name": "occurrence_key?",- "type_info": "Text"- },- {- "ordinal": 18,- "name": "occurrence_starts_at?",- "type_info": "Timestamptz"- },- {- "ordinal": 19,- "name": "occurrence_ends_at?",- "type_info": "Timestamptz"- },- {- "ordinal": 20,- "name": "occurrence_start_date?",- "type_info": "Date"- },- {- "ordinal": 21,- "name": "occurrence_end_date?",- "type_info": "Date"- }- ],- "parameters": {- "Left": [- "Text",- "UuidArray",- "Timestamptz"- ]- },- "nullable": [- false,- false,- false,- false,- true,- true,- true,- true,- true,- null,- null,- true,- true,- true,- false,- false,- false,- true,- true,- true,- true,- true- ]- },- "hash": "e37f4ad26cedd8187256b56fe295ccb90bee8396e070a7c535b8a6350c539a3d"-}diff --git a/Cargo.lock b/Cargo.lockindex 231aa62d03..9c00c96223 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -17611,6 +17611,7 @@ dependencies = ["anyhow","aws-sdk-secretsmanager","axum",+ "calendar_events","channels","chrono","comms_db_client",diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.mdindex f42e10777e..dfc91bbb6c 100644--- a/crates/calendar_events/AGENTS.md+++ b/crates/calendar_events/AGENTS.md@@ -37,7 +37,7 @@ reminder dispatch, team availability, and provider/Postgres persistence.`notification` (feature `notify`), `model_notifications`, `aws-sdk-sqs`(feature `dispatch-sqs`).- Used by: `email`, `ai_tools`, `channel_bots`, `graphql_calendar`, `complete_graph`,- `calendar_scheduling`.+ `calendar_scheduling`, `search_service`.## Recipes@@ -208,7 +208,9 @@ reminder dispatch, team availability, and provider/Postgres persistence.description. Whoever resolves to their own copy keeps it: the card's Joinbutton reads the link from the preview. Only the generated Macro call goes;join text a provider wrote into the body, as a Teams invitation's, stays, as- it does in a snapshot.+ it does in a snapshot. Search rows apply the same rule, but a row stays on+ the hit instead of resolving to the viewer's copy, so there a snapshot does+ not count as holding the meeting.- Google names the calendar an event was made on as its organizer, so anevent on a secondary calendar has that calendar's id(`…@group.calendar.google.com`) as `organizer_email`; Google'sdiff --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 4c4cbf9435..f4606a850a 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@@ -38,8 +38,13 @@ pub struct CalendarEventSearchInfo {pub organizer_email: Option<String>,/// Organizer display name, when the source names one.pub organizer_name: Option<String>,- /// Free-text event description, when the source carries one.+ /// Free-text event description, as stored: it still carries a Macro call's+ /// join line, which a reader must take out unless `holds_meeting`.pub description: Option<String>,+ /// Whether the requester holds the meeting rather than reading a channel+ /// share of it: this row is on their calendars, or a live copy of the+ /// meeting is. A snapshot copy is not a seat, so it does not count.+ pub holds_meeting: bool,/// Whether the canonical source prohibits mutation.pub is_read_only: bool,pub created_at: DateTime<Utc>,@@ -63,6 +68,13 @@ pub struct CalendarEventSearchInfo {/// requester cannot see is simply absent from the result, which drops the hit/// 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.+////// 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/// lateral prefers the next occurrence at or after `now`, falling back to the@@ -95,10 +107,11 @@ pub async fn get_calendar_events_for_search(event.end_date,event.time_zone,(cardinality(event.recurrence_lines) > 0) AS "is_recurring!",- CASE WHEN viewer.on_calendar THEN event.conference_url END AS conference_url,+ CASE WHEN meeting.holds_meeting THEN event.conference_url END AS conference_url,event.organizer_email,event.organizer_name,event.description,+ meeting.holds_meeting AS "holds_meeting!",event.is_read_only AS "is_read_only!",event.created_at AS "created_at!",event.updated_at AS "updated_at!",@@ -119,6 +132,28 @@ pub async fn get_calendar_events_for_search()) AS on_calendar) viewer+ CROSS JOIN LATERAL (+ SELECT (+ viewer.on_calendar+ OR EXISTS (+ SELECT 1+ FROM calendar_events held+ WHERE calendar_meeting_uid(held.ical_uid)+ = calendar_meeting_uid(event.ical_uid)+ AND held.status <> 'cancelled'+ AND NOT held.is_snapshot+ AND (+ held.owner_id = $1+ OR EXISTS (+ SELECT 1+ FROM macro_user_links link+ WHERE link.link_id = held.source_link_id+ AND link.primary_macro_id = $1+ )+ )+ )+ ) AS holds_meeting+ ) meetingLEFT JOIN LATERAL (SELECTinstance.occurrence_key,@@ -189,6 +224,7 @@ pub async fn get_calendar_events_for_search(organizer_email: row.organizer_email,organizer_name: row.organizer_name,description: row.description,+ holds_meeting: row.holds_meeting,is_read_only: row.is_read_only,created_at: row.created_at,updated_at: row.updated_at,diff --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 0762f05d19..d7736989a7 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@@ -151,6 +151,129 @@ async fn shared_ids_cover_live_shares_the_member_holds_no_copy_of(pool: Pool<Pos);}+async fn insert_user(pool: &Pool<Postgres>, id: &str) {+ let macro_user_id = Uuid::now_v7();+ sqlx::query(+ "INSERT INTO macro_user (id, username, email, stripe_customer_id) VALUES ($1, $2, $2, $2)",+ )+ .bind(macro_user_id)+ .bind(id)+ .execute(pool)+ .await+ .unwrap();+ sqlx::query(r#"INSERT INTO "User" (id, email, macro_user_id) VALUES ($1, $1, $2)"#)+ .bind(id)+ .bind(macro_user_id)+ .execute(pool)+ .await+ .unwrap();+}++/// Exchange's UID for a meeting it imported under `uid`.+fn exchange_uid(uid: &str) -> String {+ let wrapped: String = uid.bytes().map(|byte| format!("{byte:02X}")).collect();+ format!(+ "040000008200E00074C5B7101A82E008{}7643616C2D55696401000000{wrapped}00",+ "0".repeat(48)+ )+}++#[sqlx::test]+async fn only_a_seat_on_the_meeting_keeps_a_shared_row_join_link(pool: Pool<Postgres>) {+ const MEETING: &str = "[email protected]";+ let shared = insert_event(&pool, OWNER, MEETING, "default").await;+ let channel_id = insert_channel(&pool).await;+ share_with_channel(&pool, shared, channel_id).await;+ let now = Utc::now();+ let read = |user: &'static str| {+ let pool = pool.clone();+ async move {+ let row = get_calendar_events_for_search(&pool, user, &[shared], now)+ .await+ .unwrap()+ .remove(&shared)+ .expect("the share stays visible");+ (row.holds_meeting, row.conference_url.is_some())+ }+ };++ assert_eq!(+ read(OWNER).await,+ (true, true),+ "the sharer holds their row"+ );+ assert_eq!(read(MEMBER).await, (false, false), "a member holds nothing");++ // A guest's own copy lets them keep the link on the sharer's row too.+ let guest_copy = insert_event(&pool, ATTENDEE, MEETING, "default").await;+ assert_eq!(read(ATTENDEE).await, (true, true), "a guest holds a seat");+ assert_eq!(+ read(MEMBER).await,+ (false, false),+ "their seat is not shared"+ );++ // A snapshot of the share was imported without the link, so it must not+ // unlock the one on the sharer's row.+ sqlx::query("UPDATE calendar_events SET is_snapshot = true WHERE id = $1")+ .bind(guest_copy)+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(ATTENDEE).await,+ (false, false),+ "a snapshot is no seat"+ );++ sqlx::query(+ "UPDATE calendar_events SET is_snapshot = false, status = 'cancelled' WHERE id = $1",+ )+ .bind(guest_copy)+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(ATTENDEE).await,+ (false, false),+ "a cancelled copy is gone"+ );++ // An Outlook copy of the meeting wraps the UID but is the same meeting.+ sqlx::query("UPDATE calendar_events SET status = 'confirmed', ical_uid = $2 WHERE id = $1")+ .bind(guest_copy)+ .bind(exchange_uid(MEETING))+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(ATTENDEE).await,+ (true, true),+ "an Outlook copy is a seat"+ );++ // An inbox delegated to the member holds the meeting for them.+ let delegated_copy = insert_event(&pool, STRANGER, MEETING, "default").await;+ insert_user(&pool, MEMBER).await;+ insert_user(&pool, STRANGER).await;+ sqlx::query(+ r#"+ INSERT INTO macro_user_links (primary_macro_id, child_macro_id, link_id)+ SELECT $1, owner_id, source_link_id FROM calendar_events WHERE id = $2+ "#,+ )+ .bind(MEMBER)+ .bind(delegated_copy)+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ read(MEMBER).await,+ (true, true),+ "a delegated copy is a seat"+ );+}+#[sqlx::test]async fn search_metadata_reaches_a_channel_share_without_its_join_link(pool: Pool<Postgres>) {let shared = insert_event(&pool, OWNER, "[email protected]", "default").await;diff --git a/crates/search_service/AGENTS.md b/crates/search_service/AGENTS.mdindex 0b470277f4..574b5906f0 100644--- a/crates/search_service/AGENTS.md+++ b/crates/search_service/AGENTS.md@@ -32,7 +32,8 @@ per-entity-type search plus a unified search across them — mounted into## Boundaries- Depends on: `opensearch_client`, `models_opensearch`, `macro_db_client`,- `entity_access`, `properties`, `crm`, `item_filters`.+ `entity_access`, `properties`, `crm`, `item_filters`, `calendar_events`+ (domain only, no features, for its Macro call rule).- Used by: `document_storage_service` (mounts `search_router`); calledthrough `search_service_client`.@@ -61,7 +62,12 @@ per-entity-type search plus a unified search across them — mounted intoowner and inbox link; `shared_with_you` resolves the events shared with thecaller's channels in Postgres and searches by id, leaving out meetings thecaller holds a copy of. Enrichment re-checks every hit against the event's- access rule and withholds a share's join link.+ 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.## Relateddiff --git a/crates/search_service/Cargo.toml b/crates/search_service/Cargo.tomlindex af644ecf02..e9f085cc2a 100644--- a/crates/search_service/Cargo.toml+++ b/crates/search_service/Cargo.toml@@ -19,6 +19,7 @@ anyhow = { workspace = true }aws-sdk-secretsmanager = { workspace = true }macro_aws_config = { path = "../macro_aws_config" }axum = { workspace = true }+calendar_events = { path = "../calendar_events" }chrono = { workspace = true }channels = { path = "../channels", default-features = false, features = ["outbound"] }comms_db_client = { path = "../comms_db_client" }diff --git a/crates/search_service/src/api/search/calendar_event.rs b/crates/search_service/src/api/search/calendar_event.rsindex bfa084a6ad..a22f7d5a74 100644--- a/crates/search_service/src/api/search/calendar_event.rs+++ b/crates/search_service/src/api/search/calendar_event.rs@@ -1,4 +1,5 @@use crate::api::search::simple::SearchError;+use calendar_events::domain::ics::content_without_macro_call;use indexmap::IndexMap;use macro_db_client::calendar_event::get_events_for_search::{CalendarEventSearchInfo, get_calendar_events_for_search,@@ -19,7 +20,7 @@ use crate::api::context::SearchHandlerState;/// Enriches calendar event search results with metadata and the instance each/// row points at.-#[tracing::instrument(skip(ctx, results), err)]+#[tracing::instrument(skip(ctx, results), fields(channel_shared_count), err)]pub(in crate::api::search) async fn enrich_calendar_events(ctx: &SearchHandlerState,user_id: &str,@@ -42,6 +43,10 @@ pub(in crate::api::search) async fn enrich_calendar_events(let events = get_calendar_events_for_search(&ctx.db, user_id, &event_ids, chrono::Utc::now()).await.map_err(SearchError::InternalError)?;+ tracing::Span::current().record(+ "channel_shared_count",+ events.values().filter(|event| !event.holds_meeting).count(),+ );// Fetch event properties (e.g. tags) so rows can render and re-check// them, mirroring the projects enrichment.@@ -129,6 +134,17 @@ fn to_organizer(info: &CalendarEventSearchInfo) -> Option<CalendarEventOrganizer})}+/// The description the viewer may read. Only someone holding the meeting keeps+/// its Macro call: the rest read a channel share, which carries no join link.+/// The location plays no part, since search rows do not return it.+fn to_description(info: &CalendarEventSearchInfo) -> Option<String> {+ if info.holds_meeting {+ return info.description.clone();+ }+ let (description, _) = content_without_macro_call(info.description.clone(), None);+ description+}+pub fn construct_search_result(search_results: Vec<opensearch_client::search::model::SearchHit>,events: HashMap<Uuid, CalendarEventSearchInfo>,@@ -175,7 +191,7 @@ pub fn construct_search_result(conference_url: info.conference_url.clone(),is_read_only: info.is_read_only,organizer: to_organizer(info),- description: info.description.clone(),+ description: to_description(info),}),properties: properties_map.remove(&entity_id.to_string())diff --git a/crates/search_service/src/api/search/calendar_event/test.rs b/crates/search_service/src/api/search/calendar_event/test.rsindex d1e31348e6..0714e79d23 100644--- a/crates/search_service/src/api/search/calendar_event/test.rs+++ b/crates/search_service/src/api/search/calendar_event/test.rs@@ -1,7 +1,10 @@use super::*;+use calendar_events::domain::meeting_links::attach_macro_call;use chrono::{NaiveDate, TimeZone, Utc};use opensearch_client::search::model::{Highlight, SearchHit};+const CALL_URL: &str = "https://macro.com/app/meet/join/0123456789abcdef0123456789abcdef";+fn hit(entity_id: Uuid) -> SearchHit {SearchHit {entity_id,@@ -29,6 +32,7 @@ fn timed_series(id: Uuid) -> CalendarEventSearchInfo {organizer_email: Some("[email protected]".to_string()),organizer_name: Some("Jacob Beckerman".to_string()),description: None,+ holds_meeting: true,is_read_only: false,created_at: Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap(),updated_at: Utc.with_ymd_and_hms(2024, 1, 2, 0, 0, 0).unwrap(),@@ -40,6 +44,62 @@ fn timed_series(id: Uuid) -> CalendarEventSearchInfo {}}+/// The description a row returns for an event stored with `description`.+fn returned_description(description: &str, holds_meeting: bool) -> Option<String> {+ let id = Uuid::new_v4();+ let mut info = timed_series(id);+ info.description = Some(description.to_string());+ info.holds_meeting = holds_meeting;+ let results =+ construct_search_result(vec![hit(id)], HashMap::from([(id, info)]), HashMap::new());+ results+ .into_iter()+ .next()+ .and_then(|row| row.metadata)+ .and_then(|metadata| metadata.description)+}++#[test]+fn a_channel_member_reads_the_description_without_the_macro_call() {+ let (stored, _) = attach_macro_call(Some("Quarterly planning"), None, CALL_URL);+ assert_eq!(+ returned_description(&stored, false).as_deref(),+ Some("Quarterly planning")+ );+}++#[test]+fn a_description_holding_only_the_join_line_comes_back_empty() {+ let (stored, _) = attach_macro_call(None, None, CALL_URL);+ assert_eq!(returned_description(&stored, false), None);+}++#[test]+fn a_join_line_closing_a_long_description_still_comes_out() {+ // The mention preview's trap: a cap ahead of the strip would cut the join+ // line short of what the rule recognizes. Search caps nothing.+ let text = "Agenda ".repeat(1_000);+ let (stored, _) = attach_macro_call(Some(&text), None, CALL_URL);+ let returned = returned_description(&stored, false).expect("the text stays");+ assert!(!returned.contains("/meet/join/"), "{returned}");+ assert!(returned.starts_with("Agenda"), "{returned}");+}++#[test]+fn a_holder_keeps_the_macro_call() {+ let (stored, _) = attach_macro_call(Some("Quarterly planning"), None, CALL_URL);+ assert_eq!(+ returned_description(&stored, true).as_deref(),+ Some(stored.as_str())+ );+}++#[test]+fn a_share_without_a_macro_call_keeps_its_markup() {+ let stored = "<p>See <a href=\"https://example.com/notes\">the notes</a></p>";+ assert_eq!(returned_description(stored, false).as_deref(), Some(stored));+}+#[test]fn resolved_occurrence_rides_on_the_row() {let id = Uuid::new_v4();