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(search): send name update events for all entity types (#292)

Will Hutchinsonf9b04ab275fd
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index d8e3ad0b0b..d01330affb 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -1745,6 +1745,7 @@ dependencies = [
"model-entity",
"model_notifications",
"models_comms",
+ "models_opensearch",
"models_permissions",
"reqwest",
"secretsmanager_client",
@@ -2492,6 +2493,7 @@ dependencies = [
"metering_service_client",
"model",
"models_dcs",
+ "models_opensearch",
"models_permissions",
"regex",
"reqwest",
@@ -2581,6 +2583,7 @@ dependencies = [
"model-entity",
"model_notifications",
"models_bulk_upload",
+ "models_opensearch",
"models_pagination",
"models_permissions",
"models_soup",
@@ -2911,6 +2914,7 @@ dependencies = [
"model-entity",
"model_notifications",
"models_email",
+ "models_opensearch",
"models_pagination",
"redis",
"reqwest",
diff --git a/rust/cloud-storage/comms_service/Cargo.toml b/rust/cloud-storage/comms_service/Cargo.toml
index 61db33d66e..6c6c4172d4 100644
--- a/rust/cloud-storage/comms_service/Cargo.toml
+++ b/rust/cloud-storage/comms_service/Cargo.toml
@@ -73,6 +73,7 @@ tracing = { workspace = true }
utoipa = { workspace = true, features = ["axum_extras", "chrono", "uuid"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
uuid = { workspace = true }
+models_opensearch = { path = "../models_opensearch" }
[package.metadata.cargo-machete]
ignored = ["connection_gateway"]
diff --git a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
index aefd69d40f..98fcf2887d 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs
@@ -8,7 +8,10 @@ use axum::{
use comms_db_client::channels::create_channel::{CreateChannelOptions, create_channel};
use model::comms::ChannelType;
use model::user::UserContext;
+use models_opensearch::SearchEntityType;
use serde::{Deserialize, Serialize};
+use sqs_client::search::{SearchQueueMessage, name::UpdateEntityName};
+use tracing::Instrument;
use utoipa::ToSchema;
#[derive(Debug, Serialize, Deserialize, ToSchema)]
@@ -111,6 +114,29 @@ pub async fn create_channel_handler(
})?;
}
+ if req.name.is_some() {
+ tokio::spawn({
+ let sqs_client = ctx.sqs_client.clone();
+ let channel_id = id;
+ async move {
+ tracing::trace!("sending message to search extractor queue");
+
+ let _ = sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ UpdateEntityName {
+ entity_id: channel_id,
+ entity_type: SearchEntityType::Channels,
+ },
+ ))
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+ }
+ .in_current_span()
+ });
+ }
+
Ok((
StatusCode::OK,
Json(CreateChannelResponse { id: id.to_string() }),
diff --git a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs
index fc4658455c..a7f55de2f3 100644
--- a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs
+++ b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs
@@ -7,6 +7,8 @@ use axum::{Json, extract::State, http::StatusCode};
use axum_extra::extract::Cached;
use comms_db_client::channels::patch_channel::{self, PatchChannelOptions};
use model::comms::ChannelType;
+use models_opensearch::SearchEntityType;
+use tracing::Instrument;
#[utoipa::path(
patch,
@@ -36,6 +38,8 @@ pub async fn patch_channel_handler(
));
}
+ let name = req.channel_name.clone();
+
patch_channel::patch_channel(&ctx.db, &channel_id, &channel_owner.context.user_id, req)
.await
.map_err(|e| {
@@ -47,5 +51,30 @@ pub async fn patch_channel_handler(
)
})?;
+ if name.is_some() {
+ tokio::spawn({
+ let sqs_client = ctx.sqs_client.clone();
+ let channel_id = channel_id;
+ async move {
+ tracing::trace!("sending message to search extractor queue");
+
+ let _ = sqs_client
+ .send_message_to_search_event_queue(
+ sqs_client::search::SearchQueueMessage::UpdateEntityName(
+ sqs_client::search::name::UpdateEntityName {
+ entity_id: channel_id,
+ entity_type: SearchEntityType::Channels,
+ },
+ ),
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+ }
+ .in_current_span()
+ });
+ }
+
Ok((StatusCode::OK, "patched channel".to_string()))
}
diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.toml
index 559f99f1a3..7ed66c8fb9 100644
--- a/rust/cloud-storage/document_cognition_service/Cargo.toml
+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml
@@ -96,6 +96,7 @@ utoipa = { workspace = true, features = ["axum_extras", "chrono"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
uuid = { workspace = true }
macro_user_id = { path = "../macro_user_id" }
+models_opensearch = { path = "../models_opensearch" }
[dev-dependencies]
macro_auth = { path = "../macro_auth", features = ["testing"] }
diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs
index b32b42010c..60aae1cf31 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/create_user_chat.rs
@@ -23,6 +23,8 @@ use macro_middleware::cloud_storage::ensure_access::{
use model::chat::NewChatAttachment;
use model::{chat::AttachmentType, response::StringIDResponse, user::UserContext};
use models_permissions::share_permission::access_level::EditAccessLevel;
+use sqs_client::search::SearchQueueMessage;
+use tracing::Instrument;
#[utoipa::path(
post,
@@ -173,5 +175,33 @@ pub async fn create_user_chat_v2(
)
.await;
+ tokio::spawn({
+ let sqs_client = ctx.sqs_client.clone();
+ let chat_id = chat.clone();
+ async move {
+ tracing::trace!("sending message to search extractor queue");
+ let chat_id = match macro_uuid::string_to_uuid(&chat_id) {
+ Ok(chat_id) => chat_id,
+ Err(err) => {
+ tracing::error!(error=?err, "failed to convert chat_id to uuid");
+ return;
+ }
+ };
+
+ let _ = sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ sqs_client::search::name::UpdateEntityName {
+ entity_id: chat_id,
+ entity_type: models_opensearch::SearchEntityType::Chats,
+ },
+ ))
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+ }
+ .in_current_span()
+ });
+
Ok(StringIDResponse { id: chat })
}
diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs
index 5f87f9f648..fb4590cc73 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/patch_chat.rs
@@ -117,8 +117,31 @@ async fn patch_chat_v2(
)
.await;
- if req.name.is_some()
- && let Err(e) = ctx
+ if req.name.is_some() {
+ match macro_uuid::string_to_uuid(&chat_id) {
+ Ok(chat_id) => {
+ let _ = ctx
+ .sqs_client
+ .send_message_to_search_event_queue(
+ sqs_client::search::SearchQueueMessage::UpdateEntityName(
+ sqs_client::search::name::UpdateEntityName {
+ entity_id: chat_id,
+ entity_type: models_opensearch::SearchEntityType::Chats,
+ },
+ ),
+ )
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+ }
+ Err(err) => {
+ tracing::error!(error=?err, "failed to convert chat_id to uuid");
+ }
+ }
+
+ // TODO: remove once we have fully moved to names index
+ let _ = ctx
.sqs_client
.send_message_to_search_event_queue(
sqs_client::search::SearchQueueMessage::UpdateChatMessageMetadata(
@@ -128,12 +151,9 @@ async fn patch_chat_v2(
),
)
.await
- {
- tracing::error!(
- error = %e,
- chat_id = %chat_id,
- "Failed to send message to search event queue"
- );
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
}
Ok(())
diff --git a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs
index b6c6f85d3e..aa4d6121ac 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_message/mod.rs
@@ -31,7 +31,9 @@ use anyhow::{Context, Result};
use futures::{future::join_all, stream::StreamExt};
use metering_service_client::{CreateUsageRecordRequest, OperationType, ServiceName};
use model::chat::{NewAttachment, NewChatMessage};
+use models_opensearch::SearchEntityType;
use sqs_client::search::SearchQueueMessage;
+use sqs_client::search::name::UpdateEntityName;
use std::sync::Arc;
use tokio;
use tokio::sync::mpsc::UnboundedSender;
@@ -417,7 +419,22 @@ pub async fn handle_send_chat_message(
)
});
- // Send the message to the search event queue
+ // Send the message to the search event queue for setting chat name
+ match macro_uuid::string_to_uuid(&incoming_message.chat_id) {
+ Ok(chat_id) => {
+ let _ = ctx.sqs_client.send_message_to_search_event_queue(
+ SearchQueueMessage::UpdateEntityName(UpdateEntityName {
+ entity_id: chat_id,
+ entity_type: SearchEntityType::Chats,
+ }),
+ ).await.inspect_err(|err| tracing::error!(error=?err, "failed to send message to search event queue"));
+ }
+ Err(err) => {
+ tracing::error!(error=?err, "failed to convert chat_id to uuid");
+ }
+ }
+
+ // TODO: remove this once we have fully moved to names index
let _ = ctx
.sqs_client
.send_message_to_search_event_queue(SearchQueueMessage::UpdateChatMessageMetadata(
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index e263400c2e..e805997b13 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -105,6 +105,7 @@ utoipa = { workspace = true, features = ["axum_extras"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
uuid = { workspace = true }
zip = { workspace = true }
+models_opensearch = { path = "../models_opensearch" }
[dev-dependencies]
cool_asserts = "2"
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_blank_docx.rs b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_blank_docx.rs
deleted file mode 100644
index 4746c896f5..0000000000
--- a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/create_blank_docx.rs
+++ /dev/null
@@ -1,130 +0,0 @@
-use axum::{
- Extension, Json,
- extract::State,
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use macro_middleware::cloud_storage::ensure_access::project::ProjectBodyAccessLevelExtractor;
-use models_permissions::share_permission::access_level::EditAccessLevel;
-
-use crate::{api::context::ApiContext, model::request::documents::create::CreateBlankDocxRequest};
-use model::{
- document::{DocumentMetadata, SaveBomPart},
- response::GenericErrorResponse,
- user::UserContext,
-};
-
-/// Creates a new blank docx file for the user
-#[utoipa::path(
- post,
- path = "/documents/blank_docx",
- operation_id = "create_blank_docx",
- request_body = CreateBlankDocxRequest,
- responses(
- (status = 200, body=DocumentMetadata),
- (status = 401, body=GenericErrorResponse),
- (status = 403, body=GenericErrorResponse),
- (status = 400, body=GenericErrorResponse),
- (status = 500, body=GenericErrorResponse),
- )
- )]
-#[tracing::instrument(skip(ctx, user_context, project), fields(user_id=?user_context.user_id))]
-pub(in crate::api) async fn handler(
- State(ctx): State<ApiContext>,
- user_context: Extension<UserContext>,
- project: ProjectBodyAccessLevelExtractor<EditAccessLevel, CreateBlankDocxRequest>,
-) -> Result<Response, Response> {
- let req = project.into_inner();
-
- // Hardcoded blank docx file that is broken into it's bom parts
- // TODO: we will need some sort of script to populate this for other envs in the future
- let blank_docx_bom_parts: Vec<SaveBomPart> = vec![
- SaveBomPart {
- path: "[Content_Types].xml".to_string(),
- sha: "bda1ffc7b056aa39e84d557fd224ff3a2e26099961c5133d6c7367208b1351dc".to_string(),
- },
- SaveBomPart {
- path: "_rels/.rels".to_string(),
- sha: "c30fe099dbcfed4ecc4ae544ccf82f432c8d3bb665e2a301df283738b196d803".to_string(),
- },
- SaveBomPart {
- path: "word/_rels/document.xml.rels".to_string(),
- sha: "b725d5476e76f555fc24ecb908474fd29b671687336e5e1177a5c4c35cb5939f".to_string(),
- },
- SaveBomPart {
- path: "word/document.xml".to_string(),
- sha: "64bdf246efebfe0f7356698fbbbe2e6d0662450bcbe17b2bb6dd38793cc258b1".to_string(),
- },
- SaveBomPart {
- path: "word/theme/theme1.xml".to_string(),
- sha: "fe83a235c1dfa45cc081c3b2ad60fe4416bf0d1e05e46b02bd2293bdc5f4bc68".to_string(),
- },
- SaveBomPart {
- path: "word/settings.xml".to_string(),
- sha: "aba5e632b6f7a92b179fa0366aa9d7b3c6d37bbdc66174da5f911d9cac937fda".to_string(),
- },
- SaveBomPart {
- path: "docProps/core.xml".to_string(),
- sha: "530df3afaf5a42dab8a9ac918cba19f5989ccced888d36090095a7e11328539c".to_string(),
- },
- SaveBomPart {
- path: "word/fontTable.xml".to_string(),
- sha: "287be69ef4600ea93a78f085ee0442c324ff124c0f1ee221a8ec8cf045645e6e".to_string(),
- },
- SaveBomPart {
- path: "docProps/custom.xml".to_string(),
- sha: "cc5d15cf09603a3325ce4ccd1bae9553b27b6722f6c5c027615300f970f3a573".to_string(),
- },
- SaveBomPart {
- path: "word/webSettings.xml".to_string(),
- sha: "c99d68045ebe2a916a8ff7997daa87efa2526650089c91c0e7529b73b2ea33c7".to_string(),
- },
- SaveBomPart {
- path: "word/styles.xml".to_string(),
- sha: "d6a5bd435203456c0e73baa643555292aaeb90a6b677cd8aaf5de84c82dc7880".to_string(),
- },
- SaveBomPart {
- path: "docProps/app.xml".to_string(),
- sha: "365d2edf78885ab0dbaa801ca8b63e930ddb8f35f6edc834d897153ee4588910".to_string(),
- },
- ];
-
- let shas = blank_docx_bom_parts
- .iter()
- .map(|b| b.sha.clone())
- .collect::<Vec<String>>();
-
- // Get the share permissions
- let share_permission = macro_share_permissions::share_permission::create_new_share_permission();
-
- let document_metadata: DocumentMetadata =
- macro_db_client::document::create_blank_docx::create_blank_docx(
- ctx.db.clone(),
- "New Document",
- &user_context.user_id,
- req.project_id.as_deref(),
- &share_permission,
- blank_docx_bom_parts,
- )
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "unable to create blank docx document");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(GenericErrorResponse {
- error: true,
- message: "unable to create blank docx document".to_string(),
- }),
- )
- .into_response()
- })?;
-
- // Incr the SHA count
- if let Err(e) = ctx.redis_client.increment_counts(shas).await {
- // We don't actually care if this fails, the sha counts being messed
- // up is not the end of the world.
- tracing::error!(error=?e, "unable to increment sha ref count");
- }
-
- Ok((StatusCode::OK, Json(document_metadata)).into_response())
-}
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 1bf331e077..b3b36f5f93 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
@@ -2,7 +2,11 @@ use std::str::FromStr;
use axum::{Extension, extract::State, http::StatusCode, response::IntoResponse};
use macro_middleware::cloud_storage::ensure_access::project::ProjectBodyAccessLevelExtractor;
+use models_opensearch::SearchEntityType;
use models_permissions::share_permission::access_level::EditAccessLevel;
+use sqs_client::search::SearchQueueMessage;
+use sqs_client::search::name::UpdateEntityName;
+use tracing::Instrument;
use crate::api::middleware::internal_access::InternalUser;
use crate::api::{
@@ -114,6 +118,38 @@ pub(in crate::api) async fn create_document_handler(
}
};
+ tokio::spawn({
+ let sqs_client = state.sqs_client.clone();
+ let document_id = response_data
+ .document_response
+ .document_metadata
+ .document_id
+ .clone();
+ async move {
+ tracing::trace!("sending message to search extractor queue");
+ let document_id = match macro_uuid::string_to_uuid(&document_id) {
+ Ok(document_id) => document_id,
+ Err(err) => {
+ tracing::error!(error=?err, "failed to convert document_id to uuid");
+ return;
+ }
+ };
+
+ let _ = sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ UpdateEntityName {
+ entity_id: document_id,
+ entity_type: SearchEntityType::Documents,
+ },
+ ))
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+ }
+ .in_current_span()
+ });
+
return GenericResponse::builder()
.data(&response_data)
.send(StatusCode::OK);
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/mod.rs b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/mod.rs
index 2deccf21e4..e26c7b66cd 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/create_document/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/create_document/mod.rs
@@ -1,4 +1,3 @@
-pub(in crate::api) mod create_blank_docx;
mod create_document_handler;
mod create_document_v2;
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs b/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs
index 32071aa7de..10b5ff123c 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/edit_document/edit_document_v2.rs
@@ -10,9 +10,10 @@ use model::{
response::{ErrorResponse, GenericSuccessResponse, SuccessResponse},
user::UserContext,
};
+use models_opensearch::SearchEntityType;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use models_permissions::share_permission::access_level::AccessLevel;
-use sqs_client::search::{SearchQueueMessage, document::DocumentId};
+use sqs_client::search::{SearchQueueMessage, document::DocumentId, name::UpdateEntityName};
use tracing::Instrument;
pub async fn edit_document(
@@ -88,9 +89,32 @@ pub async fn edit_document(
let document_id = document_context.document_id.clone();
async move {
tracing::trace!("sending message to search extractor queue");
+ let document_id = match macro_uuid::string_to_uuid(&document_id) {
+ Ok(document_id) => document_id,
+ Err(err) => {
+ tracing::error!(error=?err, "failed to convert document_id to uuid");
+ return;
+ }
+ };
+
+ let _ = sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ UpdateEntityName {
+ entity_id: document_id,
+ entity_type: SearchEntityType::Documents,
+ },
+ ))
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");
+ });
+
+ // TODO: remove once we have fully moved to names index
let _ = sqs_client
.send_message_to_search_event_queue(SearchQueueMessage::UpdateDocumentMetadata(
- DocumentId { document_id },
+ DocumentId {
+ document_id: document_id.to_string(),
+ },
))
.await
.inspect_err(|e| {
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/mod.rs b/rust/cloud-storage/document_storage_service/src/api/documents/mod.rs
index 5aaf60cf0d..710e8f605b 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/mod.rs
@@ -84,23 +84,6 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {
)),
),
)
- .route(
- "/blank_docx",
- post(create_document::create_blank_docx::handler).layer(
- ServiceBuilder::new()
- .layer(axum::middleware::from_fn(
- macro_middleware::auth::ensure_user_exists::handler,
- ))
- .layer(axum::middleware::from_fn_with_state(
- state.clone(),
- macro_middleware::user_permissions::attach_user_permissions::handler,
- ))
- .layer(axum::middleware::from_fn_with_state(
- state.clone(),
- macro_middleware::user_permissions::validate_user_quota::document_handler,
- )),
- ),
- )
.route(
"/list",
get(get_document_list::get_document_list_handler).layer(axum::middleware::from_fn(
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 0ff74d8299..9f76161b42 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -133,7 +133,6 @@ use utoipa::OpenApi;
documents::get_document::handler,
documents::get_document_version::handler,
documents::create_document::create_document_handler,
- documents::create_document::create_blank_docx::handler,
documents::copy_document::copy_document_handler,
documents::save_document::save_document_handler,
documents::pre_save::presave_document_handler,
diff --git a/rust/cloud-storage/document_storage_service/src/model/request/documents/create.rs b/rust/cloud-storage/document_storage_service/src/model/request/documents/create.rs
deleted file mode 100644
index 4f23ac3b60..0000000000
--- a/rust/cloud-storage/document_storage_service/src/model/request/documents/create.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-use utoipa::ToSchema;
-
-#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug, ToSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateBlankDocxRequest {
- //// Optional project id to be used to what project the document belongs to.
- pub project_id: Option<String>,
-}
diff --git a/rust/cloud-storage/document_storage_service/src/model/request/documents/mod.rs b/rust/cloud-storage/document_storage_service/src/model/request/documents/mod.rs
index 9ee49a49fe..ab31b4fdf1 100644
--- a/rust/cloud-storage/document_storage_service/src/model/request/documents/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/model/request/documents/mod.rs
@@ -1,5 +1,4 @@
pub mod copy;
-pub mod create;
pub mod edit;
pub mod get_user_documents;
pub mod location;
diff --git a/rust/cloud-storage/email_db_client/src/threads/insert.rs b/rust/cloud-storage/email_db_client/src/threads/insert.rs
index 41c1878c18..18b4470e97 100644
--- a/rust/cloud-storage/email_db_client/src/threads/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/insert.rs
@@ -9,6 +9,7 @@ use sqlx::{Executor, PgPool, Postgres};
use std::collections::HashMap;
/// inserts a thread and all of its messages into the database
+/// returns the db thread id
#[tracing::instrument(
skip(pool, service_thread),
fields(
@@ -21,7 +22,7 @@ pub async fn insert_thread_and_messages(
pool: &PgPool,
service_thread: thread::Thread,
link_id: Uuid,
-) -> anyhow::Result<()> {
+) -> anyhow::Result<Uuid> {
let mut recipient_map: HashMap<String, UpsertedRecipients> = HashMap::new();
// we have to insert addresses before inserting the messages. these values are shared
@@ -71,7 +72,7 @@ pub async fn insert_thread_and_messages(
.context("Failed to update messages replying_to_ids")?;
}
- Ok::<_, anyhow::Error>(())
+ Ok(thread_id)
}
.await;
@@ -88,7 +89,7 @@ pub async fn insert_thread_and_messages(
tx.commit().await.context("Failed to commit transaction")?;
- Ok(())
+ Ok(result.unwrap())
}
/// inserts a thread object into the database using the provided transaction
diff --git a/rust/cloud-storage/email_service/Cargo.toml b/rust/cloud-storage/email_service/Cargo.toml
index 56458cdea6..6082e74705 100644
--- a/rust/cloud-storage/email_service/Cargo.toml
+++ b/rust/cloud-storage/email_service/Cargo.toml
@@ -105,6 +105,7 @@ urlencoding = { workspace = true }
utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
uuid = { workspace = true }
+models_opensearch = { path = "../models_opensearch" }
[dev-dependencies]
macro_auth = { path = "../macro_auth", features = ["testing"] }
diff --git a/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs b/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs
index fb9f4dbc92..4e5e6d6d43 100644
--- a/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/backfill/update_metadata.rs
@@ -3,8 +3,10 @@ use crate::pubsub::context::PubSubContext;
use models_email::email::service::backfill::{BackfillPubsubMessage, UpdateMetadataPayload};
use models_email::email::service::link;
use models_email::email::service::pubsub::{DetailedError, FailureReason, ProcessingError};
+use models_opensearch::SearchEntityType;
use sqs_client::search::SearchQueueMessage;
use sqs_client::search::email::EmailThreadMessage;
+use sqs_client::search::name::UpdateEntityName;
/// This step is invoked by BackfillMessage once all messages in a thread have been backfilled.
/// Updates the thread metadata in the database, the replying_to_id values of its messages, and
@@ -96,5 +98,21 @@ pub async fn update_thread_metadata(
})
})?;
+ // notify search about new entity
+ ctx.sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ UpdateEntityName {
+ entity_id: p.thread_db_id,
+ entity_type: SearchEntityType::Emails,
+ },
+ ))
+ .await
+ .map_err(|e| {
+ ProcessingError::NonRetryable(DetailedError {
+ reason: FailureReason::SqsEnqueueFailed,
+ source: e.context("Failed to send message to search extractor queue"),
+ })
+ })?;
+
Ok(())
}
diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs
index 5a361eba3e..e3bd79a448 100644
--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs
@@ -24,8 +24,10 @@ use models_email::gmail::operations::GmailApiOperation;
use models_email::gmail::webhook::UpsertMessagePayload;
use models_email::service::message::Message;
use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};
+use models_opensearch::SearchEntityType;
use sqs_client::search::SearchQueueMessage;
use sqs_client::search::email::EmailMessage;
+use sqs_client::search::name::UpdateEntityName;
use std::collections::{HashMap, HashSet};
use std::result;
use uuid::Uuid;
@@ -406,7 +408,7 @@ async fn fetch_and_insert_thread(
// insert threads into db
for thread in threads.into_iter() {
- threads::insert::insert_thread_and_messages(&ctx.db, thread, link_id)
+ let thread_id = threads::insert::insert_thread_and_messages(&ctx.db, thread, link_id)
.await
.map_err(|e| {
ProcessingError::Retryable(DetailedError {
@@ -414,6 +416,22 @@ async fn fetch_and_insert_thread(
source: e.context("Failed to insert thread and messages".to_string()),
})
})?;
+
+ // notify search about new entity
+ ctx.sqs_client
+ .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(
+ UpdateEntityName {
+ entity_id: thread_id,
+ entity_type: SearchEntityType::Emails,
+ },
+ ))
+ .await
+ .map_err(|e| {
+ ProcessingError::NonRetryable(DetailedError {
+ reason: FailureReason::SqsEnqueueFailed,
+ source: e.context("Failed to send message to search extractor queue"),
+ })
+ })?;
}
Ok(())