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
feat(entity_access): update to use macro_authorization (#5018)
Will Hutchinson53a9eb85660e
diff --git a/Cargo.lock b/Cargo.lockindex 89ef639d9d..9b1fb358ee 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -5483,11 +5483,14 @@ dependencies = ["filter_ast","http-body-util","item_filters",+ "macro_authorization","macro_db_migrator","macro_user_id","macro_uuid","model-error-response",+ "model_user","models_pagination",+ "rootcause","serde","serde_json","sqlx",diff --git a/crates/entity_access/Cargo.toml b/crates/entity_access/Cargo.tomlindex 9d37004884..fcb0f71579 100644--- a/crates/entity_access/Cargo.toml+++ b/crates/entity_access/Cargo.toml@@ -10,7 +10,6 @@ axum = ["dep:macro_authorization","dep:model","dep:model-error-response",- "dep:model_user",]default = ["axum", "inbound", "outbound", "ports"]inbound = ["axum", "ports"]@@ -42,7 +41,6 @@ axum = { workspace = true, optional = true }macro_authorization = { path = "../macro_authorization", optional = true, default-features = false, features = ["axum"] }model = { path = "../model", optional = true }model-error-response = { path = "../model-error-response", optional = true }-model_user = { path = "../model_user", optional = true, features = ["axum"] }# OpenAPI schema (optional)utoipa = { workspace = true, optional = true }@@ -56,6 +54,7 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }cool_asserts = "2"macro_db_migrator = { path = "../macro_db_migrator" }mockall = { workspace = true }+model_user = { path = "../model_user" }rootcause = { workspace = true }sqlx = { workspace = true, features = ["postgres", "runtime-tokio-rustls"] }tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }diff --git a/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs b/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rsindex 738d44ba22..c878916a04 100644--- a/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs+++ b/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs@@ -5,37 +5,45 @@ use std::marker::PhantomData;use std::sync::Arc;use axum::{- Extension, RequestPartsExt,+ RequestPartsExt,extract::{FromRef, FromRequestParts, Path},http::request::Parts,};+use macro_authorization::{+ MacroAuthorizationService, MacroAuthorizationState, OptionalMacroAuthorizationExtractor,+};use uuid::Uuid;-use super::{ExtractorError, InternalUser, RequiredPermission};+use super::{ExtractorError, RequiredPermission};use crate::domain::{models::{AccessLevel, Entity, EntityAccessAuth, EntityAccessReceipt, EntityPermission, EntityType,},ports::EntityAccessService,};-use model_user::axum_extractor::MacroUserExtractor;/// Validates that the user satisfies the required permission for a foreign entity.////// Foreign entities grant View access only. The extractor reads either/// `foreign_entity_id` or `id` from the route path parameters.+///+/// Type parameter `T` specifies the required access level.+/// Type parameter `Svc` is the entity access service implementation.+/// Type parameter `Auth` is the authorization service implementation.#[derive(Debug)]-pub struct ForeignEntityAccessLevelExtractor<T: RequiredPermission, Svc> {+pub struct ForeignEntityAccessLevelExtractor<T: RequiredPermission, Svc, Auth> {/// The entity access receipt.pub entity_access_receipt: EntityAccessReceipt<T>,- _marker: PhantomData<(T, Svc)>,+ _marker: PhantomData<(T, Svc, Auth)>,}-impl<T, S, Svc> FromRequestParts<S> for ForeignEntityAccessLevelExtractor<T, Svc>+impl<T, S, Svc, Auth> FromRequestParts<S> for ForeignEntityAccessLevelExtractor<T, Svc, Auth>whereT: RequiredPermission,Arc<Svc>: FromRef<S>,Svc: EntityAccessService,+ MacroAuthorizationState<Auth>: FromRef<S>,+ Auth: MacroAuthorizationService,S: Send + Sync + 'static,{type Rejection = ExtractorError;@@ -50,12 +58,15 @@ where})?;let foreign_entity_id = extract_foreign_entity_id(&path_params)?.to_string();- let internal_user: Option<Extension<InternalUser>> = parts- .extract()+ let OptionalMacroAuthorizationExtractor {+ macro_user_id,+ is_internal_access,+ ..+ } = OptionalMacroAuthorizationExtractor::<Auth>::from_request_parts(parts, state).await- .map_err(|_| ExtractorError::Internal)?;+ .map_err(ExtractorError::from)?;- if internal_user.is_some() {+ if macro_user_id.is_none() && is_internal_access {return Self::from_permission(foreign_entity_id,EntityAccessAuth::Internal,@@ -63,10 +74,9 @@ where);}- let MacroUserExtractor { macro_user_id, .. } = parts- .extract()- .await- .map_err(|_| ExtractorError::Unauthorized)?;+ let Some(macro_user_id) = macro_user_id else {+ return Err(ExtractorError::Unauthorized);+ };let permission = service.get_entity_permission(@@ -86,7 +96,7 @@ where}}-impl<T: RequiredPermission, Svc> ForeignEntityAccessLevelExtractor<T, Svc> {+impl<T: RequiredPermission, Svc, Auth> ForeignEntityAccessLevelExtractor<T, Svc, Auth> {fn from_permission(foreign_entity_id: String,auth: EntityAccessAuth,diff --git a/crates/entity_access/src/inbound/axum_extractors/mod.rs b/crates/entity_access/src/inbound/axum_extractors/mod.rsindex 3c90c89253..9b45427719 100644--- a/crates/entity_access/src/inbound/axum_extractors/mod.rs+++ b/crates/entity_access/src/inbound/axum_extractors/mod.rs@@ -30,15 +30,13 @@ pub use entity_permission::EntityPermissionExtractor;pub use foreign_entity::ForeignEntityAccessLevelExtractor;pub use history::HistoryAccessExtractor;pub use pin::PinAccessLevelExtractor;-pub use project::{- ProjectAccessLevelExtractor, ProjectBodyAccessLevelExtractor, ProjectBodyAccessLevelExtractorV2,-};+pub use project::{ProjectAccessLevelExtractor, ProjectBodyAccessLevelExtractorV2};pub use team::{MacroUserTeamExtractorV2, OptionalMacroUserTeamExtractorV2};pub use thread::ThreadAccessLevelExtractor;use std::borrow::Cow;-use crate::domain::models::{AccessError, AccessLevel};+use crate::domain::models::AccessError;use axum::{Json,http::StatusCode,@@ -49,15 +47,6 @@ use model_error_response::ErrorResponse;pub use crate::domain::models::RequiredPermission;-/// Marker struct for internal service-to-service requests.-///-/// Middleware inserts this into request extensions for authenticated internal callers.-#[derive(Debug, Clone)]-pub struct InternalUser {- /// The access level granted to the internal user.- pub access_level: AccessLevel,-}-/// Error type for access extractors that can be returned as HTTP responses.#[derive(Debug, thiserror::Error)]pub enum ExtractorError {diff --git a/crates/entity_access/src/inbound/axum_extractors/project.rs b/crates/entity_access/src/inbound/axum_extractors/project.rsindex ea72bb7906..a103ad6230 100644--- a/crates/entity_access/src/inbound/axum_extractors/project.rs+++ b/crates/entity_access/src/inbound/axum_extractors/project.rs@@ -17,7 +17,7 @@ use macro_authorization::{use macro_user_id::user_id::MacroUserIdStr;use serde::de::DeserializeOwned;-use super::{ExtractorError, InternalUser, RequiredPermission};+use super::{ExtractorError, RequiredPermission};use crate::domain::{models::{AccessLevel, Entity, EntityAccessAuth, EntityAccessReceipt, EntityPermission, EntityType,@@ -25,7 +25,6 @@ use crate::domain::{ports::EntityAccessService,};use model::project::BasicProject;-use model_user::axum_extractor::OptionalMacroUserExtractor;/// Validates that the user has at least the required access level to a project.///@@ -198,94 +197,12 @@ impl ProjectOrParentId {/// Extractor which checks the body for a project and validates the access level if it exists.///-/// Downstream consumers also use the body (which is an antipattern) so we need to keep the value around.-#[derive(Debug)]-pub enum ProjectBodyAccessLevelExtractor<T: RequiredPermission, V, Svc> {- /// A project was found in the body and access was validated.- FoundProject {- /// The project ID that was found.- project: ProjectOrParentId,- /// Marker for the desired access level.- desired: PhantomData<(T, Svc)>,- /// The entity access receipt- entity_access_receipt: EntityAccessReceipt<T>,- /// The parsed body.- body: V,- },- /// No project was found in the body.- ProjectNotInBody {- /// The parsed body.- body: V,- /// Marker for type parameters.- _marker: PhantomData<(T, Svc)>,- },-}--impl<T: RequiredPermission, V, Svc> ProjectBodyAccessLevelExtractor<T, V, Svc> {- /// Extract the body from this extractor.- pub fn into_inner(self) -> V {- match self {- Self::FoundProject { body, .. } | Self::ProjectNotInBody { body, .. } => body,- }- }-- fn from_outcome(outcome: ProjectBodyAccessOutcome<T, V>) -> Self {- match outcome {- ProjectBodyAccessOutcome::FoundProject {- project,- entity_access_receipt,- body,- } => Self::FoundProject {- project,- desired: PhantomData,- entity_access_receipt,- body,- },- ProjectBodyAccessOutcome::ProjectNotInBody { body } => Self::ProjectNotInBody {- body,- _marker: PhantomData,- },- }- }-}--impl<T, S, V, Svc> FromRequest<S> for ProjectBodyAccessLevelExtractor<T, V, Svc>-where- T: RequiredPermission,- Arc<Svc>: FromRef<S>,- Svc: EntityAccessService,- S: Send + Sync + 'static,- V: DeserializeOwned,-{- type Rejection = ExtractorError;-- async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> {- let service = <Arc<Svc>>::from_ref(state);- let OptionalMacroUserExtractor { macro_user_id, .. } = req- .extract_parts()- .await- .map_err(|_| ExtractorError::Internal)?;- let internal_user: Option<Extension<InternalUser>> = if macro_user_id.is_none() {- req.extract_parts()- .await- .map_err(|_| ExtractorError::Internal)?- } else {- None- };-- extract_project_body_access(req, service, macro_user_id, internal_user.is_some())- .await- .map(Self::from_outcome)- }-}--/// V2 of [`ProjectBodyAccessLevelExtractor`], backed by state-resolved authorization.-///-/// This preserves the V1 body and receipt semantics while resolving identity-/// through [`OptionalMacroAuthorizationExtractor`] and using native internal-/// authorization instead of request extensions. Type parameter `T` specifies-/// the required project access level, `V` is the request body, `Svc` is the-/// entity access service, and `Auth` is the authorization service.+/// Downstream consumers also use the body (which is an antipattern) so we need+/// to keep the value around. Identity is resolved through+/// [`OptionalMacroAuthorizationExtractor`], which natively supports internal+/// authorization. Type parameter `T` specifies the required project access+/// level, `V` is the request body, `Svc` is the entity access service, and+/// `Auth` is the authorization service.#[derive(Debug)]pub enum ProjectBodyAccessLevelExtractorV2<T: RequiredPermission, V, Svc, Auth> {/// A project was found in the body and access was validated.@@ -308,7 +225,6 @@ pub enum ProjectBodyAccessLevelExtractorV2<T: RequiredPermission, V, Svc, Auth>},}-#[allow(dead_code)]impl<T: RequiredPermission, V, Svc, Auth> ProjectBodyAccessLevelExtractorV2<T, V, Svc, Auth> {/// Extract the body from this extractor.pub fn into_inner(self) -> V {diff --git a/crates/foreign_entity/Cargo.toml b/crates/foreign_entity/Cargo.tomlindex 6f1485d4ea..0ee35fe4b0 100644--- a/crates/foreign_entity/Cargo.toml+++ b/crates/foreign_entity/Cargo.toml@@ -8,6 +8,7 @@ version = "0.1.0"default = ["outbound", "ports", "service"]inbound = ["dep:axum",+ "dep:macro_authorization","dep:model-error-response","dep:utoipa","entity_access/inbound",@@ -24,6 +25,7 @@ chrono = { workspace = true }entity_access = { path = "../entity_access", optional = true, default-features = false, features = ["ports"] }filter_ast = { path = "../filter_ast", optional = true }item_filters = { path = "../item_filters", optional = true }+macro_authorization = { path = "../macro_authorization", optional = true, default-features = false, features = ["axum"] }macro_uuid = { path = "../macro_uuid" }model-error-response = { path = "../model-error-response", optional = true }models_pagination = { path = "../models_pagination", optional = true }@@ -41,5 +43,7 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }http-body-util = { workspace = true }macro_db_migrator = { path = "../macro_db_migrator" }macro_user_id = { path = "../macro_user_id" }+model_user = { path = "../model_user" }+rootcause = { workspace = true }tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }tower = { workspace = true }diff --git a/crates/foreign_entity/src/inbound/axum_router.rs b/crates/foreign_entity/src/inbound/axum_router.rsindex 3206e17b4c..6ae713d4c6 100644--- a/crates/foreign_entity/src/inbound/axum_router.rs+++ b/crates/foreign_entity/src/inbound/axum_router.rs@@ -16,6 +16,7 @@ use entity_access::{domain::{models::ViewAccessLevel, ports::EntityAccessService},inbound::axum_extractors::ForeignEntityAccessLevelExtractor,};+use macro_authorization::{MacroAuthorizationService, MacroAuthorizationState};use model_error_response::ErrorResponse;use crate::domain::{@@ -24,54 +25,73 @@ use crate::domain::{};/// Router state for authenticated foreign entity operations.-pub struct ForeignEntityRouterState<S, AccessSvc> {+pub struct ForeignEntityRouterState<S, AccessSvc, Auth> {service: Arc<S>,access_service: Arc<AccessSvc>,+ authorization_state: MacroAuthorizationState<Auth>,}-impl<S, AccessSvc> Clone for ForeignEntityRouterState<S, AccessSvc> {+impl<S, AccessSvc, Auth> Clone for ForeignEntityRouterState<S, AccessSvc, Auth> {fn clone(&self) -> Self {Self {service: self.service.clone(),access_service: self.access_service.clone(),+ authorization_state: self.authorization_state.clone(),}}}-impl<S, AccessSvc> ForeignEntityRouterState<S, AccessSvc>+impl<S, AccessSvc, Auth> ForeignEntityRouterState<S, AccessSvc, Auth>whereS: ForeignEntityService,AccessSvc: EntityAccessService,{- /// Create router state from shared service references.- pub fn new(service: Arc<S>, access_service: Arc<AccessSvc>) -> Self {+ /// Create router state from shared service references and authorization state.+ pub fn new(+ service: Arc<S>,+ access_service: Arc<AccessSvc>,+ authorization_state: MacroAuthorizationState<Auth>,+ ) -> Self {Self {service,access_service,+ authorization_state,}}}-impl<S, AccessSvc> FromRef<ForeignEntityRouterState<S, AccessSvc>> for Arc<AccessSvc> {- fn from_ref(state: &ForeignEntityRouterState<S, AccessSvc>) -> Self {+impl<S, AccessSvc, Auth> FromRef<ForeignEntityRouterState<S, AccessSvc, Auth>> for Arc<AccessSvc> {+ fn from_ref(state: &ForeignEntityRouterState<S, AccessSvc, Auth>) -> Self {state.access_service.clone()}}+impl<S, AccessSvc, Auth> FromRef<ForeignEntityRouterState<S, AccessSvc, Auth>>+ for MacroAuthorizationState<Auth>+{+ fn from_ref(state: &ForeignEntityRouterState<S, AccessSvc, Auth>) -> Self {+ state.authorization_state.clone()+ }+}+/// Build the authenticated foreign entity router.////// Routes:/// - `GET /{id}` — get a visible foreign entity by its internal ID.-pub fn foreign_entity_router<S, AccessSvc, T>(- state: ForeignEntityRouterState<S, AccessSvc>,+pub fn foreign_entity_router<S, AccessSvc, Auth, T>(+ state: ForeignEntityRouterState<S, AccessSvc, Auth>,) -> Router<T>whereS: ForeignEntityService,AccessSvc: EntityAccessService,+ Auth: MacroAuthorizationService,T: Send + Sync + 'static,{Router::new()- .route("/{id}", get(get_foreign_entity_handler::<S, AccessSvc>))+ .route(+ "/{id}",+ get(get_foreign_entity_handler::<S, AccessSvc, Auth>),+ ).with_state(state)}@@ -93,13 +113,14 @@ where))]#[tracing::instrument(err, skip_all)]-pub async fn get_foreign_entity_handler<S, AccessSvc>(- State(state): State<ForeignEntityRouterState<S, AccessSvc>>,- access: ForeignEntityAccessLevelExtractor<ViewAccessLevel, AccessSvc>,+pub async fn get_foreign_entity_handler<S, AccessSvc, Auth>(+ State(state): State<ForeignEntityRouterState<S, AccessSvc, Auth>>,+ access: ForeignEntityAccessLevelExtractor<ViewAccessLevel, AccessSvc, Auth>,) -> Result<Json<ForeignEntity>, ForeignEntityError>whereS: ForeignEntityService,AccessSvc: EntityAccessService,+ Auth: MacroAuthorizationService,{let foreign_entity = state.servicediff --git a/crates/foreign_entity/src/inbound/axum_router/tests.rs b/crates/foreign_entity/src/inbound/axum_router/tests.rsindex f7f124ba66..60fb5fa6a1 100644--- a/crates/foreign_entity/src/inbound/axum_router/tests.rs+++ b/crates/foreign_entity/src/inbound/axum_router/tests.rs@@ -7,21 +7,24 @@ use axum::{response::Response,};use chrono::{DateTime, Utc};-use entity_access::{- domain::{- models::{- AccessError, AccessLevel, BotId, CallChannelInfo, EntityAccessReceipt,- EntityPermission, EntityType, RequiredPermission, UserTeamInfo, ViewAccessLevel,- },- ports::EntityAccessService,+use entity_access::domain::{+ models::{+ AccessError, AccessLevel, BotId, CallChannelInfo, EntityAccessReceipt, EntityPermission,+ EntityType, RequiredPermission, UserTeamInfo, ViewAccessLevel,},- inbound::axum_extractors::InternalUser,+ ports::EntityAccessService,};use http_body_util::BodyExt;+use macro_authorization::{+ INTERNAL_API_KEY_HEADER, InternalIdentityClaims, MacroAuthorizationError,+ MacroAuthorizationService, MacroAuthorizationState,+};use macro_user_id::{lowercased::Lowercase,user_id::{MacroUserId, MacroUserIdStr},};+use model_user::UserContext;+use rootcause::Report;use serde_json::{Value, json};use tower::ServiceExt;use uuid::Uuid;@@ -150,7 +153,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_id: &str,_entity_type: EntityType,) -> Result<EntityAccessReceipt<T>, AccessError> {- unreachable!("InternalUser extension should bypass real access receipt generation")+ unreachable!("identity-less internal access should bypass real access receipt generation")}async fn generate_bot_entity_access_receipt<T: RequiredPermission>(@@ -159,7 +162,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_id: &str,_entity_type: EntityType,) -> Result<EntityAccessReceipt<T>, AccessError> {- unreachable!("InternalUser extension should bypass bot access receipt generation")+ unreachable!("identity-less internal access should bypass bot access receipt generation")}async fn get_access_level(@@ -168,7 +171,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_id: &str,_entity_type: EntityType,) -> Result<Option<AccessLevel>, AccessError> {- unreachable!("InternalUser extension should bypass real access checks")+ unreachable!("identity-less internal access should bypass real access checks")}async fn check_access(@@ -178,7 +181,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_type: EntityType,_required_level: AccessLevel,) -> Result<AccessLevel, AccessError> {- unreachable!("InternalUser extension should bypass real access checks")+ unreachable!("identity-less internal access should bypass real access checks")}async fn check_public_access(@@ -187,7 +190,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_type: EntityType,_required_level: AccessLevel,) -> Result<AccessLevel, AccessError> {- unreachable!("InternalUser extension should bypass real access checks")+ unreachable!("identity-less internal access should bypass real access checks")}async fn get_entity_permission(@@ -197,7 +200,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_type: EntityType,_user_org_id: Option<i64>,) -> Result<EntityPermission, AccessError> {- unreachable!("InternalUser extension should bypass real access checks")+ unreachable!("identity-less internal access should bypass real access checks")}async fn get_crm_entity_permission_with_team(@@ -206,7 +209,7 @@ impl EntityAccessService for NoopEntityAccessService {_entity_id: &str,_entity_type: EntityType,) -> Result<(EntityPermission, uuid::Uuid), AccessError> {- unreachable!("InternalUser extension should bypass real access checks")+ unreachable!("identity-less internal access should bypass real access checks")}async fn get_users_by_entity(@@ -239,25 +242,49 @@ impl EntityAccessService for NoopEntityAccessService {}}+const VALID_INTERNAL_KEY: &str = "valid-internal-key";++#[derive(Clone, Debug, Default)]+struct FakeAuthorizationService;++impl MacroAuthorizationService for FakeAuthorizationService {+ async fn authorize(&self, _jwt: &str) -> Result<UserContext, Report<MacroAuthorizationError>> {+ unreachable!("internal requests should not authorize user credentials")+ }++ async fn authorize_internal(+ &self,+ provided_key: &str,+ claims: InternalIdentityClaims,+ ) -> Result<Option<UserContext>, Report<MacroAuthorizationError>> {+ if provided_key != VALID_INTERNAL_KEY {+ return Err(Report::new(MacroAuthorizationError::InvalidCredentials));+ }++ Ok(claims.user_id.map(|user_id| UserContext {+ user_id,+ fusion_user_id: "fusion-user-id".to_string(),+ organization_id: None,+ permissions: None,+ }))+ }+}+fn test_router(service: Arc<StubForeignEntityService>) -> Router {foreign_entity_router(ForeignEntityRouterState::new(service,Arc::new(NoopEntityAccessService),+ MacroAuthorizationState::new(Arc::new(FakeAuthorizationService)),))}fn internal_get(uri: impl Into<String>) -> Request<Body> {- let mut request = Request::builder()+ Request::builder().method(Method::GET).uri(uri.into())+ .header(INTERNAL_API_KEY_HEADER, VALID_INTERNAL_KEY).body(Body::empty())- .expect("test request should be built");-- request.extensions_mut().insert(InternalUser {- access_level: AccessLevel::Owner,- });-- request+ .expect("test request should be built")}async fn response_json(response: Response) -> Value {diff --git a/services/document_storage_service/src/api/context.rs b/services/document_storage_service/src/api/context.rsindex 7d140aad9c..7cada04f73 100644--- a/services/document_storage_service/src/api/context.rs+++ b/services/document_storage_service/src/api/context.rs@@ -367,7 +367,7 @@ pub(crate) type ForeignEntityServiceType = ForeignEntityServiceImpl<PgForeignEnt/// Type alias for the foreign entity router state.pub(crate) type DssForeignEntityState =- ForeignEntityRouterState<ForeignEntityServiceType, EntityAccessService>;+ ForeignEntityRouterState<ForeignEntityServiceType, EntityAccessService, AuthorizationService>;/// Type alias for the github sync service.pub(crate) type GithubSyncServiceType = GithubSyncServiceImpl<diff --git a/services/document_storage_service/src/api/documents/save_document/save_document_handler.rs b/services/document_storage_service/src/api/documents/save_document/save_document_handler.rsindex b030028f83..44dc448233 100644--- a/services/document_storage_service/src/api/documents/save_document/save_document_handler.rs+++ b/services/document_storage_service/src/api/documents/save_document/save_document_handler.rs@@ -15,7 +15,7 @@ use axum::{response::IntoResponse,};use entity_access::inbound::axum_extractors::DocumentAccessExtractor;-use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractor;+use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractorV2;use macro_authorization::MacroAuthorizationExtractor;use model::document::response::DocumentResponseMetadata;use model::{@@ -55,10 +55,11 @@ pub async fn save_document_handler(user: MacroAuthorizationExtractor<AuthorizationService>,document_context: Extension<DocumentBasic>,Path(Params { document_id }): Path<Params>,- project: ProjectBodyAccessLevelExtractor<+ project: ProjectBodyAccessLevelExtractorV2<EditAccessLevel,SaveDocumentRequest,EntityAccessService,+ AuthorizationService,>,) -> impl IntoResponse {let req = project.into_inner();diff --git a/services/document_storage_service/src/api/middleware/internal_access.rs b/services/document_storage_service/src/api/middleware/internal_access.rsindex 05414a1e92..2587d93297 100644--- a/services/document_storage_service/src/api/middleware/internal_access.rs+++ b/services/document_storage_service/src/api/middleware/internal_access.rs@@ -8,9 +8,7 @@ use axum::{middleware::Next,response::{IntoResponse, Response},};-pub(crate) use entity_access::inbound::axum_extractors::InternalUser;use model::user::UserContext;-use models_permissions::share_permission::access_level::AccessLevel;use reqwest::header::ToStrError;use thiserror::Error;use tracing::Level;@@ -83,15 +81,11 @@ pub(in crate::api) async fn handler(// Attach user_id to the UserContextreq.extensions_mut().insert(UserContext {- user_id: user_id.clone(),+ user_id,fusion_user_id: "".to_string(), // not needed in this use casepermissions: None,organization_id: None,});- req.extensions_mut().insert(InternalUser {- access_level: AccessLevel::Owner,- });-Ok(next.run(req).await)}diff --git a/services/document_storage_service/src/api/threads/edit_thread.rs b/services/document_storage_service/src/api/threads/edit_thread.rsindex bc1ab6cfbd..3ec00af633 100644--- a/services/document_storage_service/src/api/threads/edit_thread.rs+++ b/services/document_storage_service/src/api/threads/edit_thread.rs@@ -5,7 +5,7 @@ use axum::http::StatusCode;use axum::response::{IntoResponse, Response};use axum::{Extension, Json, extract};use entity_access::domain::models::EntityPermission;-use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractor;+use entity_access::inbound::axum_extractors::ProjectBodyAccessLevelExtractorV2;use entity_access::inbound::axum_extractors::ThreadAccessLevelExtractor;use macro_authorization::MacroAuthorizationExtractor;use macro_db_client::share_permission::edit::edit_thread_permission;@@ -59,10 +59,11 @@ pub async fn edit_thread_handler(user: MacroAuthorizationExtractor<AuthorizationService>,thread_context: Extension<EmailThreadPermission>,extract::Path(ThreadParams { thread_id }): extract::Path<ThreadParams>,- project: ProjectBodyAccessLevelExtractor<+ project: ProjectBodyAccessLevelExtractorV2<EditAccessLevel,PatchThreadRequestV2,EntityAccessService,+ AuthorizationService,>,) -> Result<Response, Response> {let req = project.into_inner();diff --git a/services/document_storage_service/src/main.rs b/services/document_storage_service/src/main.rsindex fd649fce36..e3df7d4bd9 100644--- a/services/document_storage_service/src/main.rs+++ b/services/document_storage_service/src/main.rs@@ -489,6 +489,7 @@ async fn main() -> anyhow::Result<()> {let foreign_entity_state = ForeignEntityRouterState::new(foreign_entity_service.clone(),entity_access_service.clone(),+ authorization_state.clone(),);// Cal.com webhooks → Meta Lead events. Both secrets are loaded here