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: docx save pdf modification data (#903)
gbirman815f89c967db
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/get_full_pdf_modification_data.rs b/rust/cloud-storage/document_storage_service/src/api/documents/get_full_pdf_modification_data.rsindex 4131451811..667fdaa0a5 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/get_full_pdf_modification_data.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/get_full_pdf_modification_data.rs@@ -1,4 +1,4 @@-use std::{collections::HashMap, str::FromStr};+use std::str::FromStr;use crate::api::context::ApiContext;@@ -12,7 +12,7 @@ use macro_db_client::document::build_pdf_modification_data::{get_complete_pdf_modification_data, get_pdf_modification_data_for_document,};use model::{- document::{DocumentBasic, FileType, modification_data::PdfModificationData},+ document::{DocumentBasic, FileType},response::{GenericErrorResponse, GenericResponse},user::UserContext,};@@ -75,13 +75,9 @@ pub async fn handler(}let initial_modification_data = match file_type {- FileType::Pdf => get_pdf_modification_data_for_document(&ctx.db, &document_id).await,- FileType::Docx => Ok(PdfModificationData {- highlights: Some(HashMap::new()),- bookmarks: Vec::new(),- placeables: Vec::new(),- pinned_terms_names: Vec::new(),- }),+ FileType::Docx | FileType::Pdf => {+ get_pdf_modification_data_for_document(&ctx.db, &document_id).await+ }_ => unreachable!(),};diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/save_document/save_document_handler.rs b/rust/cloud-storage/document_storage_service/src/api/documents/save_document/save_document_handler.rsindex 67cc851b20..398cefc396 100644--- a/rust/cloud-storage/document_storage_service/src/api/documents/save_document/save_document_handler.rs+++ b/rust/cloud-storage/document_storage_service/src/api/documents/save_document/save_document_handler.rs@@ -75,7 +75,11 @@ pub async fn save_document_handler(.as_deref().and_then(|f| FileType::from_str(f).ok()){- Some(file_type) => file_type,+ Some(file_type) => match file_type {+ // NOTE: docx files are now all converted to pdf+ FileType::Docx => FileType::Pdf,+ _ => file_type,+ },None => {tracing::error!("invalid file type");return GenericResponse::builder()@@ -95,13 +99,7 @@ pub async fn save_document_handler(// Prevalidation for saving documentsmatch file_type {- FileType::Docx => {- // Since docx are now converted to pdf, there is never a need to save the docx file- return GenericResponse::builder()- .message("no bom parts to save")- .is_error(false)- .send(StatusCode::NOT_MODIFIED);- }+ FileType::Docx => unreachable!("docx files are now converted to pdf"),FileType::Pdf => {tracing::trace!("pre-validation for static file");if req.modification_data.is_none() {diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-0bc3b351e5f4470da1cb41695bca968ed273018cf47e421794f284595c88bc11.json b/rust/cloud-storage/macro_db_client/.sqlx/query-602ab8cc5ef7a8f1756eddb3ba04498975d1bf2b14483da52fed14c2e6a9c92f.jsonsimilarity index 76%rename from rust/cloud-storage/macro_db_client/.sqlx/query-0bc3b351e5f4470da1cb41695bca968ed273018cf47e421794f284595c88bc11.jsonrename to rust/cloud-storage/macro_db_client/.sqlx/query-602ab8cc5ef7a8f1756eddb3ba04498975d1bf2b14483da52fed14c2e6a9c92f.jsonindex 7cedf91bdc..67345361bb 100644--- a/rust/cloud-storage/macro_db_client/.sqlx/query-0bc3b351e5f4470da1cb41695bca968ed273018cf47e421794f284595c88bc11.json+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-602ab8cc5ef7a8f1756eddb3ba04498975d1bf2b14483da52fed14c2e6a9c92f.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n d.name as \"document_name\",\n COALESCE(di.id, db.id) as \"document_version_id!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id?\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n AND\n i.id = $2\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n AND\n b.id = $2\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ",+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n d.name as \"document_name\",\n COALESCE(di.id, db.id) as \"document_version_id!\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id?\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n AND\n i.id = $2\n ) di ON true\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n AND\n b.id = $2\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ","describe": {"columns": [{@@ -118,5 +118,5 @@false]},- "hash": "0bc3b351e5f4470da1cb41695bca968ed273018cf47e421794f284595c88bc11"+ "hash": "602ab8cc5ef7a8f1756eddb3ba04498975d1bf2b14483da52fed14c2e6a9c92f"}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-a8a1349f82cbd20fdde8e1ba926ab48263f4082ee3b67b8512f25fba38b158c9.json b/rust/cloud-storage/macro_db_client/.sqlx/query-c4d8423378131db13674490b01c0d704ba162e0b774d06525c3fbe79a4a08b23.jsonsimilarity index 76%rename from rust/cloud-storage/macro_db_client/.sqlx/query-a8a1349f82cbd20fdde8e1ba926ab48263f4082ee3b67b8512f25fba38b158c9.jsonrename to rust/cloud-storage/macro_db_client/.sqlx/query-c4d8423378131db13674490b01c0d704ba162e0b774d06525c3fbe79a4a08b23.jsonindex 6ddddbd7b0..5ced6a7a31 100644--- a/rust/cloud-storage/macro_db_client/.sqlx/query-a8a1349f82cbd20fdde8e1ba926ab48263f4082ee3b67b8512f25fba38b158c9.json+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-c4d8423378131db13674490b01c0d704ba162e0b774d06525c3fbe79a4a08b23.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" DESC\n LIMIT 1\n ) di ON d.\"fileType\" IS DISTINCT FROM 'docx'\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ",+ "query": "\n SELECT\n d.id as \"document_id\",\n d.owner as \"owner\",\n COALESCE(db.id, di.id) as \"document_version_id!\",\n d.name as \"document_name\",\n d.\"branchedFromId\" as \"branched_from_id\",\n d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n d.\"documentFamilyId\" as \"document_family_id\",\n d.\"createdAt\"::timestamptz as \"created_at\",\n d.\"updatedAt\"::timestamptz as \"updated_at\",\n d.\"fileType\" as \"file_type\",\n db.bom_parts as \"document_bom?\",\n di.modification_data as \"modification_data?\",\n d.\"projectId\" as \"project_id\",\n p.name as \"project_name?\",\n di.sha as \"sha?\",\n dt.sub_type as \"sub_type?: DocumentSubType\"\n FROM\n \"Document\" d\n LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n LEFT JOIN LATERAL (\n SELECT\n i.id,\n i.sha,\n i.\"createdAt\",\n (\n SELECT\n imod.\"modificationData\"\n FROM\n \"DocumentInstanceModificationData\" imod\n WHERE\n imod.\"documentInstanceId\" = i.id\n ) as modification_data,\n i.\"updatedAt\"\n FROM\n \"DocumentInstance\" i\n WHERE\n i.\"documentId\" = d.id\n ORDER BY\n i.\"createdAt\" DESC\n LIMIT 1\n ) di ON true\n LEFT JOIN LATERAL (\n SELECT\n b.id,\n (\n SELECT\n json_agg(\n json_build_object(\n 'id', bp.id,\n 'sha', bp.sha,\n 'path', bp.path\n )\n )\n FROM\n \"BomPart\" bp\n WHERE\n bp.\"documentBomId\" = b.id\n ) as bom_parts\n FROM\n \"DocumentBom\" b\n WHERE\n b.\"documentId\" = d.id\n ORDER BY\n b.\"createdAt\" DESC\n LIMIT 1\n ) db ON d.\"fileType\" = 'docx'\n LEFT JOIN LATERAL (\n SELECT\n p.name\n FROM \"Project\" p\n WHERE p.id = d.\"projectId\"\n ) p ON d.\"projectId\" IS NOT NULL\n WHERE\n d.id = $1\n LIMIT 1\n ","describe": {"columns": [{@@ -117,5 +117,5 @@false]},- "hash": "a8a1349f82cbd20fdde8e1ba926ab48263f4082ee3b67b8512f25fba38b158c9"+ "hash": "c4d8423378131db13674490b01c0d704ba162e0b774d06525c3fbe79a4a08b23"}diff --git a/rust/cloud-storage/macro_db_client/src/document/get_document.rs b/rust/cloud-storage/macro_db_client/src/document/get_document.rsindex 4a027843e6..afa1edb23b 100644--- a/rust/cloud-storage/macro_db_client/src/document/get_document.rs+++ b/rust/cloud-storage/macro_db_client/src/document/get_document.rs@@ -313,7 +313,7 @@ pub async fn get_document(ORDER BYi."createdAt" DESCLIMIT 1- ) di ON d."fileType" IS DISTINCT FROM 'docx'+ ) di ON trueLEFT JOIN LATERAL (SELECTb.id,@@ -427,7 +427,7 @@ pub async fn get_document_version(i."documentId" = d.idANDi.id = $2- ) di ON d."fileType" IS DISTINCT FROM 'docx'+ ) di ON trueLEFT JOIN LATERAL (SELECTb.id,