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): internal access (#782)
Eric Hayes234fa7b70066
diff --git a/rust/cloud-storage/ai_tools/src/rewrite/tool.rs b/rust/cloud-storage/ai_tools/src/rewrite/tool.rsindex 513446783c..e41c56e3df 100644--- a/rust/cloud-storage/ai_tools/src/rewrite/tool.rs+++ b/rust/cloud-storage/ai_tools/src/rewrite/tool.rs@@ -37,12 +37,17 @@ impl AsyncTool<ToolServiceContext, RequestContext> for MarkdownRewrite {) -> ToolResult<Self::Output> {tracing::info!(markdown_file_id=?self.markdown_file_id, "Rewrite params");- rewrite_markdown(self.clone(), &sc.scribe, &request_context.user_id)- .await- .map_err(|err| ToolCallError {- description: "An internal error occured rewriting generating rewrite".into(),- internal_error: err,- })+ rewrite_markdown(+ self.clone(),+ &sc.scribe,+ &request_context.user_id,+ request_context.jwt_token.clone(),+ )+ .await+ .map_err(|err| ToolCallError {+ description: "An internal error occured rewriting generating rewrite".into(),+ internal_error: err,+ })}}@@ -50,10 +55,11 @@ pub async fn rewrite_markdown(request: MarkdownRewrite,scribe: &ToolScribe,_user_id: &str,+ jwt: String,) -> Result<AIDiffResponse, Error> {let document = scribe.document- .fetch(request.markdown_file_id.clone())+ .fetch_with_auth(request.markdown_file_id.clone(), jwt).document_content().await?;if document.file_type() != FileType::Md {diff --git a/rust/cloud-storage/document_cognition_service/src/service/attachment/fetch.rs b/rust/cloud-storage/document_cognition_service/src/service/attachment/fetch.rsindex 9217d6d253..b3f3a59e53 100644--- a/rust/cloud-storage/document_cognition_service/src/service/attachment/fetch.rs+++ b/rust/cloud-storage/document_cognition_service/src/service/attachment/fetch.rs@@ -71,7 +71,7 @@ pub async fn fetchium(AttachmentType::Document => {let document = scribe.document- .fetch(attachment.attachment_id.clone())+ .fetch_with_auth(attachment.attachment_id.clone(), jwt.to_string()).document_content().await?;if document.file_type().is_image() {diff --git a/rust/cloud-storage/document_storage_service/src/api/items/get_item_ids.rs b/rust/cloud-storage/document_storage_service/src/api/items/get_item_ids.rsindex 2e5aed40e6..08e5457838 100644--- a/rust/cloud-storage/document_storage_service/src/api/items/get_item_ids.rs+++ b/rust/cloud-storage/document_storage_service/src/api/items/get_item_ids.rs@@ -1,3 +1,4 @@+use crate::api::MACRO_INTERNAL_USER_ID;use crate::api::context::ApiContext;use axum::extract::{Query, State};use axum::http::StatusCode;@@ -25,7 +26,7 @@ pub async fn get_item_ids_handler(let user_id = user_context.user_id.clone();- if matches!(user_id.as_str(), "" | "INTERNAL") {+ if matches!(user_id.as_str(), "" | MACRO_INTERNAL_USER_ID) {return Err((StatusCode::UNAUTHORIZED,"No user id found in context".to_string(),diff --git a/rust/cloud-storage/document_storage_service/src/api/items/soup.rs b/rust/cloud-storage/document_storage_service/src/api/items/soup.rsindex 8acdc7c5cf..aea7c4aa15 100644--- a/rust/cloud-storage/document_storage_service/src/api/items/soup.rs+++ b/rust/cloud-storage/document_storage_service/src/api/items/soup.rs@@ -1,3 +1,4 @@+use crate::api::MACRO_INTERLNA_USER_ID;use crate::api::context::ApiContext;use axum::Extension;use axum::Json;@@ -148,7 +149,7 @@ where}: Params,cursor: Option<CursorWithVal<String, SimpleSortMethod>>,) -> Result<PaginatedOpaqueCursor<FrecencySoupItem>, SoupHandlerErr> {- if matches!(user_context.user_id.as_str(), "" | "INTERNAL") {+ if matches!(user_context.user_id.as_str(), "" | MACRO_INTERNAL_USER_ID) {return Err(SoupHandlerErr::Unauthorized);}diff --git a/rust/cloud-storage/document_storage_service/src/api/items/validate_item_ids.rs b/rust/cloud-storage/document_storage_service/src/api/items/validate_item_ids.rsindex 6fd7741651..2ffd3726f8 100644--- a/rust/cloud-storage/document_storage_service/src/api/items/validate_item_ids.rs+++ b/rust/cloud-storage/document_storage_service/src/api/items/validate_item_ids.rs@@ -1,3 +1,4 @@+use crate::api::MACRO_INTERNAL_USER_ID;use crate::api::context::ApiContext;use axum::Extension;use axum::extract::{Json, State};@@ -16,7 +17,7 @@ pub async fn handler(let user_id = user_context.user_id.clone();- if matches!(user_id.as_str(), "" | "INTERNAL") {+ if matches!(user_id.as_str(), "" | MACRO_INTERNAL_USER_ID) {return Err((StatusCode::UNAUTHORIZED,"No user id found in context".to_string(),diff --git a/rust/cloud-storage/document_storage_service/src/api/middleware/internal_access.rs b/rust/cloud-storage/document_storage_service/src/api/middleware/internal_access.rsindex 2d40f3ff81..b13f0a241d 100644--- a/rust/cloud-storage/document_storage_service/src/api/middleware/internal_access.rs+++ b/rust/cloud-storage/document_storage_service/src/api/middleware/internal_access.rs@@ -1,6 +1,6 @@use crate::api::{- MACRO_DOCUMENT_STORAGE_SERVICE_AUTH_HEADER_KEY, MACRO_INTERNAL_USER_ID_HEADER_KEY,- context::DocumentStorageServiceAuthKey,+ MACRO_DOCUMENT_STORAGE_SERVICE_AUTH_HEADER_KEY, MACRO_INTERNAL_USER_ID,+ MACRO_INTERNAL_USER_ID_HEADER_KEY, context::DocumentStorageServiceAuthKey,};use axum::{extract::{Request, State},@@ -84,7 +84,7 @@ pub(in crate::api) async fn handler(.get(MACRO_INTERNAL_USER_ID_HEADER_KEY).and_then(|header| header.to_str().ok()).map(|header| header.to_string())- .unwrap_or("INTERNAL".to_string());+ .unwrap_or(MACRO_INTERNAL_USER_ID.to_string());// Attach user_id to the UserContextreq.extensions_mut().insert(UserContext {diff --git a/rust/cloud-storage/document_storage_service/src/api/mod.rs b/rust/cloud-storage/document_storage_service/src/api/mod.rsindex 7d39542536..d4d6e9c5a8 100644--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs@@ -49,6 +49,7 @@ pub static MACRO_DOCUMENT_STORAGE_SERVICE_AUTH_HEADER_KEY: &str ="x-document-storage-service-auth-key";pub static MACRO_INTERNAL_USER_ID_HEADER_KEY: &str = "x-document-storage-service-user-id";+pub const MACRO_INTERNAL_USER_ID: &str = "macro|[email protected]";// permission based constantspub static MACRO_READ_PROFESSIONAL_PERMISSION_ID: &str = "read:professional_features";diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rsindex e98e030dba..a8065eb104 100644--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs@@ -41,7 +41,7 @@ where} = parts.extract().await- .map_err(|_| AccessLevelErr::InternalErr)?;+ .map_err(|_| AccessLevelErr::UnAuthorized)?;let document_context: Extension<DocumentBasic> =<Extension<DocumentBasic>>::from_request_parts(parts, state).await