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.

fix(soup): file assoc cursor (#780)

Sean Aye562aa9e25e1e
diff --git a/rust/cloud-storage/filter_ast/src/lib.rs b/rust/cloud-storage/filter_ast/src/lib.rs
index acf03a7a31..f899b4e6ef 100644
--- a/rust/cloud-storage/filter_ast/src/lib.rs
+++ b/rust/cloud-storage/filter_ast/src/lib.rs
@@ -66,9 +66,13 @@ pub enum ExprFrame<A, B> {
#[derive(Debug, Serialize, Deserialize)]
pub enum Expr<B> {
+ #[serde(rename = "&")]
And(Box<Self>, Box<Self>),
+ #[serde(rename = "|")]
Or(Box<Self>, Box<Self>),
+ #[serde(rename = "!")]
Not(Box<Self>),
+ #[serde(rename = "l")]
Literal(B),
}
diff --git a/rust/cloud-storage/item_filters/src/ast.rs b/rust/cloud-storage/item_filters/src/ast.rs
index f520e89288..73896ac7fa 100644
--- a/rust/cloud-storage/item_filters/src/ast.rs
+++ b/rust/cloud-storage/item_filters/src/ast.rs
@@ -64,16 +64,16 @@ pub type LiteralTree<T> = Option<Arc<Expr<T>>>;
#[non_exhaustive]
pub struct EntityFilterAst {
/// the filters that should be applied to the document entity
- #[serde(default)]
+ #[serde(default, rename = "df")]
pub document_filter: LiteralTree<DocumentLiteral>,
/// the filters that should be applied to the project entity
- #[serde(default)]
+ #[serde(default, rename = "pf")]
pub project_filter: LiteralTree<ProjectLiteral>,
/// the filters that should be applied to the chat entity
- #[serde(default)]
+ #[serde(default, rename = "cf")]
pub chat_filter: LiteralTree<ChatLiteral>,
/// the filters that should be applied to the email entity
- #[serde(default)]
+ #[serde(default, rename = "ef")]
pub email_filter: LiteralTree<EmailLiteral>,
}
diff --git a/rust/cloud-storage/item_filters/src/ast/document.rs b/rust/cloud-storage/item_filters/src/ast/document.rs
index 7f97e4b489..4d8832f30c 100644
--- a/rust/cloud-storage/item_filters/src/ast/document.rs
+++ b/rust/cloud-storage/item_filters/src/ast/document.rs
@@ -18,12 +18,16 @@ use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum DocumentLiteral {
/// this node value filters by [FileType]
+ #[serde(rename = "ft")]
FileType(FileType),
/// this node value filters by document [Uuid]
+ #[serde(rename = "id")]
Id(Uuid),
/// this node value filters by project [Uuid]
+ #[serde(rename = "pid")]
ProjectId(Uuid),
/// this node value filters by document owner
+ #[serde(rename = "o")]
Owner(MacroUserIdStr<'static>),
}
diff --git a/rust/cloud-storage/item_filters/src/ast/tests.rs b/rust/cloud-storage/item_filters/src/ast/tests.rs
index 242b2b778d..949aeccb4b 100644
--- a/rust/cloud-storage/item_filters/src/ast/tests.rs
+++ b/rust/cloud-storage/item_filters/src/ast/tests.rs
@@ -44,42 +44,42 @@ fn it_expands_filters() {
let json = serde_json::to_value(ast).unwrap();
let exp = json!({
- "And": [
+ "&": [
{
- "And": [
+ "&": [
{
- "And": [
+ "&": [
{
- "Or": [
+ "|": [
{
- "Literal": {
- "FileType": "pdf",
+ "l": {
+ "ft": "pdf",
}
},
{
- "Literal": {
- "FileType": "txt"
+ "l": {
+ "ft": "txt"
}
}
]
},
{
- "Literal": {
- "Id": document_id
+ "l": {
+ "id": document_id
}
}
]
},
{
- "Literal": {
- "ProjectId": project_id
+ "l": {
+ "pid": project_id
}
}
]
},
{
- "Literal": {
- "Owner": "macro|[email protected]"
+ "l": {
+ "o": "macro|[email protected]"
}
}
]
@@ -113,42 +113,42 @@ fn it_expands_file_associations() {
println!("{}", serde_json::to_string_pretty(&json).unwrap());
let exp = serde_json::json!({
- "Or": [
+ "|": [
{
- "Or": [
+ "|": [
{
- "Or": [
+ "|": [
{
- "Or": [
+ "|": [
{
- "Literal": {
- "FileType": "ai"
+ "l": {
+ "ft": "ai"
}
},
{
- "Literal": {
- "FileType": "eps"
+ "l": {
+ "ft": "eps"
}
}
]
},
{
- "Literal": {
- "FileType": "ps"
+ "l": {
+ "ft": "ps"
}
}
]
},
{
- "Literal": {
- "FileType": "dxf"
+ "l": {
+ "ft": "dxf"
}
}
]
},
{
- "Literal": {
- "FileType": "dwg"
+ "l": {
+ "ft": "dwg"
}
}
]
diff --git a/rust/cloud-storage/item_filters/src/ast/tests/other.json b/rust/cloud-storage/item_filters/src/ast/tests/other.json
index 662e220ae3..cf3dc54fcd 100644
--- a/rust/cloud-storage/item_filters/src/ast/tests/other.json
+++ b/rust/cloud-storage/item_filters/src/ast/tests/other.json
@@ -1 +1 @@
-{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Or":[{"Literal":{"FileType":"jpeg"}},{"Literal":{"FileType":"jpg"}}]},{"Literal":{"FileType":"png"}}]},{"Literal":{"FileType":"gif"}}]},{"Literal":{"FileType":"svg"}}]},{"Literal":{"FileType":"webp"}}]},{"Literal":{"FileType":"avif"}}]},{"Literal":{"FileType":"bmp"}}]},{"Literal":{"FileType":"ico"}}]},{"Literal":{"FileType":"tiff"}}]},{"Literal":{"FileType":"tif"}}]},{"Literal":{"FileType":"heic"}}]},{"Literal":{"FileType":"heif"}}]},{"Literal":{"FileType":"tar"}}]},{"Literal":{"FileType":"targz"}}]},{"Literal":{"FileType":"tgz"}}]},{"Literal":{"FileType":"gz"}}]},{"Literal":{"FileType":"bz2"}}]},{"Literal":{"FileType":"tarbz2"}}]},{"Literal":{"FileType":"tbz2"}}]},{"Literal":{"FileType":"z"}}]},{"Literal":{"FileType":"tarz"}}]},{"Literal":{"FileType":"lz"}}]},{"Literal":{"FileType":"tarlz"}}]},{"Literal":{"FileType":"xz"}}]},{"Literal":{"FileType":"tarxz"}}]},{"Literal":{"FileType":"txz"}}]},{"Literal":{"FileType":"lzma"}}]},{"Literal":{"FileType":"tarlzma"}}]},{"Literal":{"FileType":"rar"}}]},{"Literal":{"FileType":"sevenz"}}]},{"Literal":{"FileType":"zst"}}]},{"Literal":{"FileType":"tarzst"}}]},{"Literal":{"FileType":"tzst"}}]},{"Literal":{"FileType":"zip"}}]},{"Literal":{"FileType":"exe"}}]},{"Literal":{"FileType":"msi"}}]},{"Literal":{"FileType":"dll"}}]},{"Literal":{"FileType":"bat"}}]},{"Literal":{"FileType":"cmd"}}]},{"Literal":{"FileType":"com"}}]},{"Literal":{"FileType":"appimage"}}]},{"Literal":{"FileType":"app"}}]},{"Literal":{"FileType":"bin"}}]},{"Literal":{"FileType":"deb"}}]},{"Literal":{"FileType":"rpm"}}]},{"Literal":{"FileType":"apk"}}]},{"Literal":{"FileType":"dmg"}}]},{"Literal":{"FileType":"pkg"}}]},{"Literal":{"FileType":"crx"}}]},{"Literal":{"FileType":"xpi"}}]},{"Literal":{"FileType":"mp3"}}]},{"Literal":{"FileType":"wav"}}]},{"Literal":{"FileType":"ogg"}}]},{"Literal":{"FileType":"flac"}}]},{"Literal":{"FileType":"aac"}}]},{"Literal":{"FileType":"m4a"}}]},{"Literal":{"FileType":"wma"}}]},{"Literal":{"FileType":"mid"}}]},{"Literal":{"FileType":"midi"}}]},{"Literal":{"FileType":"mp4"}}]},{"Literal":{"FileType":"mkv"}}]},{"Literal":{"FileType":"webm"}}]},{"Literal":{"FileType":"avi"}}]},{"Literal":{"FileType":"mov"}}]},{"Literal":{"FileType":"wmv"}}]},{"Literal":{"FileType":"mpg"}}]},{"Literal":{"FileType":"mpeg"}}]},{"Literal":{"FileType":"m4v"}}]},{"Literal":{"FileType":"flv"}}]},{"Literal":{"FileType":"f4v"}}]},{"Literal":{"FileType":"threegp"}}]},{"Literal":{"FileType":"ttf"}}]},{"Literal":{"FileType":"otf"}}]},{"Literal":{"FileType":"woff"}}]},{"Literal":{"FileType":"woff2"}}]},{"Literal":{"FileType":"eot"}}]},{"Literal":{"FileType":"rtf"}}]},{"Literal":{"FileType":"odt"}}]},{"Literal":{"FileType":"ods"}}]},{"Literal":{"FileType":"odp"}}]},{"Literal":{"FileType":"odg"}}]},{"Literal":{"FileType":"odf"}}]},{"Literal":{"FileType":"epub"}}]},{"Literal":{"FileType":"mobi"}}]},{"Literal":{"FileType":"azw"}}]},{"Literal":{"FileType":"azw3"}}]},{"Literal":{"FileType":"djvu"}}]},{"Literal":{"FileType":"xls"}}]},{"Literal":{"FileType":"ppt"}}]},{"Literal":{"FileType":"pptx"}}]},{"Literal":{"FileType":"xlsx"}}]},{"Literal":{"FileType":"db"}}]},{"Literal":{"FileType":"sqlite"}}]},{"Literal":{"FileType":"sqlite3"}}]},{"Literal":{"FileType":"mdb"}}]},{"Literal":{"FileType":"accdb"}}]},{"Literal":{"FileType":"dbf"}}]},{"Literal":{"FileType":"plist"}}]},{"Literal":{"FileType":"toml"}}]},{"Literal":{"FileType":"env"}}]},{"Literal":{"FileType":"dot"}}]},{"Literal":{"FileType":"gv"}}]},{"Literal":{"FileType":"torrent"}}]},{"Literal":{"FileType":"ics"}}]},{"Literal":{"FileType":"vcf"}}]},{"Literal":{"FileType":"ai"}}]},{"Literal":{"FileType":"eps"}}]},{"Literal":{"FileType":"ps"}}]},{"Literal":{"FileType":"dxf"}}]},{"Literal":{"FileType":"dwg"}}]},{"Literal":{"FileType":"stl"}}]},{"Literal":{"FileType":"obj"}}]},{"Literal":{"FileType":"fbx"}}]},{"Literal":{"FileType":"blend"}}]},{"Literal":{"FileType":"dae"}}]},{"Literal":{"FileType":"threeds"}}]},{"Literal":{"FileType":"gltf"}}]},{"Literal":{"FileType":"glb"}}]},{"Literal":{"FileType":"vhd"}}]},{"Literal":{"FileType":"vhdx"}}]},{"Literal":{"FileType":"vmdk"}}]},{"Literal":{"FileType":"ova"}}]},{"Literal":{"FileType":"ovf"}}]},{"Literal":{"FileType":"iso"}}]},{"Literal":{"FileType":"img"}}]},{"Literal":{"FileType":"swf"}}]}
+{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"|":[{"l":{"ft":"jpeg"}},{"l":{"ft":"jpg"}}]},{"l":{"ft":"png"}}]},{"l":{"ft":"gif"}}]},{"l":{"ft":"svg"}}]},{"l":{"ft":"webp"}}]},{"l":{"ft":"avif"}}]},{"l":{"ft":"bmp"}}]},{"l":{"ft":"ico"}}]},{"l":{"ft":"tiff"}}]},{"l":{"ft":"tif"}}]},{"l":{"ft":"heic"}}]},{"l":{"ft":"heif"}}]},{"l":{"ft":"tar"}}]},{"l":{"ft":"targz"}}]},{"l":{"ft":"tgz"}}]},{"l":{"ft":"gz"}}]},{"l":{"ft":"bz2"}}]},{"l":{"ft":"tarbz2"}}]},{"l":{"ft":"tbz2"}}]},{"l":{"ft":"z"}}]},{"l":{"ft":"tarz"}}]},{"l":{"ft":"lz"}}]},{"l":{"ft":"tarlz"}}]},{"l":{"ft":"xz"}}]},{"l":{"ft":"tarxz"}}]},{"l":{"ft":"txz"}}]},{"l":{"ft":"lzma"}}]},{"l":{"ft":"tarlzma"}}]},{"l":{"ft":"rar"}}]},{"l":{"ft":"sevenz"}}]},{"l":{"ft":"zst"}}]},{"l":{"ft":"tarzst"}}]},{"l":{"ft":"tzst"}}]},{"l":{"ft":"zip"}}]},{"l":{"ft":"exe"}}]},{"l":{"ft":"msi"}}]},{"l":{"ft":"dll"}}]},{"l":{"ft":"bat"}}]},{"l":{"ft":"cmd"}}]},{"l":{"ft":"com"}}]},{"l":{"ft":"appimage"}}]},{"l":{"ft":"app"}}]},{"l":{"ft":"bin"}}]},{"l":{"ft":"deb"}}]},{"l":{"ft":"rpm"}}]},{"l":{"ft":"apk"}}]},{"l":{"ft":"dmg"}}]},{"l":{"ft":"pkg"}}]},{"l":{"ft":"crx"}}]},{"l":{"ft":"xpi"}}]},{"l":{"ft":"mp3"}}]},{"l":{"ft":"wav"}}]},{"l":{"ft":"ogg"}}]},{"l":{"ft":"flac"}}]},{"l":{"ft":"aac"}}]},{"l":{"ft":"m4a"}}]},{"l":{"ft":"wma"}}]},{"l":{"ft":"mid"}}]},{"l":{"ft":"midi"}}]},{"l":{"ft":"mp4"}}]},{"l":{"ft":"mkv"}}]},{"l":{"ft":"webm"}}]},{"l":{"ft":"avi"}}]},{"l":{"ft":"mov"}}]},{"l":{"ft":"wmv"}}]},{"l":{"ft":"mpg"}}]},{"l":{"ft":"mpeg"}}]},{"l":{"ft":"m4v"}}]},{"l":{"ft":"flv"}}]},{"l":{"ft":"f4v"}}]},{"l":{"ft":"threegp"}}]},{"l":{"ft":"ttf"}}]},{"l":{"ft":"otf"}}]},{"l":{"ft":"woff"}}]},{"l":{"ft":"woff2"}}]},{"l":{"ft":"eot"}}]},{"l":{"ft":"rtf"}}]},{"l":{"ft":"odt"}}]},{"l":{"ft":"ods"}}]},{"l":{"ft":"odp"}}]},{"l":{"ft":"odg"}}]},{"l":{"ft":"odf"}}]},{"l":{"ft":"epub"}}]},{"l":{"ft":"mobi"}}]},{"l":{"ft":"azw"}}]},{"l":{"ft":"azw3"}}]},{"l":{"ft":"djvu"}}]},{"l":{"ft":"xls"}}]},{"l":{"ft":"ppt"}}]},{"l":{"ft":"pptx"}}]},{"l":{"ft":"xlsx"}}]},{"l":{"ft":"db"}}]},{"l":{"ft":"sqlite"}}]},{"l":{"ft":"sqlite3"}}]},{"l":{"ft":"mdb"}}]},{"l":{"ft":"accdb"}}]},{"l":{"ft":"dbf"}}]},{"l":{"ft":"plist"}}]},{"l":{"ft":"toml"}}]},{"l":{"ft":"env"}}]},{"l":{"ft":"dot"}}]},{"l":{"ft":"gv"}}]},{"l":{"ft":"torrent"}}]},{"l":{"ft":"ics"}}]},{"l":{"ft":"vcf"}}]},{"l":{"ft":"ai"}}]},{"l":{"ft":"eps"}}]},{"l":{"ft":"ps"}}]},{"l":{"ft":"dxf"}}]},{"l":{"ft":"dwg"}}]},{"l":{"ft":"stl"}}]},{"l":{"ft":"obj"}}]},{"l":{"ft":"fbx"}}]},{"l":{"ft":"blend"}}]},{"l":{"ft":"dae"}}]},{"l":{"ft":"threeds"}}]},{"l":{"ft":"gltf"}}]},{"l":{"ft":"glb"}}]},{"l":{"ft":"vhd"}}]},{"l":{"ft":"vhdx"}}]},{"l":{"ft":"vmdk"}}]},{"l":{"ft":"ova"}}]},{"l":{"ft":"ovf"}}]},{"l":{"ft":"iso"}}]},{"l":{"ft":"img"}}]},{"l":{"ft":"swf"}}]}
diff --git a/rust/cloud-storage/models_pagination/Cargo.toml b/rust/cloud-storage/models_pagination/Cargo.toml
index 2a4919fa27..c8b41ac46e 100644
--- a/rust/cloud-storage/models_pagination/Cargo.toml
+++ b/rust/cloud-storage/models_pagination/Cargo.toml
@@ -5,7 +5,7 @@ publish = false
version = "0.1.0"
[features]
-axum = ["dep:axum", "dep:model-error-response"]
+axum = ["dep:axum", "dep:model-error-response", "serde_json/unbounded_depth"]
docs = [
] # adds the doc attrs, the reason this is a feature is because of JsonSchema
diff --git a/rust/cloud-storage/models_pagination/src/axum.rs b/rust/cloud-storage/models_pagination/src/axum.rs
index 585ab29ec1..66ca9353a7 100644
--- a/rust/cloud-storage/models_pagination/src/axum.rs
+++ b/rust/cloud-storage/models_pagination/src/axum.rs
@@ -38,27 +38,36 @@ impl<Id, S: Sortable, F> CursorExtractor<Id, S, F> {
/// represents an error that can occur while extracting a [CursorExtractor]
/// from the axum request parts
#[derive(Debug, Error)]
-pub enum CusorExtractErr {
+pub enum CursorExtractErr {
/// an error occurred while decoding the input value
#[error(transparent)]
DecodeErr(Base64SerdeErr<serde_json::Error>),
+ /// The query was too large to deserialize
+ #[error("Query is too large, must be < 16kb")]
+ SizeErr,
}
-impl IntoResponse for CusorExtractErr {
+impl IntoResponse for CursorExtractErr {
fn into_response(self) -> axum::response::Response {
match self {
- CusorExtractErr::DecodeErr(Base64SerdeErr::DecodeErr(_e)) => (
+ CursorExtractErr::DecodeErr(Base64SerdeErr::DecodeErr(_e)) => (
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
message: "failed to decode cursor value",
}),
),
- CusorExtractErr::DecodeErr(Base64SerdeErr::SerdeErr(_e)) => (
+ CursorExtractErr::DecodeErr(Base64SerdeErr::SerdeErr(_e)) => (
StatusCode::BAD_REQUEST,
Json(ErrorResponse {
message: "the cursor contained unexpected data",
}),
),
+ CursorExtractErr::SizeErr => (
+ StatusCode::BAD_REQUEST,
+ Json(ErrorResponse {
+ message: "Query is too large, must be <16kb",
+ }),
+ ),
}
.into_response()
}
@@ -73,7 +82,7 @@ where
Id: DeserializeOwned,
F: DeserializeOwned,
{
- type Rejection = CusorExtractErr;
+ type Rejection = CursorExtractErr;
#[tracing::instrument(err, skip(parts, state))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
@@ -85,12 +94,25 @@ where
else {
return Ok(CursorExtractor::None);
};
+
let encoded: Base64Str<CursorWithValAndFilter<Id, Sort, F>> =
Base64Str::new_from_string(cursor);
+ let bytes = encoded.len();
+ if bytes > 16_000 {
+ return Err(CursorExtractErr::SizeErr);
+ }
+
let decoded = encoded
- .decode(|bytes| serde_json::from_slice(&bytes))
- .map_err(CusorExtractErr::DecodeErr)?;
+ .decode(|bytes| {
+ let mut deserializer = serde_json::Deserializer::from_slice(&bytes);
+ deserializer.disable_recursion_limit();
+ <CursorWithValAndFilter<Id, Sort, F>>::deserialize(&mut deserializer)
+ })
+ .inspect_err(|e| {
+ dbg!(e);
+ })
+ .map_err(CursorExtractErr::DecodeErr)?;
Ok(CursorExtractor::Some(decoded))
}
diff --git a/rust/cloud-storage/models_pagination/src/cursor.rs b/rust/cloud-storage/models_pagination/src/cursor.rs
index 7880763041..16a59fba1c 100644
--- a/rust/cloud-storage/models_pagination/src/cursor.rs
+++ b/rust/cloud-storage/models_pagination/src/cursor.rs
@@ -1,7 +1,7 @@
use base64::{DecodeError, Engine, engine::general_purpose};
use either::Either;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
-use std::{cmp::Ordering, marker::PhantomData};
+use std::{cmp::Ordering, marker::PhantomData, ops::Deref};
use thiserror::Error;
/// struct which encapsulates a single page of cursor based pagination result
@@ -312,6 +312,14 @@ pub struct Base64Str<T> {
target: PhantomData<T>,
}
+impl<T> Deref for Base64Str<T> {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ &self.data
+ }
+}
+
/// Errors that can occur while working with a [Base64Str]
#[derive(Debug, Error)]
pub enum Base64SerdeErr<E> {
diff --git a/rust/cloud-storage/soup/src/inbound/axum_router.rs b/rust/cloud-storage/soup/src/inbound/axum_router.rs
index a86e8d336b..9ccc463d67 100644
--- a/rust/cloud-storage/soup/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/soup/src/inbound/axum_router.rs
@@ -316,7 +316,6 @@ where
T: SoupService,
U: EmailService,
{
- dbg!(&post_soup_request);
let link = match email_link {
Ok(l) => Some(l.0.0),
Err(EmailLinkErr::NotFound) => None,
diff --git a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
index 95437bc39e..c02421e9b1 100644
--- a/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
+++ b/rust/cloud-storage/soup/src/inbound/axum_router/tests.rs
@@ -10,6 +10,11 @@ use email::domain::{
use http_body_util::BodyExt;
use macro_user_id::{email::EmailStr, user_id::MacroUserIdStr};
use model_user::UserContext;
+use models_pagination::{
+ Cursor, CursorVal, Frecency, FrecencyValue, Identify, Paginate, PaginateOn, Query,
+ SimpleSortMethod, SortOn, Sortable, TypeEraseCursor,
+};
+use serde::Serialize;
use serde_json::json;
use std::sync::Arc;
use tower::util::ServiceExt;
@@ -17,14 +22,15 @@ use uuid::Uuid;
use crate::{
domain::{
- models::{SoupErr, SoupRequest, SoupType},
+ models::{SoupErr, SoupQuery, SoupRequest, SoupType},
ports::{SoupOutput, SoupService},
},
- inbound::axum_router::{SoupRouterState, soup_router},
+ inbound::axum_router::{SoupCursor, SoupRouterState, soup_router},
};
static CURSOR: &str = "eyJpZCI6ImUzNmM5MTJlLTU2M2MtNDIxZS1iMTAzLWE0YjAwY2ZmMzBlZSIsImxpbWl0IjoxMDAsInZhbCI6eyJzb3J0X3R5cGUiOiJ1cGRhdGVkX2F0IiwibGFzdF92YWwiOiIyMDI1LTExLTA3VDE5OjEyOjU5Ljc4MFoifX0=";
+#[derive(Clone)]
struct MockSoup {
called: Arc<std::sync::Mutex<Vec<SoupRequest>>>,
}
@@ -299,3 +305,259 @@ async fn it_loads_email_sent_view() {
}
)
}
+
+#[tokio::test]
+async fn it_parses_file_assoc_filters() {
+ let soup = MockSoup::new();
+ let inner_counter = soup.called.clone();
+ let router: Router = soup_router(SoupRouterState::new(
+ soup,
+ MockEmailLinkResult {
+ get_link_result: Arc::new(|| Ok(None)),
+ },
+ ))
+ .layer(Extension(UserContext {
+ user_id: "macro|[email protected]".to_string(),
+ fusion_user_id: "1234".to_string(),
+ permissions: None,
+ organization_id: None,
+ }));
+
+ let request = Request::builder()
+ .uri("/soup")
+ .method(Method::POST)
+ .header("content-type", "application/json")
+ .body(axum::body::Body::from(
+ serde_json::to_vec(&serde_json::json!({
+ "document_filters": {
+ "file_types": ["assoc:other"]
+ }
+ }))
+ .unwrap(),
+ ))
+ .unwrap();
+
+ let _res = router.oneshot(request).await.unwrap();
+
+ let guard = inner_counter.lock().unwrap();
+ let arg = guard.first().unwrap();
+ assert_matches!(
+ arg,
+ SoupRequest {
+ soup_type: SoupType::Expanded,
+ limit: _,
+ cursor: SoupQuery::Simple(Query::Sort(SimpleSortMethod::ViewedAt, Some(_filters))),
+ user: _,
+ email_preview_view: _,
+ link_id: _
+ }
+ )
+}
+
+#[tokio::test]
+async fn cursor_with_assoc_works() {
+ let soup = MockSoup::new();
+ let inner_counter = soup.called.clone();
+ let router: Router = soup_router(SoupRouterState::new(
+ soup.clone(),
+ MockEmailLinkResult {
+ get_link_result: Arc::new(|| Ok(None)),
+ },
+ ))
+ .layer(Extension(UserContext {
+ user_id: "macro|[email protected]".to_string(),
+ fusion_user_id: "1234".to_string(),
+ permissions: None,
+ organization_id: None,
+ }));
+
+ let request = Request::builder()
+ .uri("/soup")
+ .method(Method::POST)
+ .header("content-type", "application/json")
+ .body(axum::body::Body::from(
+ serde_json::to_vec(&serde_json::json!({
+ "document_filters": {
+ "file_types": ["assoc:other"]
+ }
+ }))
+ .unwrap(),
+ ))
+ .unwrap();
+
+ let _res = router.oneshot(request).await.unwrap();
+
+ let arg = {
+ let mut guard = inner_counter.lock().unwrap();
+ guard.pop().unwrap()
+ };
+
+ #[derive(Serialize)]
+ struct Data(usize, Uuid);
+
+ impl Identify for Data {
+ type Id = Uuid;
+
+ fn id(&self) -> Uuid {
+ self.1
+ }
+ }
+
+ impl SortOn<Frecency> for Data {
+ fn sort_on(sort: Frecency) -> impl FnMut(&Self) -> models_pagination::CursorVal<Frecency> {
+ |v| CursorVal {
+ sort_type: Frecency,
+ last_val: FrecencyValue::FrecencyScore(v.0 as f64),
+ }
+ }
+ }
+
+ // create arbitrary pagination data
+ let res = (0..1000)
+ .map(|x| Data(x, Uuid::new_v4()))
+ .paginate_on(100, Frecency)
+ .filter_on(arg.cursor.filter().cloned())
+ .into_page();
+
+ let cursor = res.type_erase().next_cursor.unwrap();
+
+ let request2 = Request::builder()
+ .uri(format!("/soup?cursor={cursor}"))
+ .method(Method::POST)
+ .header("content-type", "application/json")
+ .body(axum::body::Body::from(
+ serde_json::to_vec(&serde_json::json!({})).unwrap(),
+ ))
+ .unwrap();
+
+ let router: Router = soup_router(SoupRouterState::new(
+ soup,
+ MockEmailLinkResult {
+ get_link_result: Arc::new(|| Ok(None)),
+ },
+ ))
+ .layer(Extension(UserContext {
+ user_id: "macro|[email protected]".to_string(),
+ fusion_user_id: "1234".to_string(),
+ permissions: None,
+ organization_id: None,
+ }));
+
+ let _res = router.oneshot(request2).await.unwrap();
+ let guard2 = inner_counter.lock().unwrap();
+ let req = guard2.first().unwrap();
+ assert_matches!(
+ req,
+ SoupRequest {
+ cursor: SoupQuery::Frecency(Query::Cursor(Cursor {
+ filter: Some(_f),
+ ..
+ })),
+ ..
+ }
+ )
+}
+
+#[tokio::test]
+async fn cursor_with_code_works() {
+ let soup = MockSoup::new();
+ let inner_counter = soup.called.clone();
+ let router: Router = soup_router(SoupRouterState::new(
+ soup.clone(),
+ MockEmailLinkResult {
+ get_link_result: Arc::new(|| Ok(None)),
+ },
+ ))
+ .layer(Extension(UserContext {
+ user_id: "macro|[email protected]".to_string(),
+ fusion_user_id: "1234".to_string(),
+ permissions: None,
+ organization_id: None,
+ }));
+
+ let request = Request::builder()
+ .uri("/soup")
+ .method(Method::POST)
+ .header("content-type", "application/json")
+ .body(axum::body::Body::from(
+ serde_json::to_vec(&serde_json::json!({
+ "document_filters": {
+ "file_types": ["assoc:code"]
+ }
+ }))
+ .unwrap(),
+ ))
+ .unwrap();
+
+ let _res = router.oneshot(request).await.unwrap();
+
+ let arg = {
+ let mut guard = inner_counter.lock().unwrap();
+ guard.pop().unwrap()
+ };
+
+ #[derive(Serialize)]
+ struct Data(usize, Uuid);
+
+ impl Identify for Data {
+ type Id = Uuid;
+
+ fn id(&self) -> Uuid {
+ self.1
+ }
+ }
+
+ impl SortOn<Frecency> for Data {
+ fn sort_on(sort: Frecency) -> impl FnMut(&Self) -> models_pagination::CursorVal<Frecency> {
+ |v| CursorVal {
+ sort_type: Frecency,
+ last_val: FrecencyValue::FrecencyScore(v.0 as f64),
+ }
+ }
+ }
+
+ // create arbitrary pagination data
+ let res = (0..1000)
+ .map(|x| Data(x, Uuid::new_v4()))
+ .paginate_on(100, Frecency)
+ .filter_on(arg.cursor.filter().cloned())
+ .into_page();
+
+ let cursor = res.type_erase().next_cursor.unwrap();
+
+ let request2 = Request::builder()
+ .uri(format!("/soup?cursor={cursor}"))
+ .method(Method::POST)
+ .header("content-type", "application/json")
+ .body(axum::body::Body::from(
+ serde_json::to_vec(&serde_json::json!({})).unwrap(),
+ ))
+ .unwrap();
+
+ let router: Router = soup_router(SoupRouterState::new(
+ soup,
+ MockEmailLinkResult {
+ get_link_result: Arc::new(|| Ok(None)),
+ },
+ ))
+ .layer(Extension(UserContext {
+ user_id: "macro|[email protected]".to_string(),
+ fusion_user_id: "1234".to_string(),
+ permissions: None,
+ organization_id: None,
+ }));
+
+ let _res = router.oneshot(request2).await.unwrap();
+ let guard2 = inner_counter.lock().unwrap();
+ let req = guard2.first().unwrap();
+ assert_matches!(
+ req,
+ SoupRequest {
+ cursor: SoupQuery::Frecency(Query::Cursor(Cursor {
+ filter: Some(_f),
+ ..
+ })),
+ ..
+ }
+ )
+}