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(favorites): use get_entity_permission for channel favorites (#8361)
Jacob Beckerman2eb8037fe6cb
diff --git a/crates/entity_access/src/inbound/axum_extractors/entity_body.rs b/crates/entity_access/src/inbound/axum_extractors/entity_body.rsindex 982a7991a4..8532982c66 100644--- a/crates/entity_access/src/inbound/axum_extractors/entity_body.rs+++ b/crates/entity_access/src/inbound/axum_extractors/entity_body.rs@@ -98,21 +98,32 @@ where});}- let user = match authorization {+ let (user, user_org_id) = match authorization {MacroAuthorization::User(user) | MacroAuthorization::Internal(Some(user)) => {- user.macro_user_id+ let org_id = user.user_context.organization_id.map(i64::from);+ (user.macro_user_id, org_id)}MacroAuthorization::Harness(_) => return Err(ExtractorError::Unauthorized),MacroAuthorization::Bot(_) | MacroAuthorization::Internal(None) => {unreachable!("bot and identity-less internal access returned above")}};- let access_level = service- .get_access_level(Some(&user), &entity_id, entity_type)- .await- .map_err(ExtractorError::from)?- .ok_or(ExtractorError::Unauthorized)?;- let entity_permission = EntityPermission::AccessLevel { access_level };+ // Channels require `get_entity_permission` with user_org_id for proper+ // access checks on public/organization/team channels. Other entity+ // types use the simpler `get_access_level`.+ let entity_permission = if entity_type == EntityType::Channel {+ service+ .get_entity_permission(Some(&user), &entity_id, entity_type, user_org_id)+ .await+ .map_err(ExtractorError::from)?+ } else {+ let access_level = service+ .get_access_level(Some(&user), &entity_id, entity_type)+ .await+ .map_err(ExtractorError::from)?+ .ok_or(ExtractorError::Unauthorized)?;+ EntityPermission::AccessLevel { access_level }+ };if !entity_permission.satisfies::<T>() {return Err(ExtractorError::Unauthorized);}diff --git a/crates/entity_access/src/inbound/axum_extractors/entity_body/test.rs b/crates/entity_access/src/inbound/axum_extractors/entity_body/test.rsindex 74af44ba20..26ce514d7a 100644--- a/crates/entity_access/src/inbound/axum_extractors/entity_body/test.rs+++ b/crates/entity_access/src/inbound/axum_extractors/entity_body/test.rs@@ -435,36 +435,51 @@ async fn bot_typed_body_failure_is_rejected_before_acl_lookup() {}#[tokio::test]-async fn channels_and_static_files_keep_get_access_level_semantics() {+async fn channels_use_get_entity_permission_for_org_aware_access() {let state = TestState::new(Some(AccessLevel::View));+ let response = router(state.clone())+ .oneshot(+ request("/view")+ .header(header::AUTHORIZATION, "Bearer valid")+ .body(body("channel", "channel-1"))+ .unwrap(),+ )+ .await+ .unwrap();- for (entity_type, entity_id) in [("channel", "channel-1"), ("static_file", "static-1")] {- let response = router(state.clone())- .oneshot(- request("/view")- .header(header::AUTHORIZATION, "Bearer valid")- .body(body(entity_type, entity_id))- .unwrap(),- )- .await- .unwrap();+ assert_eq!(response.status(), StatusCode::OK);+ // Channels use get_entity_permission (which delegates to get_access_level+ // in the fake) to support organization-aware access for public/org channels.+ assert_eq!(+ state.entity_access.calls(),+ [AccessCall {+ user_id: Some(USER_ID.to_string()),+ entity_id: "channel-1".to_string(),+ entity_type: EntityType::Channel,+ },]+ );+}- assert_eq!(response.status(), StatusCode::OK);- }+#[tokio::test]+async fn static_files_use_get_access_level() {+ let state = TestState::new(Some(AccessLevel::View));+ let response = router(state.clone())+ .oneshot(+ request("/view")+ .header(header::AUTHORIZATION, "Bearer valid")+ .body(body("static_file", "static-1"))+ .unwrap(),+ )+ .await+ .unwrap();+ assert_eq!(response.status(), StatusCode::OK);assert_eq!(state.entity_access.calls(),- [- AccessCall {- user_id: Some(USER_ID.to_string()),- entity_id: "channel-1".to_string(),- entity_type: EntityType::Channel,- },- AccessCall {- user_id: Some(USER_ID.to_string()),- entity_id: "static-1".to_string(),- entity_type: EntityType::StaticFile,- },- ]+ [AccessCall {+ user_id: Some(USER_ID.to_string()),+ entity_id: "static-1".to_string(),+ entity_type: EntityType::StaticFile,+ },]);}