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): share/unshare with team in edit call (#2722)

Will Hutchinson6833a0b24d06
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts
index 7ca9050682..a9fca7bd54 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequest.ts
@@ -5,10 +5,15 @@
* OpenAPI spec version: 0.1.0
*/
import type { EditCallRecordRequestSharePermission } from './editCallRecordRequestSharePermission';
+import type { EditCallRecordRequestShareWithTeam } from './editCallRecordRequestShareWithTeam';
/**
* Edit call request
*/
export interface EditCallRecordRequest {
sharePermission?: EditCallRecordRequestSharePermission;
+ /** If `Some(true)`, grant the creator's team View access on the call.
+If `Some(false)`, revoke the creator's team's access. `None` is a no-op.
+The team is resolved from the call's `created_by`, not the acting user. */
+ shareWithTeam?: EditCallRecordRequestShareWithTeam;
}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestShareWithTeam.ts b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestShareWithTeam.ts
new file mode 100644
index 0000000000..82fad62e3c
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/editCallRecordRequestShareWithTeam.ts
@@ -0,0 +1,13 @@
+/**
+ * Generated by orval v7.13.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * If `Some(true)`, grant the creator's team View access on the call.
+If `Some(false)`, revoke the creator's team's access. `None` is a no-op.
+The team is resolved from the call's `created_by`, not the acting user.
+ */
+export type EditCallRecordRequestShareWithTeam = boolean | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index c4d900e722..ad3c0c1463 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -259,6 +259,7 @@ export * from './editAnchorResponse';
export * from './editAnchorResponseAllOf';
export * from './editCallRecordRequest';
export * from './editCallRecordRequestSharePermission';
+export * from './editCallRecordRequestShareWithTeam';
export * from './editCommentRequest';
export * from './editCommentRequestMentions';
export * from './editCommentRequestText';
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 091456e950..c88c1f409e 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -967,6 +967,12 @@ export const editCallRecordBody = zod
}),
])
.optional(),
+ shareWithTeam: zod
+ .boolean()
+ .nullish()
+ .describe(
+ "If `Some(true)`, grant the creator's team View access on the call.\nIf `Some(false)`, revoke the creator's team's access. `None` is a no-op.\nThe team is resolved from the call's `created_by`, not the acting user."
+ ),
})
.describe('Edit call request');
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 27d55930a2..3fcd65cf7c 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -7537,6 +7537,10 @@
"description": "Updated share permissions."
}
]
+ },
+ "shareWithTeam": {
+ "type": ["boolean", "null"],
+ "description": "If `Some(true)`, grant the creator's team View access on the call.\nIf `Some(false)`, revoke the creator's team's access. `None` is a no-op.\nThe team is resolved from the call's `created_by`, not the acting user."
}
}
},
diff --git a/rust/cloud-storage/call/.sqlx/query-12bbf364a130b8f3af7e7bc7f8c64eb026124d2a66d2735b95ef387433cecd03.json b/rust/cloud-storage/call/.sqlx/query-12bbf364a130b8f3af7e7bc7f8c64eb026124d2a66d2735b95ef387433cecd03.json
new file mode 100644
index 0000000000..8bcde4e677
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-12bbf364a130b8f3af7e7bc7f8c64eb026124d2a66d2735b95ef387433cecd03.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT team_id\n FROM team_user\n WHERE user_id = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "team_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "12bbf364a130b8f3af7e7bc7f8c64eb026124d2a66d2735b95ef387433cecd03"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json b/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
deleted file mode 100644
index c92d9c45fc..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "34a70ab661c087eb2c6b97d57099ac2c7ff263b9340003c319475fcafdf0356b"
-}
diff --git a/rust/cloud-storage/call/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json b/rust/cloud-storage/call/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json
new file mode 100644
index 0000000000..72262bfe13
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1\n AND entity_type = $2\n AND source_id = $3\n AND source_type = $4\n AND granted_from_project_id IS NULL\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "entity_access_source_type",
+ "kind": {
+ "Enum": [
+ "channel",
+ "team",
+ "user"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-3bd649e798f834ea3e0fc9d6c3b03d923622666779a97429afb926c64b517e1b.json b/rust/cloud-storage/call/.sqlx/query-3bd649e798f834ea3e0fc9d6c3b03d923622666779a97429afb926c64b517e1b.json
new file mode 100644
index 0000000000..6e2c2d93de
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-3bd649e798f834ea3e0fc9d6c3b03d923622666779a97429afb926c64b517e1b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "UPDATE calls SET share_with_team = $2 WHERE id = $1",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3bd649e798f834ea3e0fc9d6c3b03d923622666779a97429afb926c64b517e1b"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/rust/cloud-storage/call/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
similarity index 84%
rename from rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
rename to rust/cloud-storage/call/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
index b75a3a2ff5..7eadb2f534 100644
--- a/rust/cloud-storage/call/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
+++ b/rust/cloud-storage/call/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ",
+ "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT DO NOTHING\n ",
"describe": {
"columns": [],
"parameters": {
@@ -37,5 +37,5 @@
},
"nullable": []
},
- "hash": "41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132"
+ "hash": "44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098"
}
diff --git a/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json b/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
deleted file mode 100644
index c91a76ff52..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM entity_access\n WHERE entity_id = $1 AND entity_type = $2\n AND source_id = ANY($3) AND source_type = 'channel'\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "46ffaa1a906d49a47c765c9c03d89e50037adc4b72c364bdb4282ab0c8cf1237"
-}
diff --git a/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json b/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
deleted file mode 100644
index ac050656e7..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b.json
+++ /dev/null
@@ -1,29 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)\n SELECT $1, $2, u.user_id, 'user', $3\n FROM UNNEST($4::text[]) as u(user_id)\n ON CONFLICT (entity_id, entity_type, source_id, source_type)\n WHERE granted_from_project_id IS NULL\n AND access_level != 'owner' -- this prevents us from overriding the owner user\n DO UPDATE SET access_level = EXCLUDED.access_level, updated_at = NOW()\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- {
- "Custom": {
- "name": "\"AccessLevel\"",
- "kind": {
- "Enum": [
- "view",
- "comment",
- "edit",
- "owner"
- ]
- }
- }
- },
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "5ffee439386fd24fee2bfa20caa76b882f5be1d44a2a06a71783418fc5ef381b"
-}
diff --git a/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json b/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
deleted file mode 100644
index b7e5230b4c..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM entity_access\n WHERE (source_id = ANY($1) AND source_type = 'channel')\n AND (entity_id = ANY($2) OR granted_from_project_id = ANY($3))\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "TextArray",
- "UuidArray",
- "TextArray"
- ]
- },
- "nullable": []
- },
- "hash": "7078d46dbcbe1c4201bcb4f63d98400d28bde0e2c3af5211a83a01165f751029"
-}
diff --git a/rust/cloud-storage/call/.sqlx/query-77b9642e3ce72202c80aacda76790b7a1e1eee80d0b7388c2ad68e8ce5a996c7.json b/rust/cloud-storage/call/.sqlx/query-77b9642e3ce72202c80aacda76790b7a1e1eee80d0b7388c2ad68e8ce5a996c7.json
new file mode 100644
index 0000000000..ce6db4c49c
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-77b9642e3ce72202c80aacda76790b7a1e1eee80d0b7388c2ad68e8ce5a996c7.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT created_by as \"created_by!\"\n FROM (\n SELECT created_by FROM calls WHERE id = $1\n UNION ALL\n SELECT created_by FROM call_records WHERE id = $1\n ) t\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "created_by!",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "77b9642e3ce72202c80aacda76790b7a1e1eee80d0b7388c2ad68e8ce5a996c7"
+}
diff --git a/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json b/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
deleted file mode 100644
index f47413e3dc..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE parent_projects AS (\n -- Base case: the project itself\n SELECT id, name, \"parentId\"\n FROM \"Project\"\n WHERE id = $1\n\n UNION ALL\n\n -- Recursive case: walk up to the parent\n SELECT p.id, p.name, p.\"parentId\"\n FROM \"Project\" p\n INNER JOIN parent_projects pp ON p.id = pp.\"parentId\"\n )\n SELECT id as \"id!\"\n FROM parent_projects\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- null
- ]
- },
- "hash": "e08bcee71072e0e693b1b3f2df39a2b9574f45847919251446878f32b9febbc2"
-}
diff --git a/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json b/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
deleted file mode 100644
index c718076a09..0000000000
--- a/rust/cloud-storage/call/.sqlx/query-f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH RECURSIVE child_projects AS (\n SELECT id FROM \"Project\" WHERE id = $1\n\n UNION ALL\n\n SELECT p.id FROM \"Project\" p\n INNER JOIN child_projects cp ON p.\"parentId\" = cp.id\n )\n SELECT id as \"entity_id!\", 'project' as \"entity_type!\" FROM child_projects\n\n UNION ALL\n\n SELECT d.id as \"entity_id!\", 'document' as \"entity_type!\" FROM \"Document\" d\n WHERE d.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT c.id as \"entity_id!\", 'chat' as \"entity_type!\" FROM \"Chat\" c\n WHERE c.\"projectId\" IN (SELECT id FROM child_projects)\n\n UNION ALL\n\n SELECT et.id::text as \"entity_id!\", 'email_thread' as \"entity_type!\" FROM email_threads et\n WHERE et.project_id IN (SELECT id FROM child_projects)\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "entity_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "entity_type!",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "Text"
- ]
- },
- "nullable": [
- null,
- null
- ]
- },
- "hash": "f6a7499d3079d346afe5d866734ffc5d4ac3f9f1a8c2a5714ef130e53d11145f"
-}
diff --git a/rust/cloud-storage/call/src/domain/models.rs b/rust/cloud-storage/call/src/domain/models.rs
index 96c479fc97..f267def154 100644
--- a/rust/cloud-storage/call/src/domain/models.rs
+++ b/rust/cloud-storage/call/src/domain/models.rs
@@ -147,6 +147,10 @@ pub struct EditCallRecordRequest {
/// Updated share permissions.
pub share_permission:
Option<models_permissions::share_permission::UpdateSharePermissionRequestV2>,
+ /// If `Some(true)`, grant the creator's team View access on the call.
+ /// If `Some(false)`, revoke the creator's team's access. `None` is a no-op.
+ /// The team is resolved from the call's `created_by`, not the acting user.
+ pub share_with_team: Option<bool>,
}
/// A transcript segment as returned in a [`CallRecord`].
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 6e4d041acd..1c77ea2c0b 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
@@ -1150,6 +1150,10 @@ impl CallRepository for PgCallRepo {
edit::update_share_permission(&mut tx, call_record_id, share_permission).await?;
}
+ if let Some(share_with_team) = request.share_with_team {
+ edit::set_share_with_team(&mut tx, call_record_id, share_with_team).await?;
+ }
+
tx.commit().await?;
Ok(())
}
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs
index 23b22bfb6e..f84f35ec2b 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo/edit.rs
@@ -1,5 +1,6 @@
//! SQL operations for editing call-record share permissions.
+use entity_access_db_utils::{AccessLevel, EntityAccessSourceType};
use model_entity::EntityType;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use models_permissions::share_permission::channel_share_permission::UpdateOperation;
@@ -48,6 +49,94 @@ pub(super) async fn update_share_permission(
Ok(())
}
+/// Grant or revoke the call creator's team's View access on the call.
+///
+/// The team is resolved from the call's `created_by` in either the active
+/// `calls` table or the archived `call_records` table — not from the acting
+/// user. If the creator has no team, this is a no-op. Also keeps the
+/// `calls.share_with_team` flag in sync when the call is still active so
+/// `archive_call` reflects the latest choice.
+pub(super) async fn set_share_with_team(
+ transaction: &mut Transaction<'_, Postgres>,
+ call_id: &Uuid,
+ share: bool,
+) -> Result<(), sqlx::Error> {
+ let created_by: String = sqlx::query_scalar!(
+ r#"
+ SELECT created_by as "created_by!"
+ FROM (
+ SELECT created_by FROM calls WHERE id = $1
+ UNION ALL
+ SELECT created_by FROM call_records WHERE id = $1
+ ) t
+ LIMIT 1
+ "#,
+ call_id,
+ )
+ .fetch_one(transaction.as_mut())
+ .await?;
+
+ sqlx::query!(
+ r#"UPDATE calls SET share_with_team = $2 WHERE id = $1"#,
+ call_id,
+ share,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+
+ let team_id: Option<Uuid> = sqlx::query_scalar!(
+ r#"
+ SELECT team_id
+ FROM team_user
+ WHERE user_id = $1
+ LIMIT 1
+ "#,
+ &created_by,
+ )
+ .fetch_optional(transaction.as_mut())
+ .await?;
+
+ let Some(team_id) = team_id else {
+ return Ok(());
+ };
+
+ if share {
+ sqlx::query!(
+ r#"
+ INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, $2, $3, $4, $5)
+ ON CONFLICT DO NOTHING
+ "#,
+ call_id,
+ EntityType::Call.as_ref(),
+ &team_id.to_string(),
+ EntityAccessSourceType::Team as _,
+ AccessLevel::View as _,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ } else {
+ sqlx::query!(
+ r#"
+ DELETE FROM entity_access
+ WHERE entity_id = $1
+ AND entity_type = $2
+ AND source_id = $3
+ AND source_type = $4
+ AND granted_from_project_id IS NULL
+ "#,
+ call_id,
+ EntityType::Call.as_ref(),
+ &team_id.to_string(),
+ EntityAccessSourceType::Team as _,
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+
+ Ok(())
+}
+
/// Update the SharePermission row (isPublic, publicAccessLevel).
async fn update_share_permission_row(
transaction: &mut Transaction<'_, Postgres>,
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 c788c3cd90..4bc1bcc341 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
@@ -957,6 +957,7 @@ async fn patch_call_record_sets_is_public_true_defaults_view(
public_access_level: None,
channel_share_permissions: None,
}),
+ share_with_team: None,
},
)
.await?;
@@ -1002,6 +1003,7 @@ async fn patch_call_record_sets_is_public_false_clears_public_access_level(
public_access_level: Some(AccessLevel::Edit),
channel_share_permissions: None,
}),
+ share_with_team: None,
},
)
.await?;
@@ -1037,6 +1039,7 @@ async fn patch_call_record_sets_public_access_level(pool: Pool<Postgres>) -> any
public_access_level: Some(AccessLevel::Edit),
channel_share_permissions: None,
}),
+ share_with_team: None,
},
)
.await?;
@@ -1078,6 +1081,7 @@ async fn patch_call_record_adds_channel_share_permission(
access_level: Some(AccessLevel::View),
}]),
}),
+ share_with_team: None,
},
)
.await?;
@@ -1151,6 +1155,7 @@ async fn patch_call_record_removes_channel_share_permission(
access_level: None,
}]),
}),
+ share_with_team: None,
},
)
.await?;
@@ -1192,6 +1197,7 @@ async fn patch_call_record_none_is_noop(pool: Pool<Postgres>) -> anyhow::Result<
&CALL_ARCHIVED,
&EditCallRecordRequest {
share_permission: None,
+ share_with_team: None,
},
)
.await?;
@@ -1211,3 +1217,240 @@ async fn patch_call_record_none_is_noop(pool: Pool<Postgres>) -> anyhow::Result<
assert_eq!(before.public_access_level, after.public_access_level);
Ok(())
}
+
+// -- patch_call_record: share_with_team ---------------------------------------
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_share_with_team_true_grants_team_access_on_active_call(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let team_id: Uuid = Uuid::from_u128(0xaaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaa001);
+
+ // The active call's created_by is USER_A — that's the team we should grant.
+ give_user_a_team(&pool, USER_A.as_ref(), &team_id).await?;
+
+ repo.patch_call_record(
+ &CALL1,
+ &EditCallRecordRequest {
+ share_permission: None,
+ share_with_team: Some(true),
+ },
+ )
+ .await?;
+
+ let row = sqlx::query!(
+ r#"
+ SELECT source_id, access_level::text as "access_level"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'call' AND source_type = 'team'
+ "#,
+ CALL1,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(row.source_id, team_id.to_string());
+ assert_eq!(row.access_level.as_deref(), Some("view"));
+
+ let flag = sqlx::query_scalar!(r#"SELECT share_with_team FROM calls WHERE id = $1"#, CALL1,)
+ .fetch_one(&pool)
+ .await?;
+ assert!(flag);
+
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_share_with_team_false_removes_team_access(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let team_id: Uuid = Uuid::from_u128(0xaaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaa002);
+
+ give_user_a_team(&pool, USER_A.as_ref(), &team_id).await?;
+
+ // Pre-seed a team entity_access row so we can observe the deletion.
+ sqlx::query(
+ r#"INSERT INTO entity_access (entity_id, entity_type, source_id, source_type, access_level)
+ VALUES ($1, 'call', $2, 'team', 'view')"#,
+ )
+ .bind(CALL1)
+ .bind(team_id.to_string())
+ .execute(&pool)
+ .await?;
+
+ repo.patch_call_record(
+ &CALL1,
+ &EditCallRecordRequest {
+ share_permission: None,
+ share_with_team: Some(false),
+ },
+ )
+ .await?;
+
+ let count = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM entity_access
+ WHERE entity_id = $1 AND source_type = 'team'"#,
+ CALL1,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(count, 0);
+
+ let flag = sqlx::query_scalar!(r#"SELECT share_with_team FROM calls WHERE id = $1"#, CALL1,)
+ .fetch_one(&pool)
+ .await?;
+ assert!(!flag);
+
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_share_with_team_works_on_archived_record(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let team_id: Uuid = Uuid::from_u128(0xaaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaa003);
+
+ // CALL_ARCHIVED was created by USER_A; its team should get View.
+ give_user_a_team(&pool, USER_A.as_ref(), &team_id).await?;
+
+ repo.patch_call_record(
+ &CALL_ARCHIVED,
+ &EditCallRecordRequest {
+ share_permission: None,
+ share_with_team: Some(true),
+ },
+ )
+ .await?;
+
+ let row = sqlx::query!(
+ r#"
+ SELECT source_id, access_level::text as "access_level"
+ FROM entity_access
+ WHERE entity_id = $1 AND entity_type = 'call' AND source_type = 'team'
+ "#,
+ CALL_ARCHIVED,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert_eq!(row.source_id, team_id.to_string());
+ assert_eq!(row.access_level.as_deref(), Some("view"));
+
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_share_with_team_ignores_non_creator_teams(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+ let creator_team: Uuid = Uuid::from_u128(0xaaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaa004);
+ let other_team: Uuid = Uuid::from_u128(0xbbbbbbbb_bbbb_bbbb_bbbb_bbbbbbbbb004);
+ let other_macro_user_id = Uuid::now_v7();
+
+ // USER_A (the call creator) is on `creator_team`.
+ give_user_a_team(&pool, USER_A.as_ref(), &creator_team).await?;
+
+ // Seed a second team whose owner is a different user (USER_B). The repo
+ // must not grant access to this team — the lookup keys off the call's
+ // created_by (USER_A), not off any other user's team membership.
+ sqlx::query(
+ r#"INSERT INTO macro_user (id, username, email, stripe_customer_id) VALUES ($1, $2, $3, $4)"#,
+ )
+ .bind(other_macro_user_id)
+ .bind(USER_B.as_ref())
+ .bind("cus_other")
+ .execute(&pool)
+ .await?;
+ sqlx::query(r#"INSERT INTO "User" (id, email, macro_user_id) VALUES ($1, $2, $3)"#)
+ .bind(USER_B.as_ref())
+ .bind(other_macro_user_id)
+ .execute(&pool)
+ .await?;
+ sqlx::query(r#"INSERT INTO team (id, name, owner_id) VALUES ($1, $2, $3)"#)
+ .bind(other_team)
+ .bind("unrelated team")
+ .bind(USER_B.as_ref())
+ .execute(&pool)
+ .await?;
+ sqlx::query(r#"INSERT INTO team_user (user_id, team_id, team_role) VALUES ($1, $2, 'owner')"#)
+ .bind(USER_B.as_ref())
+ .bind(other_team)
+ .execute(&pool)
+ .await?;
+
+ repo.patch_call_record(
+ &CALL1,
+ &EditCallRecordRequest {
+ share_permission: None,
+ share_with_team: Some(true),
+ },
+ )
+ .await?;
+
+ let source_ids: Vec<String> = sqlx::query_scalar!(
+ r#"SELECT source_id FROM entity_access
+ WHERE entity_id = $1 AND source_type = 'team'"#,
+ CALL1,
+ )
+ .fetch_all(&pool)
+ .await?;
+
+ assert_eq!(source_ids, vec![creator_team.to_string()]);
+
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn patch_call_record_share_with_team_true_noop_when_creator_has_no_team(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool.clone());
+
+ // USER_A is the creator and has no team — the call should succeed but
+ // not create any team entity_access rows.
+ repo.patch_call_record(
+ &CALL1,
+ &EditCallRecordRequest {
+ share_permission: None,
+ share_with_team: Some(true),
+ },
+ )
+ .await?;
+
+ let count = sqlx::query_scalar!(
+ r#"SELECT COUNT(*) as "count!" FROM entity_access
+ WHERE entity_id = $1 AND source_type = 'team'"#,
+ CALL1,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert_eq!(count, 0);
+
+ let flag = sqlx::query_scalar!(r#"SELECT share_with_team FROM calls WHERE id = $1"#, CALL1,)
+ .fetch_one(&pool)
+ .await?;
+ assert!(flag);
+
+ Ok(())
+}