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.

chore(macro_user): remove extractors (#5027)

Will Hutchinson39ba0f5f3963
diff --git a/Cargo.lock b/Cargo.lock
index 5225417abe..2995496edc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9062,10 +9062,8 @@ dependencies = [
name = "model_user"
version = "0.1.0"
dependencies = [
- "axum",
"macro_user_id",
"serde",
- "thiserror 2.0.18",
"utoipa",
"uuid",
"workspace-hack",
diff --git a/crates/complete_graph/Cargo.toml b/crates/complete_graph/Cargo.toml
index 1fb4fda62f..ffe1ee266b 100644
--- a/crates/complete_graph/Cargo.toml
+++ b/crates/complete_graph/Cargo.toml
@@ -33,7 +33,7 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }
[dev-dependencies]
apollo-compiler = { workspace = true }
macro_user_id = { path = "../macro_user_id" }
-model_user = { path = "../model_user", features = ["axum"] }
+model_user = { path = "../model_user" }
models_pagination = { path = "../models_pagination" }
models_properties = { path = "../models_properties" }
models_soup = { path = "../models_soup" }
diff --git a/crates/documents/Cargo.toml b/crates/documents/Cargo.toml
index 11a3702269..ae52bac348 100644
--- a/crates/documents/Cargo.toml
+++ b/crates/documents/Cargo.toml
@@ -121,7 +121,7 @@ axum = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true }
jsonwebtoken = { workspace = true, optional = true }
model-error-response = { path = "../model-error-response", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
+model_user = { path = "../model_user", optional = true }
utoipa = { workspace = true, optional = true }
# Outbound dependencies
diff --git a/crates/macro_middleware/Cargo.toml b/crates/macro_middleware/Cargo.toml
index 2d2ff3d693..c743886542 100644
--- a/crates/macro_middleware/Cargo.toml
+++ b/crates/macro_middleware/Cargo.toml
@@ -35,7 +35,7 @@ macro_user_id = { path = "../macro_user_id", optional = true }
macro_uuid = { path = "../macro_uuid" }
model = { path = "../model" }
model-entity = { path = "../model-entity" }
-model_user = { path = "../model_user", features = ["axum"], optional = true }
+model_user = { path = "../model_user", optional = true }
models_permissions = { path = "../models_permissions" }
remote_env_var = { path = "../remote_env_var" }
serde = { workspace = true }
diff --git a/crates/model/Cargo.toml b/crates/model/Cargo.toml
index 1fceb7b8df..4fd96f7ff5 100644
--- a/crates/model/Cargo.toml
+++ b/crates/model/Cargo.toml
@@ -13,9 +13,10 @@ chrono = { workspace = true }
document_sub_type = { path = "../document_sub_type" }
doppleganger = { workspace = true, features = ["chrono", "uuid"] }
macro_user_id = { path = "../macro_user_id", features = ["schema"] }
+model-entity = { path = "../model-entity" }
model-error-response = { path = "../model-error-response" }
model_file_type = { path = "../model_file_type", features = ["utoipa"] }
-model_user = { path = "../model_user", features = ["axum"] }
+model_user = { path = "../model_user" }
models_bulk_upload = { path = "../models_bulk_upload" }
models_pagination = { path = "../models_pagination" }
models_permissions = { path = "../models_permissions" }
@@ -29,5 +30,4 @@ thiserror.workspace = true
tracing = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras", "chrono"] }
uuid = { workspace = true }
-model-entity = { path = "../model-entity"}
workspace-hack = { version = "0.1", path = "../workspace-hack" }
diff --git a/crates/model/src/user/mod.rs b/crates/model/src/user/mod.rs
index d488ed213a..894218e08d 100644
--- a/crates/model/src/user/mod.rs
+++ b/crates/model/src/user/mod.rs
@@ -1,5 +1,4 @@
pub use model_user::{
ProfilePictureQueryParams, ProfilePictures, PutUserNameQueryParams, UserContext, UserInfo,
UserInfoWithMacroUserId, UserName, UserNames, UserPermission, UserProfilePicture,
- axum_extractor,
};
diff --git a/crates/model_user/Cargo.toml b/crates/model_user/Cargo.toml
index 912e25dde7..6eb35c5478 100644
--- a/crates/model_user/Cargo.toml
+++ b/crates/model_user/Cargo.toml
@@ -4,14 +4,9 @@ name = "model_user"
publish = false
version = "0.1.0"
-[features]
-axum = ["dep:axum", "dep:thiserror"]
-
[dependencies]
-axum = { workspace = true, optional = true }
macro_user_id = { path = "../macro_user_id" }
serde = { workspace = true }
-thiserror = { workspace = true, optional = true }
utoipa = { workspace = true }
uuid = { workspace = true }
workspace-hack = { version = "0.1", path = "../workspace-hack" }
diff --git a/crates/model_user/src/axum_extractor.rs b/crates/model_user/src/axum_extractor.rs
deleted file mode 100644
index 5584935cb9..0000000000
--- a/crates/model_user/src/axum_extractor.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use axum::{
- Extension, RequestPartsExt,
- extract::{FromRequestParts, rejection::ExtensionRejection},
- http::{StatusCode, request::Parts},
- response::IntoResponse,
-};
-use macro_user_id::{cowlike::CowLike, error::ParseErr, user_id::MacroUserIdStr};
-use thiserror::Error;
-
-use crate::UserContext;
-
-#[derive(Debug, Error)]
-pub enum UserExtractorErr {
- #[error("Internal server error")]
- AxumExtensionErr(#[from] ExtensionRejection),
- #[error("The user context was empty")]
- UserContextEmpty,
- #[error("Invalid macro user id: {0}")]
- InvalidId(#[from] ParseErr),
-}
-
-impl IntoResponse for UserExtractorErr {
- fn into_response(self) -> axum::response::Response {
- let msg = self.to_string();
- (StatusCode::UNAUTHORIZED, msg).into_response()
- }
-}
-
-/// Extractor that requires an authenticated user.
-/// Fails with `UserContextEmpty` if the user_id is empty.
-#[non_exhaustive]
-#[derive(Clone)]
-pub struct MacroUserExtractor {
- pub macro_user_id: MacroUserIdStr<'static>,
- pub user_context: UserContext,
-}
-
-impl<S> FromRequestParts<S> for MacroUserExtractor
-where
- S: Send + Sync,
-{
- type Rejection = UserExtractorErr;
-
- /// Perform the extraction.
- async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
- let ext: Extension<UserContext> = parts.extract_with_state(state).await?;
- if ext.0.user_id.is_empty() {
- return Err(UserExtractorErr::UserContextEmpty);
- }
-
- let macro_user_id =
- MacroUserIdStr::parse_from_str(&ext.0.user_id).map(CowLike::into_owned)?;
-
- Ok(MacroUserExtractor {
- macro_user_id,
- user_context: ext.0,
- })
- }
-}
-
-/// Extractor that succeeds even for unauthenticated users.
-/// Returns `None` for `macro_user_id` if the user_id is empty.
-#[non_exhaustive]
-#[derive(Clone)]
-pub struct OptionalMacroUserExtractor {
- pub macro_user_id: Option<MacroUserIdStr<'static>>,
- pub user_context: UserContext,
-}
-
-impl<S> FromRequestParts<S> for OptionalMacroUserExtractor
-where
- S: Send + Sync,
-{
- type Rejection = UserExtractorErr;
-
- async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
- let ext: Extension<UserContext> = parts.extract_with_state(state).await?;
-
- if ext.0.user_id.is_empty() {
- return Ok(OptionalMacroUserExtractor {
- macro_user_id: None,
- user_context: ext.0,
- });
- }
-
- let macro_user_id =
- MacroUserIdStr::parse_from_str(&ext.0.user_id).map(CowLike::into_owned)?;
-
- Ok(OptionalMacroUserExtractor {
- macro_user_id: Some(macro_user_id),
- user_context: ext.0,
- })
- }
-}
diff --git a/crates/model_user/src/lib.rs b/crates/model_user/src/lib.rs
index 3c34c1da7d..e8cdaefdb7 100644
--- a/crates/model_user/src/lib.rs
+++ b/crates/model_user/src/lib.rs
@@ -1,9 +1,6 @@
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
-#[cfg(feature = "axum")]
-pub mod axum_extractor;
-
#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug)]
pub struct UserPermission {
/// The role the permission is for
diff --git a/crates/notification/Cargo.toml b/crates/notification/Cargo.toml
index eb52dc90db..f443969947 100644
--- a/crates/notification/Cargo.toml
+++ b/crates/notification/Cargo.toml
@@ -36,14 +36,16 @@ hex = { workspace = true }
hmac = { workspace = true }
itertools = { workspace = true }
last_online_tracker = { path = "../last_online_tracker" }
-macro_authorization = { path = "../macro_authorization", default-features = false, features = ["axum"], optional = true }
+macro_authorization = { path = "../macro_authorization", default-features = false, features = [
+ "axum",
+], optional = true }
macro_env = { path = "../macro_env" }
macro_service_urls = { path = "../macro_service_urls" }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid" }
model-entity = { path = "../model-entity" }
model-error-response = { path = "../model-error-response", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
+model_user = { path = "../model_user", optional = true }
models_pagination = { path = "../models_pagination" }
rate_limit = { path = "../rate_limit" }
redis = { workspace = true, features = [
diff --git a/crates/referral/Cargo.toml b/crates/referral/Cargo.toml
index f5d5c2f638..d43300d1a7 100644
--- a/crates/referral/Cargo.toml
+++ b/crates/referral/Cargo.toml
@@ -32,6 +32,7 @@ tracing = { workspace = true }
uuid = { workspace = true }
# Domain models
+invite_email = { path = "../invite_email" }
macro_authorization = { path = "../macro_authorization", optional = true, default-features = false, features = [
"axum",
] }
@@ -40,14 +41,13 @@ macro_uuid = { path = "../macro_uuid" }
model-entity = { path = "../model-entity" }
notification = { path = "../notification" }
rate_limit = { path = "../rate_limit", features = ["axum"] }
-invite_email = { path = "../invite_email" }
# Axum dependencies (for inbound)
axum = { workspace = true, optional = true }
axum-extra = { workspace = true, optional = true }
ip_extractor = { path = "../ip_extractor", optional = true }
model-error-response = { path = "../model-error-response", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
+model_user = { path = "../model_user", optional = true }
tower = { workspace = true, optional = true }
utoipa = { workspace = true, optional = true }
diff --git a/crates/teams/Cargo.toml b/crates/teams/Cargo.toml
index d9515988b8..f87055a286 100644
--- a/crates/teams/Cargo.toml
+++ b/crates/teams/Cargo.toml
@@ -27,9 +27,9 @@ inbound = ["axum", "ports"]
outbound = [
"dep:analytics_client",
"dep:contacts",
+ "dep:models_email",
"dep:sqlx",
"dep:sqs_client",
- "dep:models_email",
"dep:url",
"ports",
]
@@ -75,7 +75,7 @@ tokio = { workspace = true, optional = true }
# Axum dependencies (for inbound)
axum = { workspace = true, optional = true }
model-error-response = { path = "../model-error-response", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
+model_user = { path = "../model_user", optional = true }
utoipa = { workspace = true, optional = true }
# Notification dependencies (for ports)
@@ -85,12 +85,12 @@ notification = { path = "../notification", optional = true, default-features = f
# Outbound dependencies
analytics_client = { path = "../analytics_client", optional = true }
+models_email = { path = "../models_email", optional = true }
sqlx = { workspace = true, optional = true }
-url = { workspace = true, optional = true }
sqs_client = { path = "../sqs_client", default-features = false, features = [
"email",
], optional = true }
-models_email = { path = "../models_email", optional = true }
+url = { workspace = true, optional = true }
workspace-hack = { version = "0.1", path = "../workspace-hack" }
[dev-dependencies]
diff --git a/crates/webhook/Cargo.toml b/crates/webhook/Cargo.toml
index 3f50d3b740..74c9eb2922 100644
--- a/crates/webhook/Cargo.toml
+++ b/crates/webhook/Cargo.toml
@@ -20,10 +20,10 @@ inbound = [
"dep:model-error-response",
"dep:model_user",
"dep:rate_limit",
- "rate_limit/axum",
"dep:serde_json",
"dep:utoipa",
"ports",
+ "rate_limit/axum",
]
ingestion = [
"dep:channels",
@@ -36,9 +36,9 @@ ingestion = [
outbound = [
"dep:hex",
"dep:hmac",
+ "dep:macro_uuid",
"dep:reqwest",
"dep:sha2",
- "dep:macro_uuid",
"dep:sqlx",
"dep:sqs_client",
"dep:tokio",
@@ -70,7 +70,7 @@ macro_event_topics = { path = "../macro_event_topics" }
macro_user_id = { path = "../macro_user_id" }
macro_uuid = { path = "../macro_uuid", optional = true }
model-error-response = { path = "../model-error-response", optional = true }
-model_user = { path = "../model_user", optional = true, features = ["axum"] }
+model_user = { path = "../model_user", optional = true }
rate_limit = { path = "../rate_limit", optional = true, default-features = false }
rdkafka = { workspace = true, optional = true }
reqwest = { workspace = true, optional = true }
@@ -90,10 +90,10 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }
[dev-dependencies]
channel_sender = { path = "../channel_sender" }
-tokio = { workspace = true, features = ["test-util"] }
macro_db_migrator = { path = "../macro_db_migrator" }
rate_limit = { path = "../rate_limit", default-features = false, features = [
"axum",
"testing",
] }
+tokio = { workspace = true, features = ["test-util"] }
tower = { workspace = true }
diff --git a/services/notification_service/Cargo.toml b/services/notification_service/Cargo.toml
index 36abf762f9..2220806262 100644
--- a/services/notification_service/Cargo.toml
+++ b/services/notification_service/Cargo.toml
@@ -40,10 +40,10 @@ macro_cors = { path = "../../crates/macro_cors" }
macro_entrypoint = { path = "../../crates/macro_entrypoint" }
macro_env = { path = "../../crates/macro_env" }
macro_env_var = { path = "../../crates/macro_env_var" }
-macro_queues = { path = "../../crates/macro_queues" }
macro_middleware = { path = "../../crates/macro_middleware", default-features = false, features = [
"auth",
] }
+macro_queues = { path = "../../crates/macro_queues" }
macro_tower_layers = { path = "../../crates/macro_tower_layers" }
macro_user_id = { path = "../../crates/macro_user_id" }
macro_uuid = { path = "../../crates/macro_uuid" }
@@ -53,8 +53,10 @@ model-entity = { path = "../../crates/model-entity" }
model-error-response = { path = "../../crates/model-error-response" }
model_file_type = { path = "../../crates/model_file_type" }
model_notifications = { path = "../../crates/model_notifications" }
-model_user = { path = "../../crates/model_user", features = ["axum"] }
-models_pagination = { path = "../../crates/models_pagination", features = ["axum"] }
+model_user = { path = "../../crates/model_user" }
+models_pagination = { path = "../../crates/models_pagination", features = [
+ "axum",
+] }
notification = { path = "../../crates/notification", features = ["axum"] }
notification_db_client = { path = "../../crates/notification_db_client" }
paste = { workspace = true }