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.

feat(dss): create/copy document handles tasks (#451)

Will Hutchinson24cab3a68fb4
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs
index 0b3f8c7a38..737f21dee6 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_handler.rs
@@ -99,6 +99,7 @@ pub(in crate::api) async fn create_document_handler(
project_id: req.project_id.as_deref(),
email_attachment_id: req.email_attachment_id,
created_at: req.created_at.as_ref(),
+ is_task: req.is_task,
},
)
.await;
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_v2.rs b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_v2.rs
index 0d82367ae4..42d609fcea 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_v2.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_document_v2.rs
@@ -19,6 +19,7 @@ pub struct CreateDocumentParams<'a> {
pub project_id: Option<&'a str>,
pub email_attachment_id: Option<Uuid>,
pub created_at: Option<&'a DateTime<Utc>>,
+ pub is_task: bool,
}
/// Creates a document in the database
@@ -40,7 +41,9 @@ pub async fn create_document(
project_id,
email_attachment_id,
created_at,
+ is_task,
} = params;
+
tracing::trace!("creating document v2");
let share_permission = if let Some(file_type) = file_type {
@@ -75,6 +78,7 @@ pub async fn create_document(
skip_history: false,
email_attachment_id,
created_at,
+ is_task,
},
)
.await
diff --git a/rust/cloud-storage/email_service/src/bin/backfill_gmail_attachments/upload.rs b/rust/cloud-storage/email_service/src/bin/backfill_gmail_attachments/upload.rs
index f89caa1ddd..d661b218c4 100644
--- a/rust/cloud-storage/email_service/src/bin/backfill_gmail_attachments/upload.rs
+++ b/rust/cloud-storage/email_service/src/bin/backfill_gmail_attachments/upload.rs
@@ -131,6 +131,7 @@ impl AttachmentProcessor {
project_id: None,
created_at: Some(attachment.internal_date_ts),
email_attachment_id: Some(attachment.attachment_db_id),
+ is_task: false,
},
&self.macro_id_destination,
)
diff --git a/rust/cloud-storage/email_service/src/util/upload_attachment.rs b/rust/cloud-storage/email_service/src/util/upload_attachment.rs
index 9c4a32003b..9a4f49cbe7 100644
--- a/rust/cloud-storage/email_service/src/util/upload_attachment.rs
+++ b/rust/cloud-storage/email_service/src/util/upload_attachment.rs
@@ -129,6 +129,7 @@ async fn create_dss_document_record(
project_id: None,
created_at: Some(p.internal_date_ts),
email_attachment_id: Some(p.attachment_db_id),
+ is_task: false,
};
dss_client
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-5f836243295a3d3de05ee966cbdf68f20831b1a073af32d703705a7e7fea55af.json b/rust/cloud-storage/macro_db_client/.sqlx/query-5f836243295a3d3de05ee966cbdf68f20831b1a073af32d703705a7e7fea55af.json
new file mode 100644
index 0000000000..86888a61b9
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-5f836243295a3d3de05ee966cbdf68f20831b1a073af32d703705a7e7fea55af.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO document_task (document_id)\n VALUES ($1)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "5f836243295a3d3de05ee966cbdf68f20831b1a073af32d703705a7e7fea55af"
+}
diff --git a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs b/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
index 73da4a62c4..f161caeadf 100644
--- a/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/copy_document/mod.rs
@@ -234,6 +234,18 @@ pub(in crate::document) async fn copy_non_docx_document(
None
};
+ if original_document.is_task {
+ sqlx::query!(
+ r#"
+ INSERT INTO document_task (document_id)
+ VALUES ($1)
+ "#,
+ document.id
+ )
+ .execute(transaction.as_mut())
+ .await?;
+ }
+
Ok(DocumentMetadata {
document_id: document.id.clone(),
owner: user_id.to_string(),
@@ -250,7 +262,7 @@ pub(in crate::document) async fn copy_non_docx_document(
modification_data: original_modification_data,
created_at: document.created_at,
updated_at: document.updated_at,
- is_task: false, // TODO: @daniel please update this when you add in task creation/copy
+ is_task: original_document.is_task,
})
}
diff --git a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
index 1f34b44e73..8c6659f4cb 100644
--- a/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
+++ b/rust/cloud-storage/macro_db_client/src/document/v2/create.rs
@@ -28,6 +28,9 @@ pub struct CreateDocumentArgs<'a> {
pub email_attachment_id: Option<Uuid>,
/// Optional value. defaults to now if not included
pub created_at: Option<&'a chrono::DateTime<chrono::Utc>>,
+ /// Whether the document is a task.
+ /// This is only applicable for md documents.
+ pub is_task: bool,
}
/// Creates a new document
@@ -68,6 +71,7 @@ pub async fn create_document_txn(
skip_history,
created_at: _, // overwritten below
email_attachment_id,
+ is_task,
} = args;
// default to now if created_at argument not included
@@ -123,6 +127,24 @@ pub async fn create_document_txn(
.id
};
+ if is_task {
+ if file_type != Some(FileType::Md) {
+ return Err(anyhow::anyhow!(
+ "is_task is only applicable for md documents"
+ ));
+ }
+
+ sqlx::query!(
+ r#"
+ INSERT INTO document_task (document_id)
+ VALUES ($1)
+ "#,
+ document_id
+ )
+ .execute(&mut **transaction)
+ .await?;
+ }
+
// Docx documents have their versions associated with a DocumentBom
// whereas all other file types use DocumentInstance
let document_version = match file_type {
@@ -207,7 +229,7 @@ pub async fn create_document_txn(
project_name,
document_version.created_at,
document_version.updated_at,
- false, // TODO: @daniel please update this when you add in task creation in create document
+ is_task,
))
}
@@ -321,6 +343,7 @@ mod tests {
skip_history: false,
email_attachment_id: None,
created_at: Some(&ts),
+ is_task: false,
},
)
.await?;
@@ -347,6 +370,7 @@ mod tests {
skip_history: false,
email_attachment_id: None,
created_at: None,
+ is_task: false,
},
)
.await?;
@@ -385,6 +409,7 @@ mod tests {
skip_history: false,
email_attachment_id: None,
created_at: Some(&ts),
+ is_task: false,
},
)
.await?;
@@ -414,6 +439,7 @@ mod tests {
skip_history: false,
email_attachment_id: None,
created_at: None,
+ is_task: false,
},
)
.await?;
@@ -444,6 +470,7 @@ mod tests {
skip_history: false,
email_attachment_id: None,
created_at: None,
+ is_task: false,
},
)
.await;
diff --git a/rust/cloud-storage/macro_db_client/src/instructions/create.rs b/rust/cloud-storage/macro_db_client/src/instructions/create.rs
index 091d16b5ae..488fcd049f 100644
--- a/rust/cloud-storage/macro_db_client/src/instructions/create.rs
+++ b/rust/cloud-storage/macro_db_client/src/instructions/create.rs
@@ -34,6 +34,7 @@ pub async fn create_instructions_document(
skip_history: false,
email_attachment_id: None,
created_at: None,
+ is_task: false,
},
)
.await?;
diff --git a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
index 5098301113..bdd6ea1dcd 100644
--- a/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
+++ b/rust/cloud-storage/macro_db_client/src/projects/upload_folder/mod.rs
@@ -121,6 +121,7 @@ async fn traverse_with_ids(
skip_history: true,
email_attachment_id: None,
created_at: None,
+ is_task: false,
},
)
.await?;
diff --git a/rust/cloud-storage/model/src/document/response/mod.rs b/rust/cloud-storage/model/src/document/response/mod.rs
index 82d535910b..2d3aae99a8 100644
--- a/rust/cloud-storage/model/src/document/response/mod.rs
+++ b/rust/cloud-storage/model/src/document/response/mod.rs
@@ -222,4 +222,9 @@ pub struct CreateDocumentRequest {
pub email_attachment_id: Option<Uuid>,
/// Optional time to set the document's created_at to. Set when backfilling email attachments.
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
+ /// Whether the document is a task.
+ /// This is only applicable for md documents and the request will fail if the file type is not
+ /// md.
+ #[serde(default)]
+ pub is_task: bool,
}