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(ownership): entity_access add bot access source type (#6396)

Will Hutchinson1c2dc46842eb
diff --git a/.sqlx/query-03126b7a70835aac508c3f236c9e5bcd98c0df2596f1d098c08cd4308583f307.json b/.sqlx/query-03126b7a70835aac508c3f236c9e5bcd98c0df2596f1d098c08cd4308583f307.json
index ee80650f37..259180ab58 100644
--- a/.sqlx/query-03126b7a70835aac508c3f236c9e5bcd98c0df2596f1d098c08cd4308583f307.json
+++ b/.sqlx/query-03126b7a70835aac508c3f236c9e5bcd98c0df2596f1d098c08cd4308583f307.json
@@ -14,7 +14,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json b/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json
index 72262bfe13..af1c40addb 100644
--- a/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json
+++ b/.sqlx/query-370a87eb4e8c69c5430716f06c0b23ec03e343c026d2e13ba7c4337fab85cd05.json
@@ -15,7 +15,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json b/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
index b75a3a2ff5..11763184b5 100644
--- a/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
+++ b/.sqlx/query-41de07226ced9b95c7419c9e6d5d9bd9c5890cf1c144f0f8905664cd72c7f132.json
@@ -15,7 +15,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json b/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
index 7eadb2f534..87ce24c182 100644
--- a/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
+++ b/.sqlx/query-44cc40d5175302af5445a34d4add1e7dc2d0cea3efa5b87c16cb2416b43fc098.json
@@ -15,7 +15,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json b/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json
index 113b9e269a..3b0277bbdf 100644
--- a/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json
+++ b/.sqlx/query-5b17a30f841372cce9989af409baf993e24bfe90d3a3553f6851b3e92c8540eb.json
@@ -23,7 +23,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/.sqlx/query-cf53541f8a737c46ac505cb6511044d4e1571addbaa8c0c56f099378188b9c66.json b/.sqlx/query-cf53541f8a737c46ac505cb6511044d4e1571addbaa8c0c56f099378188b9c66.json
index 3a30e7dcd0..ab2fea542b 100644
--- a/.sqlx/query-cf53541f8a737c46ac505cb6511044d4e1571addbaa8c0c56f099378188b9c66.json
+++ b/.sqlx/query-cf53541f8a737c46ac505cb6511044d4e1571addbaa8c0c56f099378188b9c66.json
@@ -13,7 +13,8 @@
"Enum": [
"channel",
"team",
- "user"
+ "user",
+ "bot"
]
}
}
diff --git a/crates/entity_access/src/domain/models/access_explanation.rs b/crates/entity_access/src/domain/models/access_explanation.rs
index 5bf5ca70f2..2fa60e4f14 100644
--- a/crates/entity_access/src/domain/models/access_explanation.rs
+++ b/crates/entity_access/src/domain/models/access_explanation.rs
@@ -158,7 +158,7 @@ pub enum AccessGrant {
EntityAccess {
/// Who the row was granted to.
source_type: EntityAccessSourceType,
- /// User id, channel id, or team id.
+ /// User or bot principal, channel id, or team id.
source_id: String,
/// Level stored on the row.
access_level: AccessLevel,
@@ -428,6 +428,7 @@ fn format_source_type(source_type: EntityAccessSourceType) -> &'static str {
EntityAccessSourceType::User => "user",
EntityAccessSourceType::Channel => "channel",
EntityAccessSourceType::Team => "team",
+ EntityAccessSourceType::Bot => "bot",
}
}
diff --git a/crates/entity_access/src/domain/models/access_explanation/test.rs b/crates/entity_access/src/domain/models/access_explanation/test.rs
index 26f6a8daaa..44a012c9a9 100644
--- a/crates/entity_access/src/domain/models/access_explanation/test.rs
+++ b/crates/entity_access/src/domain/models/access_explanation/test.rs
@@ -175,3 +175,18 @@ fn display_lists_each_grant() {
assert!(rendered.contains("effective: view"));
assert!(rendered.contains("public_link view"));
}
+
+#[test]
+fn display_lists_bot_typed_entity_access_grant() {
+ let grant = AccessGrant::EntityAccess {
+ source_type: EntityAccessSourceType::Bot,
+ source_id: "bot|00000000-0000-0000-0000-000000000123".to_string(),
+ access_level: AccessLevel::Owner,
+ granted_from_project_id: None,
+ };
+
+ assert_eq!(
+ grant.to_string(),
+ "entity_access bot bot|00000000-0000-0000-0000-000000000123 owner"
+ );
+}
diff --git a/crates/entity_access/src/outbound/pg_access_repo/test.rs b/crates/entity_access/src/outbound/pg_access_repo/test.rs
index d28d05bfc2..7e5c401f14 100644
--- a/crates/entity_access/src/outbound/pg_access_repo/test.rs
+++ b/crates/entity_access/src/outbound/pg_access_repo/test.rs
@@ -720,6 +720,38 @@ async fn team_item_access_includes_team_channels_and_bot_grants(
Ok(())
}
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn team_item_access_resolves_bot_typed_grant(pool: PgPool) -> anyhow::Result<()> {
+ let team_id = Uuid::new_v4();
+ let bot_id = BotId::new_from_uuid(Uuid::new_v4());
+ let bot_principal = bot_id.into_storage_id();
+ let document_id = Uuid::new_v4();
+
+ insert_pg_bot_team(&pool, team_id).await?;
+ insert_pg_bot(&pool, bot_id, None, Some(team_id)).await?;
+ insert_pg_bot_entity_access(
+ &pool,
+ document_id,
+ "document",
+ bot_principal.as_ref(),
+ "bot",
+ AccessLevel::Owner,
+ )
+ .await?;
+
+ let access = PgAccessRepository::new(pool)
+ .get_team_entity_access(
+ bot_id,
+ team_id,
+ &document_id.to_string(),
+ EntityType::Document,
+ )
+ .await?;
+
+ assert_eq!(access, Some(AccessLevel::Owner));
+ Ok(())
+}
+
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
async fn team_item_access_allows_public_link_sharing(pool: PgPool) -> anyhow::Result<()> {
let team_id = Uuid::new_v4();
diff --git a/crates/macro_db_client/migrations/20260910144346_add_bot_entity_access_source_type.sql b/crates/macro_db_client/migrations/20260910144346_add_bot_entity_access_source_type.sql
new file mode 100644
index 0000000000..bf66c27716
--- /dev/null
+++ b/crates/macro_db_client/migrations/20260910144346_add_bot_entity_access_source_type.sql
@@ -0,0 +1 @@
+ALTER TYPE entity_access_source_type ADD VALUE IF NOT EXISTS 'bot';
diff --git a/crates/models_entity_access_management/src/lib.rs b/crates/models_entity_access_management/src/lib.rs
index 2c86fb38f9..c679feef1b 100644
--- a/crates/models_entity_access_management/src/lib.rs
+++ b/crates/models_entity_access_management/src/lib.rs
@@ -17,4 +17,6 @@ pub enum EntityAccessSourceType {
Team,
/// User source
User,
+ /// Bot source
+ Bot,
}