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(bots): allow channel member to create a scoped bot to a channel (#5298)
Will Hutchinson7d5d3563e46d
diff --git a/crates/bots/src/inbound/axum_router.rs b/crates/bots/src/inbound/axum_router.rsindex 0249cb8a79..04f0226877 100644--- a/crates/bots/src/inbound/axum_router.rs+++ b/crates/bots/src/inbound/axum_router.rs@@ -19,7 +19,7 @@ use axum::{};use entity_access::{domain::{- models::{AdminParticipantRole, EntityAccessReceipt},+ models::{EntityAccessReceipt, MemberParticipantRole},ports::EntityAccessService,},inbound::axum_extractors::ChannelAccessLevelExtractor,@@ -167,7 +167,7 @@ where}fn caller_from_receipt(- receipt: &EntityAccessReceipt<AdminParticipantRole>,+ receipt: &EntityAccessReceipt<MemberParticipantRole>,) -> Result<MacroUserIdStr<'static>, BotsHandlerErr> {receipt.get_authenticated_user()@@ -396,7 +396,7 @@ async fn list_channel_bots_handler<Auth: MacroAuthorizationService,>(State(state): State<BotsRouterState<S, Svc, Auth>>,- _access: ChannelAccessLevelExtractor<AdminParticipantRole, Svc, Auth>,+ _access: ChannelAccessLevelExtractor<MemberParticipantRole, Svc, Auth>,Path(path): Path<ChannelPath>,) -> Result<Json<Vec<Bot>>, BotsHandlerErr> {Ok(Json(@@ -410,7 +410,7 @@ async fn add_channel_bot_handler<Auth: MacroAuthorizationService,>(State(state): State<BotsRouterState<S, Svc, Auth>>,- access: ChannelAccessLevelExtractor<AdminParticipantRole, Svc, Auth>,+ access: ChannelAccessLevelExtractor<MemberParticipantRole, Svc, Auth>,Path(path): Path<ChannelPath>,Json(req): Json<AddChannelBotRequest>,) -> Result<StatusCode, BotsHandlerErr> {@@ -428,7 +428,7 @@ async fn remove_channel_bot_handler<Auth: MacroAuthorizationService,>(State(state): State<BotsRouterState<S, Svc, Auth>>,- access: ChannelAccessLevelExtractor<AdminParticipantRole, Svc, Auth>,+ access: ChannelAccessLevelExtractor<MemberParticipantRole, Svc, Auth>,Path(path): Path<ChannelBotPath>,) -> Result<StatusCode, BotsHandlerErr> {let caller = caller_from_receipt(&access.entity_access_receipt)?;diff --git a/crates/bots/src/inbound/axum_router/tests.rs b/crates/bots/src/inbound/axum_router/tests.rsindex 466dcdde24..6a414ccd7d 100644--- a/crates/bots/src/inbound/axum_router/tests.rs+++ b/crates/bots/src/inbound/axum_router/tests.rs@@ -575,29 +575,6 @@ async fn bot_remove_channel_requires_bot_usability() {assert_eq!(service.remove_calls.load(Ordering::SeqCst), 1);}-#[tokio::test]-async fn channel_member_cannot_add_bot_to_channel() {- let service = TestBotService::new(TestBotMode::Ok);- let channel_id = Uuid::new_v4();- let bot_id = BotId::new_from_uuid(Uuid::new_v4());- let request = Request::builder()- .method("POST")- .uri(format!("/channels/{channel_id}/bots"))- .header("content-type", "application/json")- .body(Body::from(- serde_json::json!({ "bot_id": bot_id }).to_string(),- ))- .unwrap();-- let response = router(service.clone(), EntityParticipantRole::Member)- .oneshot(request)- .await- .unwrap();-- assert_eq!(response.status(), StatusCode::UNAUTHORIZED);- assert_eq!(service.add_calls.load(Ordering::SeqCst), 0);-}-#[tokio::test]async fn channel_admin_still_needs_bot_usability_to_add_bot() {let service = TestBotService::new(TestBotMode::Unauthorized);@@ -621,26 +598,6 @@ async fn channel_admin_still_needs_bot_usability_to_add_bot() {assert_eq!(service.add_calls.load(Ordering::SeqCst), 1);}-#[tokio::test]-async fn channel_member_cannot_remove_bot_from_channel() {- let service = TestBotService::new(TestBotMode::Ok);- let channel_id = Uuid::new_v4();- let bot_id = BotId::new_from_uuid(Uuid::new_v4());- let request = Request::builder()- .method("DELETE")- .uri(format!("/channels/{channel_id}/bots/{bot_id}"))- .body(Body::empty())- .unwrap();-- let response = router(service.clone(), EntityParticipantRole::Member)- .oneshot(request)- .await- .unwrap();-- assert_eq!(response.status(), StatusCode::UNAUTHORIZED);- assert_eq!(service.remove_calls.load(Ordering::SeqCst), 0);-}-#[tokio::test]async fn channel_admin_still_needs_bot_usability_to_remove_bot() {let service = TestBotService::new(TestBotMode::Unauthorized);diff --git a/crates/bots/src/inbound/channel_webhook_router.rs b/crates/bots/src/inbound/channel_webhook_router.rsindex f5e8749f74..c36a9b1d48 100644--- a/crates/bots/src/inbound/channel_webhook_router.rs+++ b/crates/bots/src/inbound/channel_webhook_router.rs@@ -24,7 +24,7 @@ use channels::domain::{};use entity_access::{domain::{- models::{AdminParticipantRole, EntityAccessReceipt},+ models::{EntityAccessReceipt, MemberParticipantRole},ports::EntityAccessService,},inbound::axum_extractors::ChannelAccessLevelExtractor,@@ -212,7 +212,7 @@ where}fn caller_from_receipt(- receipt: &EntityAccessReceipt<AdminParticipantRole>,+ receipt: &EntityAccessReceipt<MemberParticipantRole>,) -> Result<MacroUserIdStr<'static>, ChannelBotWebhookHandlerErr> {receipt.get_authenticated_user()@@ -241,7 +241,7 @@ fn caller_from_receipt(#[tracing::instrument(err, skip_all)]pub async fn create_channel_scoped_bot_handler<BotSvc, ChannelPoster, AccessSvc, Auth>(State(state): State<ChannelBotWebhookRouterState<BotSvc, ChannelPoster, AccessSvc, Auth>>,- access: ChannelAccessLevelExtractor<AdminParticipantRole, AccessSvc, Auth>,+ access: ChannelAccessLevelExtractor<MemberParticipantRole, AccessSvc, Auth>,Path(path): Path<ChannelPath>,Json(req): Json<CreateChannelScopedBotRequest>,) -> Result<(StatusCode, Json<CreateChannelScopedBotResponse>), ChannelBotWebhookHandlerErr>diff --git a/crates/bots/src/inbound/channel_webhook_router/tests.rs b/crates/bots/src/inbound/channel_webhook_router/tests.rsindex 390d506351..bf407e54df 100644--- a/crates/bots/src/inbound/channel_webhook_router/tests.rs+++ b/crates/bots/src/inbound/channel_webhook_router/tests.rs@@ -716,28 +716,6 @@ fn scoped_bot_request_body() -> Body {)}-#[tokio::test]-async fn channel_webhook_router_member_cannot_create_scoped_bot() {- let bot_id = BotId::new_from_uuid(Uuid::new_v4());- let service = TestBotService::for_create(scoped_bot_response(bot_id));- let poster = TestChannelPoster::new();- let channel_id = Uuid::new_v4();- let request = Request::builder()- .method("POST")- .uri(format!("/channels/{channel_id}/bots/scoped"))- .header("content-type", "application/json")- .body(scoped_bot_request_body())- .unwrap();-- let response = router(service.clone(), poster, EntityParticipantRole::Member)- .oneshot(request)- .await- .unwrap();-- assert_eq!(response.status(), StatusCode::UNAUTHORIZED);- assert_eq!(service.create_calls.load(Ordering::SeqCst), 0);-}-#[tokio::test]async fn channel_webhook_router_admin_can_create_scoped_bot() {let bot_id = BotId::new_from_uuid(Uuid::new_v4());