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(email-service): Specify thread access level in get thread endpoint (#326)

Evan Hutnike539d8968bda
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 69052509c7..7059a329e7 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2953,6 +2953,7 @@ dependencies = [
"models_email",
"models_opensearch",
"models_pagination",
+ "models_permissions",
"redis",
"reqwest",
"s3_client",
diff --git a/rust/cloud-storage/email_service/Cargo.toml b/rust/cloud-storage/email_service/Cargo.toml
index cc54badd2f..3fea55dba9 100644
--- a/rust/cloud-storage/email_service/Cargo.toml
+++ b/rust/cloud-storage/email_service/Cargo.toml
@@ -71,6 +71,7 @@ model-entity = { path = "../model-entity" }
model_notifications = { path = "../model_notifications" }
models_email = { path = "../models_email" }
models_pagination = { path = "../models_pagination", features = ["axum"] }
+models_permissions = { path = "../models_permissions" }
redis = { workspace = true, features = [
"cluster-async",
"tokio-native-tls-comp",
diff --git a/rust/cloud-storage/email_service/src/api/email/threads/get.rs b/rust/cloud-storage/email_service/src/api/email/threads/get.rs
index f180508c0d..7c05c2aacc 100644
--- a/rust/cloud-storage/email_service/src/api/email/threads/get.rs
+++ b/rust/cloud-storage/email_service/src/api/email/threads/get.rs
@@ -11,6 +11,7 @@ use models_email::email::service::thread;
use models_email::service::link::Link;
use models_email::service::message::MessageWithBodyReplyless;
use models_email::service::thread::APIThread;
+use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::types::Uuid;
use strum_macros::AsRefStr;
use thiserror::Error;
@@ -65,6 +66,7 @@ pub struct GetThreadParams {
pub struct GetThreadResponse {
/// the thread, with messages inside
pub thread: thread::APIThread,
+ pub access_level: AccessLevel,
}
/// Represents pagination parameters with defaults applied
@@ -127,7 +129,7 @@ pub async fn get_thread_handler(
}
// if the requester doesn't own the thread, check if it has been shared with the requester
- if thread.link_id != link.id {
+ let access_level = if thread.link_id != link.id {
// call will fail if user doesn't have an access level. otherwise, we can return the thread
ctx.dss_client
.get_thread_access_level(&link.macro_id, &thread.db_id.unwrap().to_string())
@@ -135,8 +137,11 @@ pub async fn get_thread_handler(
.map_err(|e| {
tracing::error!(error=?e, "unable to get access level for thread for user");
GetThreadError::ThreadNotFound
- })?;
- }
+ })?
+ } else {
+ // it's the user's thread
+ AccessLevel::Owner
+ };
let tasks: Vec<_> = thread
.clone()
@@ -151,7 +156,10 @@ pub async fn get_thread_handler(
Ok((
StatusCode::OK,
- Json(GetThreadResponse { thread: api_thread }),
+ Json(GetThreadResponse {
+ access_level,
+ thread: api_thread,
+ }),
)
.into_response())
}