Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(call): delete call (#2625)

Will Hutchinson18ed4bd90bc3
diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.ts
index f7e4def9d1..1ceb889f5a 100644
--- a/js/app/packages/macro-entity/src/queries/dss.ts
+++ b/js/app/packages/macro-entity/src/queries/dss.ts
@@ -3,9 +3,11 @@ import {
deleteItem,
moveToFolder,
} from '@core/component/FileList/itemOperations';
+import { throwOnErr } from '@core/util/maybeResult';
import { toast } from '@core/component/Toast/Toast';
import { useMutation } from '@tanstack/solid-query';
import type { EntityData } from '@entity';
+import { callServiceClient } from '@service-call/client';
import type { ItemType } from '@service-storage/client';
import { queryClient } from '@queries/client';
import { soupKeys } from '@queries/soup/keys';
@@ -20,16 +22,30 @@ import {
export function createBulkDeleteDssItemsMutation() {
const isDeletable = (entity: EntityData) => {
const type = entity.type;
- return type === 'chat' || type === 'document' || type === 'project';
+ return (
+ type === 'chat' ||
+ type === 'document' ||
+ type === 'project' ||
+ type === 'call'
+ );
};
return useMutation(() => ({
mutationFn: async (entities: EntityData[]) => {
const deletable = entities.filter(isDeletable);
- return await Promise.all(
+ const results = await Promise.all(
deletable.map((e) => {
+ if (e.type === 'call') {
+ return throwOnErr(() =>
+ callServiceClient.deleteCallRecord(e.id)
+ ).then(() => true);
+ }
return deleteItem({ id: e.id, itemType: e.type as ItemType });
})
);
+ if (deletable.some((e) => e.type === 'call')) {
+ queryClient.invalidateQueries({ queryKey: ['call'] });
+ }
+ return results;
},
onMutate: async (entities: EntityData[]) => {
const deletable = entities.filter(isDeletable);
diff --git a/js/app/packages/service-clients/service-call/client.ts b/js/app/packages/service-clients/service-call/client.ts
index 2c4afddfbe..60b27779df 100644
--- a/js/app/packages/service-clients/service-call/client.ts
+++ b/js/app/packages/service-clients/service-call/client.ts
@@ -52,4 +52,14 @@ export const callServiceClient = {
(result) => result
);
},
+
+ async deleteCallRecord(callId: string) {
+ return mapOk(
+ await fetchWithToken<Record<string, never>>(
+ `${host}/call/record/${callId}`,
+ { method: 'DELETE' }
+ ),
+ () => undefined
+ );
+ },
};
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 39fa9f878b..a6909bf534 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -907,6 +907,15 @@ export const getCallRecordResponse = zod
'Full record of a call, unifying rows from `calls` (active) and\n`call_records` (archived) into a single response shape.'
);
+/**
+ * Deletes a call record (and its participants/transcripts via cascade).
+Access is validated via channel membership (MemberParticipantRole).
+ * @summary Handler for `DELETE /call/record/{call_id}`.
+ */
+export const deleteCallRecordParams = zod.object({
+ call_id: zod.string().uuid().describe('Call ID'),
+});
+
/**
* Gets or creates a call for the channel. If a call already exists, joins it;
otherwise creates a new one. Always returns a join token.
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 862d768cda..740e0940d8 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -654,6 +654,59 @@
}
}
}
+ },
+ "delete": {
+ "tags": ["call::inbound::axum_router"],
+ "summary": "Handler for `DELETE /call/record/{call_id}`.",
+ "description": "Deletes a call record (and its participants/transcripts via cascade).\nAccess is validated via channel membership (MemberParticipantRole).",
+ "operationId": "delete_call_record",
+ "parameters": [
+ {
+ "name": "call_id",
+ "in": "path",
+ "description": "Call ID",
+ "required": true,
+ "schema": {
+ "type": "string",
+ "format": "uuid"
+ }
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "Call record deleted"
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
}
},
"/call/webhook": {
diff --git a/rust/cloud-storage/call/.sqlx/query-bc5d15913b03fd0396e76b5551960bfde660e446ff82c8f14a5e4d17ae03dfc3.json b/rust/cloud-storage/call/.sqlx/query-bc5d15913b03fd0396e76b5551960bfde660e446ff82c8f14a5e4d17ae03dfc3.json
new file mode 100644
index 0000000000..20d2ab0b0b
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-bc5d15913b03fd0396e76b5551960bfde660e446ff82c8f14a5e4d17ae03dfc3.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM call_records WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "bc5d15913b03fd0396e76b5551960bfde660e446ff82c8f14a5e4d17ae03dfc3"
+}
diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rs
index be7bf236ab..aab8b12ef5 100644
--- a/rust/cloud-storage/call/src/domain/ports.rs
+++ b/rust/cloud-storage/call/src/domain/ports.rs
@@ -163,6 +163,13 @@ pub trait CallRepository: Send + Sync + 'static {
channel_id: &Uuid,
user_id: MacroUserIdStr<'a>,
) -> impl Future<Output = Result<Option<String>, Self::Err>> + Send;
+
+ /// Delete a row from `call_records` by id. Participants and transcript
+ /// segments are removed via `ON DELETE CASCADE`. No-op if no row matches.
+ fn delete_call_record(
+ &self,
+ call_record_id: &Uuid,
+ ) -> impl Future<Output = Result<(), Self::Err>> + Send;
}
/// Storage port for generating presigned recording URLs.
@@ -282,6 +289,18 @@ pub trait CallService: Send + Sync + 'static {
&self,
receipt: EntityAccessReceipt<MemberParticipantRole>,
) -> impl Future<Output = Result<CallRecord, CallError>> + Send;
+
+ /// Delete a [`CallRecord`] the caller has channel-member access to.
+ ///
+ /// Authorization is carried in the receipt produced by
+ /// `CallAccessLevelExtractor`; the entity on the receipt must be
+ /// `EntityType::Call` and its `entity_id` must be the call's UUID.
+ /// Only `call_records` rows are affected — active calls in the `calls`
+ /// table are untouched. Idempotent.
+ fn delete_call_record(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ ) -> impl Future<Output = Result<(), CallError>> + Send;
}
/// Lightweight read-only port for querying call records in Soup.
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 498bc67986..61f1e48084 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -646,6 +646,29 @@ impl<
Ok(record)
}
+ #[tracing::instrument(err, skip(self))]
+ async fn delete_call_record(
+ &self,
+ receipt: EntityAccessReceipt<MemberParticipantRole>,
+ ) -> Result<(), CallError> {
+ let entity = receipt.entity();
+ if entity.entity_type != EntityType::Call {
+ return Err(CallError::Internal(anyhow::anyhow!(
+ "expected Call entity in receipt, got {:?}",
+ entity.entity_type
+ )));
+ }
+ let call_id = Uuid::parse_str(&entity.entity_id)
+ .map_err(|_| CallError::Internal(anyhow::anyhow!("invalid call_id in receipt")))?;
+
+ self.repo
+ .delete_call_record(&call_id)
+ .await
+ .map_err(|e| CallError::Internal(e.into()))?;
+
+ Ok(())
+ }
+
#[tracing::instrument(err, skip(self, segment))]
async fn ingest_transcript_segment(
&self,
diff --git a/rust/cloud-storage/call/src/inbound/axum_router.rs b/rust/cloud-storage/call/src/inbound/axum_router.rs
index 939e1090f7..9ef23a14f6 100644
--- a/rust/cloud-storage/call/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/call/src/inbound/axum_router.rs
@@ -77,6 +77,7 @@ impl<S, Svc> FromRef<CallRouterState<S, Svc>> for Arc<Svc> {
/// - `GET /{channel_id}/active` — check if an active call exists
/// - `DELETE /{channel_id}` — leave or end a call
/// - `GET /record/{call_id}` — get a full call record (transcript + participants)
+/// - `DELETE /record/{call_id}` — delete a call record
pub fn call_router<S, Svc, T>(state: CallRouterState<S, Svc>) -> Router<T>
where
S: CallService,
@@ -92,7 +93,10 @@ where
"/{channel_id}/active",
get(check_active_call_handler::<S, Svc>),
)
- .route("/record/{call_id}", get(get_call_record_handler::<S, Svc>))
+ .route(
+ "/record/{call_id}",
+ get(get_call_record_handler::<S, Svc>).delete(delete_call_record_handler::<S, Svc>),
+ )
.with_state(state)
}
@@ -315,6 +319,36 @@ pub async fn get_call_record_handler<S: CallService, Svc: EntityAccessService>(
Ok(Json(record))
}
+/// Handler for `DELETE /call/record/{call_id}`.
+///
+/// Deletes a call record (and its participants/transcripts via cascade).
+/// Access is validated via channel membership (MemberParticipantRole).
+#[utoipa::path(
+ delete,
+ operation_id = "delete_call_record",
+ path = "/call/record/{call_id}",
+ params(
+ ("call_id" = Uuid, Path, description = "Call ID"),
+ ),
+ responses(
+ (status = 204, description = "Call record deleted"),
+ (status = 401, body = ErrorResponse),
+ (status = 404, body = ErrorResponse),
+ (status = 500, body = ErrorResponse),
+ )
+)]
+#[tracing::instrument(err, skip_all)]
+pub async fn delete_call_record_handler<S: CallService, Svc: EntityAccessService>(
+ State(state): State<CallRouterState<S, Svc>>,
+ access: CallAccessLevelExtractor<MemberParticipantRole, Svc>,
+) -> Result<StatusCode, CallError> {
+ state
+ .service
+ .delete_call_record(access.entity_access_receipt)
+ .await?;
+ Ok(StatusCode::NO_CONTENT)
+}
+
/// Handler for `DELETE /call/{channel_id}`.
#[utoipa::path(
delete,
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
index b0907fa687..5f390bdde4 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
@@ -1006,4 +1006,17 @@ impl CallRepository for PgCallRepo {
&name_lookup,
)))
}
+
+ #[tracing::instrument(err, skip(self))]
+ async fn delete_call_record(&self, call_record_id: &Uuid) -> Result<(), Self::Err> {
+ sqlx::query!(
+ r#"
+ DELETE FROM call_records WHERE id = $1
+ "#,
+ call_record_id,
+ )
+ .execute(&self.pool)
+ .await?;
+ Ok(())
+ }
}
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
index 49efb7bc93..1ab2669a2f 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
@@ -619,8 +619,6 @@ async fn get_call_record_returns_none_for_unknown(pool: Pool<Postgres>) -> anyho
Ok(())
}
-// -- get_call_records_by_user ------------------------------------------------
-
#[sqlx::test(
fixtures(path = "../../../fixtures", scripts("call_repo")),
migrator = "MACRO_DB_MIGRATIONS"
@@ -650,3 +648,70 @@ async fn get_call_records_by_user_includes_channel_member_not_in_call(
);
Ok(())
}
+
+// -- delete_call_record -------------------------------------------------------
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn delete_call_record_cascades(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ // Sanity check: the archived call and its children exist before delete.
+ let pre_participants: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM call_record_participants WHERE call_record_id = $1"#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+ let pre_transcripts: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM call_record_transcripts WHERE call_record_id = $1"#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(pre_participants > 0);
+ assert!(pre_transcripts > 0);
+
+ repo.delete_call_record(&CALL_ARCHIVED).await?;
+
+ // Record row is gone.
+ let record = repo.get_call_record_by_call_id(&CALL_ARCHIVED).await?;
+ assert!(record.is_none());
+
+ // Cascade removed participants and transcripts.
+ let remaining_participants: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM call_record_participants WHERE call_record_id = $1"#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+ let remaining_transcripts: i64 = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM call_record_transcripts WHERE call_record_id = $1"#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(remaining_participants, 0);
+ assert_eq!(remaining_transcripts, 0);
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn delete_call_record_noop_for_unknown_id(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let repo = repo(pool);
+ // Non-existent id — should succeed without touching anything.
+ repo.delete_call_record(&Uuid::now_v7()).await?;
+
+ // Existing archived record must still be present.
+ assert!(
+ repo.get_call_record_by_call_id(&CALL_ARCHIVED)
+ .await?
+ .is_some()
+ );
+ Ok(())
+}
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 445d7f83b4..0cf542a42f 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -196,6 +196,7 @@ use utoipa::OpenApi;
call::inbound::axum_router::check_active_call_handler,
call::inbound::axum_router::leave_or_end_call_handler,
call::inbound::axum_router::get_call_record_handler,
+ call::inbound::axum_router::delete_call_record_handler,
call::inbound::axum_router::webhook_handler,
call::inbound::axum_router::transcript_handler,
diff --git a/rust/cloud-storage/macro_db_client/migrations/20260416120000_fix_call_record_share_permission_cascade.sql b/rust/cloud-storage/macro_db_client/migrations/20260416120000_fix_call_record_share_permission_cascade.sql
new file mode 100644
index 0000000000..f0257de84d
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/migrations/20260416120000_fix_call_record_share_permission_cascade.sql
@@ -0,0 +1,27 @@
+-- Break the circular cascade between call_records and SharePermission.
+--
+-- call_records.share_permission_id was created with ON DELETE CASCADE, and
+-- trg_delete_share_permission_call_record (BEFORE DELETE on call_records)
+-- also deletes the referenced SharePermission. Deleting a call_record fired
+-- the trigger, which deleted the SharePermission, which cascaded back to the
+-- same call_record row already being deleted:
+-- "tuple to be deleted was already modified by an operation triggered by
+-- the current command"
+--
+-- SharePermission rows tied to a call/call_record are only ever removed via
+-- the BEFORE DELETE trigger on call_records; they are never deleted
+-- directly. Drop the reverse cascade and mark the FK DEFERRABLE INITIALLY
+-- DEFERRED so that when the trigger deletes the SharePermission, the FK
+-- check waits until COMMIT (by which time the call_record is also gone).
+
+ALTER TABLE call_records
+ DROP CONSTRAINT call_records_share_permission_id_fkey,
+ ADD CONSTRAINT call_records_share_permission_id_fkey
+ FOREIGN KEY (share_permission_id) REFERENCES "SharePermission"(id)
+ DEFERRABLE INITIALLY DEFERRED;
+
+ALTER TABLE calls
+ DROP CONSTRAINT calls_share_permission_id_fkey,
+ ADD CONSTRAINT calls_share_permission_id_fkey
+ FOREIGN KEY (share_permission_id) REFERENCES "SharePermission"(id)
+ DEFERRABLE INITIALLY DEFERRED;