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.

remove comms service client from macro_middleware crate (#1082)

Will Hutchinsonce5384e64e55
diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.ts
index 45ce1df7c8..a695263dea 100644
--- a/infra/stacks/cloud-storage-service/index.ts
+++ b/infra/stacks/cloud-storage-service/index.ts
@@ -313,12 +313,6 @@ const cloudStorageService = new CloudStorageService(
name: 'SEARCH_EVENT_QUEUE',
value: pulumi.interpolate`${searchEventQueueName}`,
},
- {
- name: 'COMMS_SERVICE_URL',
- value: `https://comms-service${
- stack === 'prod' ? '' : `-${stack}`
- }.macro.com`,
- },
{
name: 'DOCUMENT_PERMISSION_JWT_SECRET_KEY',
value: pulumi.interpolate`${DOCUMENT_STORAGE_PERMISSIONS_KEY}`,
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index ef93e16b0c..6be0b9f0b0 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2726,7 +2726,7 @@ dependencies = [
"clap",
"cloudfront_sign",
"comms",
- "comms_service_client",
+ "comms_db_client",
"connection_gateway",
"cool_asserts",
"document_sub_type",
@@ -5066,7 +5066,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"axum",
- "comms_service_client",
"http-body-util",
"macro_auth",
"macro_db_client",
@@ -5153,6 +5152,7 @@ name = "macro_share_permissions"
version = "0.1.0"
dependencies = [
"anyhow",
+ "comms_db_client",
"comms_service_client",
"macro_db_client",
"macro_user_id",
@@ -6656,7 +6656,6 @@ name = "properties"
version = "0.1.0"
dependencies = [
"anyhow",
- "comms_service_client",
"email_db_client",
"futures",
"macro_db_client",
diff --git a/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs b/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
index 568c9cbf7e..dca4e3b97f 100644
--- a/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
+++ b/rust/cloud-storage/comms_db_client/src/participants/get_participants.rs
@@ -4,6 +4,7 @@ use doppleganger::Mirror;
use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model::comms::ChannelId;
+use sqlx::Transaction;
use sqlx::{Pool, Postgres};
use uuid::Uuid;
@@ -16,6 +17,42 @@ pub enum DbParticipantRole {
Owner,
}
+#[tracing::instrument(skip(tsx))]
+pub async fn get_participants_tsx<'t>(
+ tsx: &mut Transaction<'t, Postgres>,
+ channel_id: &Uuid,
+) -> Result<Vec<models_comms::channel::ChannelParticipant>, sqlx::Error> {
+ let participants = sqlx::query!(
+ r#"
+ SELECT
+ user_id,
+ channel_id,
+ joined_at,
+ left_at,
+ role as "role: DbParticipantRole"
+ FROM comms_channel_participants
+ WHERE channel_id = $1
+ ORDER BY joined_at DESC
+ "#,
+ channel_id
+ )
+ .try_map(|row| {
+ Ok(models_comms::channel::ChannelParticipant {
+ channel_id: ChannelId(row.channel_id),
+ user_id: macro_user_id::user_id::MacroUserIdStr::parse_from_str(&row.user_id)
+ .map_err(|e| sqlx::Error::Decode(Box::new(e)))?
+ .into_owned(),
+ role: DbParticipantRole::mirror(row.role),
+ joined_at: row.joined_at,
+ left_at: row.left_at,
+ })
+ })
+ .fetch_all(tsx.as_mut())
+ .await?;
+
+ Ok(participants)
+}
+
#[tracing::instrument(skip(db))]
pub async fn get_participants(
db: &Pool<Postgres>,
diff --git a/rust/cloud-storage/document_cognition_service/src/api/attachments/get_models_for_attachments.rs b/rust/cloud-storage/document_cognition_service/src/api/attachments/get_models_for_attachments.rs
index 1cb0ffdc76..71961e0d86 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/attachments/get_models_for_attachments.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/attachments/get_models_for_attachments.rs
@@ -53,7 +53,6 @@ pub async fn get_models_for_attachments_handler(
if attachment.attachment_type == AttachmentType::Document {
get_users_access_level_v2(
&state.db,
- &state.comms_service_client,
&user_context.user_id,
&attachment.attachment_id,
"document",
@@ -67,7 +66,6 @@ pub async fn get_models_for_attachments_handler(
} else if attachment.attachment_type == AttachmentType::Channel {
get_users_access_level_v2(
&state.db,
- &state.comms_service_client,
&user_context.user_id,
&attachment.attachment_id,
"channel",
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 ba6bfc20e2..86f5293a33 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
@@ -48,7 +48,6 @@ pub(in crate::api) async fn create_chat_handler(
if attachment.attachment_type == AttachmentType::Document {
get_users_access_level_v2(
&state.db,
- &state.comms_service_client,
user_context.macro_user_id.as_ref(),
&attachment.attachment_id,
"document",
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 e3651bdee8..4b88c39cd9 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
@@ -153,7 +153,6 @@ async fn patch_chat_transaction(
if let Some(share_permission) = share_permission {
update_user_item_access(
&mut transaction,
- &ctx.comms_service_client,
&user_context.user_id,
chat_id,
"chat",
diff --git a/rust/cloud-storage/document_cognition_service/src/api/ws/attachment_permissions.rs b/rust/cloud-storage/document_cognition_service/src/api/ws/attachment_permissions.rs
index 01e095982d..7447325976 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/ws/attachment_permissions.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/ws/attachment_permissions.rs
@@ -18,7 +18,6 @@ pub async fn ensure_user_attachment_access(
async move {
get_users_access_level_v2(
&ctx.db,
- &ctx.comms_service_client,
&user_ctx.user_id,
attachment_id.as_str(),
&attachment_type
diff --git a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_permissions.rs b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_permissions.rs
index 6d29ade7ed..14d7250473 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/ws/chat_permissions.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/ws/chat_permissions.rs
@@ -20,30 +20,24 @@ pub async fn chat_access(
chat_id: &str,
stream_id: String,
) -> Result<AccessLevel, WebSocketError> {
- get_users_access_level_v2(
- &ctx.db,
- &ctx.comms_service_client,
- &user_ctx.user_id,
- chat_id,
- "chat",
- )
- .await
- .map_err(|e| {
- tracing::error!(
- error = ?e,
- "Failed to get user access level"
- );
- WebSocketError::StreamError(StreamError::Unauthorized {
- stream_id: stream_id.clone(),
+ get_users_access_level_v2(&ctx.db, &user_ctx.user_id, chat_id, "chat")
+ .await
+ .map_err(|e| {
+ tracing::error!(
+ error = ?e,
+ "Failed to get user access level"
+ );
+ WebSocketError::StreamError(StreamError::Unauthorized {
+ stream_id: stream_id.clone(),
+ })
+ })
+ .and_then(|access| match access {
+ Some(access) => Ok(access),
+ None => {
+ tracing::error!("User has no access to chat");
+ Err(WebSocketError::StreamError(StreamError::Unauthorized {
+ stream_id,
+ }))
+ }
})
- })
- .and_then(|access| match access {
- Some(access) => Ok(access),
- None => {
- tracing::error!("User has no access to chat");
- Err(WebSocketError::StreamError(StreamError::Unauthorized {
- stream_id,
- }))
- }
- })
}
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index 0c28487de8..347f73797a 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -46,7 +46,6 @@ chrono = { workspace = true }
clap = { workspace = true }
cloudfront_sign = { workspace = true }
comms = { path = "../comms", features = ["outbound"] }
-comms_service_client = { path = "../comms_service_client" }
connection_gateway = { path = "../connection_gateway" }
document_sub_type = { path = "../document_sub_type" }
dynamodb_client = { path = "../dynamodb_client" }
@@ -121,6 +120,7 @@ utoipa = { workspace = true, features = ["axum_extras"] }
utoipa-swagger-ui = { workspace = true, features = ["axum"] }
uuid = { workspace = true }
zip = { workspace = true }
+comms_db_client = { path = "../comms_db_client" }
[dev-dependencies]
cool_asserts = "2"
@@ -128,4 +128,4 @@ frecency = { path = "../frecency", features = ["mock"] }
ordered-float = { workspace = true }
[package.metadata.cargo-machete]
-ignored = ["comms_service", "connection_gateway"]
+ignored = ["connection_gateway"]
diff --git a/rust/cloud-storage/document_storage_service/src/api/channel/update_channel_share_permission.rs b/rust/cloud-storage/document_storage_service/src/api/channel/update_channel_share_permission.rs
index 3c1dfe60df..0ba1d819a5 100644
--- a/rust/cloud-storage/document_storage_service/src/api/channel/update_channel_share_permission.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/channel/update_channel_share_permission.rs
@@ -47,7 +47,6 @@ pub async fn handler(
// Get users max access level to the item
let user_access_level = get_users_access_level_v2(
&ctx.db,
- &ctx.comms_service_client,
req.user_id.0.as_ref(),
&req.item_id,
&req.item_type,
@@ -130,9 +129,7 @@ pub async fn handler(
.into_response()
})?;
- let channel_participants = ctx
- .comms_service_client
- .get_channel_participants(&req.channel_id)
+ let channel_participants = comms_db_client::participants::get_participants::get_participants(&ctx.db, &channel_id)
.await
.map_err(|e| {
tracing::error!(error=?e, "failed to get channel participants");
diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rs
index 960e16a1a1..ac3d332590 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -52,7 +52,6 @@ pub(crate) struct ApiContext {
pub soup_router_state: DssSoupState,
pub sqs_client: Arc<sqs_client::SQS>,
pub macro_notify_client: Arc<macro_notify::MacroNotify>,
- pub comms_service_client: Arc<comms_service_client::CommsServiceClient>,
pub conn_gateway_client: Arc<ConnectionGatewayClient>,
pub sync_service_client: Arc<SyncServiceClient>,
pub system_properties_service: Arc<SystemPropertiesService>,
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/delete_document.rs b/rust/cloud-storage/document_storage_service/src/api/documents/delete_document.rs
index 0d54364cdc..7d4738948a 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/delete_document.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/delete_document.rs
@@ -177,10 +177,11 @@ pub async fn permanently_delete_document_handler(
})?;
// Delete entity mentions where this doc is the source
- if let Err(e) = state
- .comms_service_client
- .delete_mentions_by_source(vec![document_id.clone()])
- .await
+ if let Err(e) = comms_db_client::entity_mentions::delete_entity_mentions_by_source(
+ &state.db,
+ vec![document_id.clone()],
+ )
+ .await
{
tracing::error!(error=?e, "unable to delete entity mentions");
}
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 46c899c54f..229ee83fc5 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
@@ -119,7 +119,6 @@ async fn edit_document_transaction(
if let Some(share_permission) = share_permission {
update_user_item_access(
&mut transaction,
- &ctx.comms_service_client,
&user_context.user_id,
&document_context.document_id,
"document",
diff --git a/rust/cloud-storage/document_storage_service/src/api/documents/get_document_access_level.rs b/rust/cloud-storage/document_storage_service/src/api/documents/get_document_access_level.rs
index 721e41093e..7f454228ec 100644
--- a/rust/cloud-storage/document_storage_service/src/api/documents/get_document_access_level.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/documents/get_document_access_level.rs
@@ -37,7 +37,6 @@ pub async fn handler(
let user_access_level: Option<AccessLevel> =
match macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(
&ctx.db,
- &ctx.comms_service_client,
&user_context.user_id,
&document_id,
"document",
diff --git a/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs b/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
index 20c36e1ce3..c02362527d 100644
--- a/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/projects/edit_project.rs
@@ -224,7 +224,6 @@ async fn patch_project_transaction(
if let Some(share_permission) = share_permission {
update_user_item_access(
&mut transaction,
- &ctx.comms_service_client,
&user_context.user_id,
&project_context.id,
"project",
diff --git a/rust/cloud-storage/document_storage_service/src/api/projects/project_permission.rs b/rust/cloud-storage/document_storage_service/src/api/projects/project_permission.rs
index 93f5c24b63..4363f76e40 100644
--- a/rust/cloud-storage/document_storage_service/src/api/projects/project_permission.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/projects/project_permission.rs
@@ -92,7 +92,6 @@ pub async fn get_project_access_level_handler(
let user_access_level: Option<AccessLevel> =
match macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(
&ctx.db,
- &ctx.comms_service_client,
&user_context.user_id,
&id,
"project",
diff --git a/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs b/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
index 618bcb8469..06a1d78bcf 100644
--- a/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/threads/edit_thread.rs
@@ -100,7 +100,6 @@ pub async fn edit_thread_handler(
update_user_item_access(
&mut tx,
- &ctx.comms_service_client,
&user_context.user_id,
&thread_id,
"thread",
diff --git a/rust/cloud-storage/document_storage_service/src/api/threads/get_thread_access_level.rs b/rust/cloud-storage/document_storage_service/src/api/threads/get_thread_access_level.rs
index 38e5851a66..709eb2861c 100644
--- a/rust/cloud-storage/document_storage_service/src/api/threads/get_thread_access_level.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/threads/get_thread_access_level.rs
@@ -21,7 +21,6 @@ pub async fn handler(
let user_access_level: Option<AccessLevel> =
match macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(
&ctx.db,
- &ctx.comms_service_client,
&user_context.user_id,
&thread_id,
"thread",
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs
index 4567beda0c..2d8391733a 100644
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs
+++ b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/chat.rs
@@ -1,7 +1,6 @@
use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
use anyhow::Context;
use chrono::Utc;
-use comms_service_client::CommsServiceClient;
use futures::future::join_all;
use models_permissions::share_permission::access_level::AccessLevel;
use models_permissions::user_item_access::UserItemAccess;
@@ -9,7 +8,6 @@ use sqlx::PgPool;
async fn process_single_chat(
db: PgPool,
- comms_service_client: CommsServiceClient,
chat_id: String,
user_id: String,
) -> anyhow::Result<Vec<UserItemAccess>> {
@@ -37,12 +35,12 @@ async fn process_single_chat(
let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
.with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
- let participants = comms_service_client
- .get_channel_participants(&csp.channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
+ let participants =
+ comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
+ .await
+ .with_context(|| {
+ format!("Failed to get participants for channel {}", csp.channel_id)
+ })?;
// Add an access record for each participant
for participant in participants {
@@ -65,11 +63,7 @@ async fn process_single_chat(
}
/// Backfills UserItemAccess records for chats with concurrent processing.
-pub async fn backfill_chats_updated(
- db: &PgPool,
- comms_service_client: &CommsServiceClient,
- start_offset: Option<i64>,
-) -> anyhow::Result<()> {
+pub async fn backfill_chats_updated(db: &PgPool, start_offset: Option<i64>) -> anyhow::Result<()> {
let mut offset = start_offset.unwrap_or(0);
if let Some(so) = start_offset {
@@ -113,13 +107,11 @@ pub async fn backfill_chats_updated(
// Clone the resources needed for the concurrent task.
// Cloning PgPool and the client should be cheap.
let db_clone = db.clone();
- let client_clone = comms_service_client.clone();
let chat_id_clone = chat_id.clone();
let user_id_clone = user_id.clone();
tasks.push(tokio::spawn(process_single_chat(
db_clone,
- client_clone,
chat_id_clone,
user_id_clone,
)));
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs
index 263801ce4d..4fafededd2 100644
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs
+++ b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/document.rs
@@ -1,7 +1,6 @@
use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
use anyhow::Context;
use chrono::Utc;
-use comms_service_client::CommsServiceClient;
use futures::future::join_all;
use model::document::DocumentMetadata;
use models_permissions::share_permission::access_level::AccessLevel;
@@ -11,7 +10,6 @@ use sqlx::PgPool;
/// Processes a single document to generate its corresponding UserItemAccess records.
async fn process_single_document(
db: PgPool,
- comms_service_client: CommsServiceClient,
document: DocumentMetadata, // Assuming DocumentMetadata implements Clone
) -> anyhow::Result<Vec<UserItemAccess>> {
let mut generated_items = Vec::new();
@@ -46,12 +44,12 @@ async fn process_single_document(
let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
.with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
- let participants = comms_service_client
- .get_channel_participants(&csp.channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
+ let participants =
+ comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
+ .await
+ .with_context(|| {
+ format!("Failed to get participants for channel {}", csp.channel_id)
+ })?;
for participant in participants {
if participant.user_id != user_id {
@@ -75,7 +73,6 @@ async fn process_single_document(
/// Backfills UserItemAccess records for documents with concurrent processing.
pub async fn backfill_documents_updated(
db: &PgPool,
- comms_service_client: &CommsServiceClient,
start_offset: Option<i64>,
) -> anyhow::Result<()> {
let mut offset = start_offset.unwrap_or(0);
@@ -120,13 +117,11 @@ pub async fn backfill_documents_updated(
let mut tasks = Vec::new();
for document in chunk {
let db_clone = db.clone();
- let client_clone = comms_service_client.clone();
// Assumes DocumentMetadata implements Clone. If not, add `#[derive(Clone)]`.
let document_clone = document.clone();
tasks.push(tokio::spawn(process_single_document(
db_clone,
- client_clone,
document_clone,
)));
}
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs
index 90b1728217..af58809849 100644
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/mod.rs
@@ -1,13 +1,11 @@
//! backfill_useritemaccess.rs is used to trigger a backfill for the UserItemAccess table
//! - DATABASE_URL
//! - DOCUMENT_STORAGE_SERVICE_AUTH_KEY
-//! - COMMS_SERVICE_URL
mod chat;
mod document;
mod project;
use anyhow::Context;
-use comms_service_client::CommsServiceClient;
use macro_entrypoint::MacroEntrypoint;
use sqlx::postgres::PgPoolOptions;
@@ -57,10 +55,6 @@ async fn main() -> anyhow::Result<()> {
println!("Starting backfill_useritemaccess script");
let database_url = std::env::var("DATABASE_URL").context("DATABASE_URL not set")?;
- let comms_internal_key = std::env::var("DOCUMENT_STORAGE_SERVICE_AUTH_KEY")
- .context("DOCUMENT_STORAGE_SERVICE_AUTH_KEY not set")?;
- let comms_service_url =
- std::env::var("COMMS_SERVICE_URL").context("COMMS_SERVICE_URL not set")?;
let db = PgPoolOptions::new()
.min_connections(10)
@@ -69,27 +63,25 @@ async fn main() -> anyhow::Result<()> {
.await
.context("could not connect to db")?;
- let comms_service_client = CommsServiceClient::new(comms_internal_key, comms_service_url);
-
// --- Backfill Logic Controlled by Environment Variables ---
if is_backfill_enabled("BACKFILL_CHATS") {
let offset = get_offset("CHAT_OFFSET");
- chat::backfill_chats_updated(&db, &comms_service_client, offset).await?;
+ chat::backfill_chats_updated(&db, offset).await?;
} else {
println!("Skipping chat backfill: BACKFILL_CHATS is not set to 'true'.");
}
if is_backfill_enabled("BACKFILL_DOCUMENTS") {
let offset = get_offset("DOCS_OFFSET");
- document::backfill_documents_updated(&db, &comms_service_client, offset).await?;
+ document::backfill_documents_updated(&db, offset).await?;
} else {
println!("Skipping document backfill: BACKFILL_DOCUMENTS is not set to 'true'.");
}
if is_backfill_enabled("BACKFILL_PROJECTS") {
let offset = get_offset("PROJECTS_OFFSET");
- project::backfill_projects_updated(&db, &comms_service_client, offset).await?;
+ project::backfill_projects_updated(&db, offset).await?;
} else {
println!("Skipping project backfill: BACKFILL_PROJECTS is not set to 'true'.");
}
diff --git a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs
index 2c958c9655..a0d5a39fe4 100644
--- a/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs
+++ b/rust/cloud-storage/document_storage_service/src/bin/backfill_useritemaccess/project.rs
@@ -1,7 +1,6 @@
use crate::{CONCURRENT_PROCESSING_LIMIT, DB_FETCH_SIZE, INSERT_BATCH_SIZE};
use anyhow::Context;
use chrono::Utc;
-use comms_service_client::CommsServiceClient;
use futures::future::join_all;
use models_permissions::share_permission::access_level::AccessLevel;
use models_permissions::user_item_access::UserItemAccess;
@@ -9,7 +8,6 @@ use sqlx::PgPool;
pub async fn process_single_project(
db: PgPool,
- comms_service_client: CommsServiceClient,
project_id: String,
user_id: String,
) -> anyhow::Result<Vec<UserItemAccess>> {
@@ -37,12 +35,12 @@ pub async fn process_single_project(
let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
.with_context(|| format!("Failed to parse channel UUID: {}", csp.channel_id))?;
- let participants = comms_service_client
- .get_channel_participants(&csp.channel_id)
- .await
- .with_context(|| {
- format!("Failed to get participants for channel {}", csp.channel_id)
- })?;
+ let participants =
+ comms_db_client::participants::get_participants::get_participants(&db, &channel_id)
+ .await
+ .with_context(|| {
+ format!("Failed to get participants for channel {}", csp.channel_id)
+ })?;
for participant in participants {
if participant.user_id.as_ref() != user_id {
@@ -66,7 +64,6 @@ pub async fn process_single_project(
/// Backfills UserItemAccess records for projects with concurrent processing.
pub async fn backfill_projects_updated(
db: &PgPool,
- comms_service_client: &CommsServiceClient,
start_offset: Option<i64>,
) -> anyhow::Result<()> {
let mut offset = start_offset.unwrap_or(0);
@@ -110,13 +107,11 @@ pub async fn backfill_projects_updated(
let mut tasks = Vec::new();
for (project_id, user_id) in chunk {
let db_clone = db.clone();
- let client_clone = comms_service_client.clone();
let project_id_clone = project_id.clone();
let user_id_clone = user_id.clone();
tasks.push(tokio::spawn(process_single_project(
db_clone,
- client_clone,
project_id_clone,
user_id_clone,
)));
diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rs
index 67ac614fe3..9585bed235 100644
--- a/rust/cloud-storage/document_storage_service/src/config.rs
+++ b/rust/cloud-storage/document_storage_service/src/config.rs
@@ -41,7 +41,6 @@ env_var! {
pub RedisUri,
pub NotificationQueue,
pub SearchEventQueue,
- pub CommsServiceUrl,
pub ConnectionGatewayUrl,
pub BulkUploadRequestsTable,
pub UploadStagingBucket,
diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rs
index d36bdf9a41..7f406b2068 100644
--- a/rust/cloud-storage/document_storage_service/src/main.rs
+++ b/rust/cloud-storage/document_storage_service/src/main.rs
@@ -8,7 +8,6 @@ use comms::{
domain::service::ChannelServiceImpl,
outbound::{http::user_repo::UserRepoImpl, postgres::comms_repo::PgCommsRepo},
};
-use comms_service_client::CommsServiceClient;
use config::{Config, Environment};
use connection_gateway_client::client::ConnectionGatewayClient;
use dynamodb_client::DynamodbClient;
@@ -155,11 +154,6 @@ async fn main() -> anyhow::Result<()> {
let dss_auth_key = DocumentStorageServiceAuthKey::new()?;
- let comms_service_client = CommsServiceClient::new(
- dss_auth_key.as_ref().to_string(),
- config.vars.comms_service_url.as_ref().to_string(),
- );
-
let conn_gateway_client = ConnectionGatewayClient::new(
internal_api_secret.as_ref().to_string(),
config.vars.connection_gateway_url.as_ref().to_string(),
@@ -201,13 +195,7 @@ async fn main() -> anyhow::Result<()> {
EmailServiceImpl::new(EmailPgRepo::new(db.clone()), frecency_service.clone());
let system_properties_service =
SystemPropertiesServiceImpl::new(PgSystemPropertiesRepository::new(db.clone()));
- let permission_checker = PermissionServiceImpl::new(
- db.clone(),
- CommsServiceClient::new(
- dss_auth_key.as_ref().to_string(),
- config.vars.comms_service_url.as_ref().to_string(),
- ),
- );
+ let permission_checker = PermissionServiceImpl::new(db.clone());
let notification_service = NotificationServiceImpl::new(Arc::new(macro_notify_client.clone()));
let properties_service = PropertiesServiceImpl::new(
PropertiesPgRepo::new(db.clone()),
@@ -248,7 +236,6 @@ async fn main() -> anyhow::Result<()> {
dynamo_db,
sqs_client: Arc::new(sqs_client),
macro_notify_client: Arc::new(macro_notify_client),
- comms_service_client: Arc::new(comms_service_client),
conn_gateway_client: Arc::new(conn_gateway_client),
sync_service_client: Arc::new(sync_service_client),
system_properties_service: Arc::new(system_properties_service),
diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json
new file mode 100644
index 0000000000..8844ec6411
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT c.id\n FROM comms_channels c\n INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id \n WHERE cp.user_id = $1 AND cp.left_at IS NULL\n AND c.id = ANY($2::uuid[])\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "b288dfc8e7703bdfb49bc1066c290743da8653dc50e3d388697e429308afeafa"
+}
diff --git a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
index 9d9cabb5b0..818e5a4c03 100644
--- a/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
+++ b/rust/cloud-storage/macro_db_client/src/share_permission/get.rs
@@ -379,6 +379,31 @@ pub async fn get_macro_id_from_thread_id(
Ok(macro_id)
}
+/// COPIED FROM COMMS_DB_CLIENT and is needed in the `get_users_access_level_v2`
+/// in macro_middleware
+pub async fn check_channels_for_user(
+ db: &sqlx::Pool<sqlx::Postgres>,
+ user_id: &str,
+ channel_ids: &[uuid::Uuid],
+) -> Result<Vec<uuid::Uuid>, sqlx::Error> {
+ let channels = sqlx::query!(
+ r#"
+ SELECT c.id
+ FROM comms_channels c
+ INNER JOIN comms_channel_participants cp ON cp.channel_id = c.id
+ WHERE cp.user_id = $1 AND cp.left_at IS NULL
+ AND c.id = ANY($2::uuid[])
+ "#,
+ user_id,
+ channel_ids
+ )
+ .map(|row| row.id)
+ .fetch_all(db)
+ .await?;
+
+ Ok(channels)
+}
+
/// Retrieves all document, chat, and project IDs associated with the given share permission IDs
/// Returns a map where the key is the share_permission_id, and the value is a tuple containing the
/// item id and type
diff --git a/rust/cloud-storage/macro_middleware/Cargo.toml b/rust/cloud-storage/macro_middleware/Cargo.toml
index 5e42dfa873..3ba760b0a6 100644
--- a/rust/cloud-storage/macro_middleware/Cargo.toml
+++ b/rust/cloud-storage/macro_middleware/Cargo.toml
@@ -8,7 +8,6 @@ version = "0.1.0"
all = ["auth", "cloud_storage", "tracking", "user_permissions"]
auth = ["dep:macro_auth", "dep:url"]
cloud_storage = [
- "dep:comms_service_client",
"dep:macro_share_permissions",
"dep:permission",
"macro_db_client",
@@ -22,7 +21,6 @@ user_permissions = ["dep:macro_user_id", "dep:user_quota", "macro_db_client"]
[dependencies]
anyhow = { workspace = true }
axum = { workspace = true, features = ["macros"] }
-comms_service_client = { path = "../comms_service_client", optional = true }
http-body-util = { workspace = true }
macro_auth = { path = "../macro_auth", optional = true }
macro_db_client = { path = "../macro_db_client", optional = true }
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/chat.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/chat.rs
index 6f9474d6dd..be8cc6f1b4 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/chat.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/chat.rs
@@ -1,4 +1,4 @@
-use std::{marker::PhantomData, sync::Arc};
+use std::marker::PhantomData;
use super::get_users_access_level_v2;
use crate::cloud_storage::ensure_access::{AccessLevelErr, BuildAccessLevel};
@@ -7,7 +7,6 @@ use axum::{
extract::{FromRef, FromRequestParts},
http::request::Parts,
};
-use comms_service_client::CommsServiceClient;
use model::{chat::ChatBasic, user::axum_extractor::MacroUserExtractor};
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::PgPool;
@@ -25,7 +24,6 @@ impl<T, S> FromRequestParts<S> for ChatAccessLevelExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
@@ -33,7 +31,6 @@ where
#[tracing::instrument(ret, err, skip(parts, state))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let MacroUserExtractor {
macro_user_id,
@@ -61,15 +58,10 @@ where
return Err(AccessLevelErr::UnAuthorized);
}
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- &chat_context.id,
- "chat",
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, &chat_context.id, "chat")
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired = T::into_access_level();
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs
index a8065eb104..f270248b86 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/document.rs
@@ -1,11 +1,10 @@
-use std::{marker::PhantomData, sync::Arc};
+use std::marker::PhantomData;
use axum::{
Extension, RequestPartsExt, async_trait,
extract::{FromRef, FromRequestParts},
http::request::Parts,
};
-use comms_service_client::CommsServiceClient;
use sqlx::PgPool;
use super::get_users_access_level_v2;
@@ -24,7 +23,6 @@ impl<T, S> FromRequestParts<S> for DocumentAccessExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
@@ -32,7 +30,6 @@ where
#[tracing::instrument(ret, err, skip(state, parts))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let MacroUserExtractor {
macro_user_id,
@@ -63,7 +60,6 @@ where
let access_level: Option<AccessLevel> = get_users_access_level_v2(
&db,
- &comms_client,
&user_context.user_id,
&document_context.document_id,
"document",
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/history.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/history.rs
index 8c365d1875..d2a09eba2d 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/history.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/history.rs
@@ -1,5 +1,4 @@
use std::marker::PhantomData;
-use std::sync::Arc;
use crate::cloud_storage::ensure_access::{
AccessLevelErr, BuildAccessLevel, get_users_access_level_v2,
@@ -11,7 +10,6 @@ use axum::{
Extension,
extract::{FromRequestParts, Path},
};
-use comms_service_client::CommsServiceClient;
use model::user::UserContext;
use models_permissions::share_permission::access_level::AccessLevel;
use sqlx::PgPool;
@@ -33,14 +31,12 @@ impl<T, S> FromRequestParts<S> for HistoryAccessExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let user_context: Extension<UserContext> =
<Extension<UserContext>>::from_request_parts(parts, state)
.await
@@ -49,15 +45,10 @@ where
.await
.map_err(|_| AccessLevelErr::BadRequest)?;
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- &item_id,
- &item_type,
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, &item_id, &item_type)
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired = T::into_access_level();
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/macros.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/macros.rs
index 55e2ed55c3..7c3f4be11b 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/macros.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/macros.rs
@@ -5,12 +5,11 @@ use axum::{
extract::{FromRef, FromRequestParts, Path},
http::request::Parts,
};
-use comms_service_client::CommsServiceClient;
use model::user::UserContext;
use models_permissions::share_permission::access_level::AccessLevel;
use serde::Deserialize;
use sqlx::PgPool;
-use std::{marker::PhantomData, sync::Arc};
+use std::marker::PhantomData;
#[derive(Deserialize)]
pub struct Params {
@@ -32,7 +31,6 @@ impl<T, S> FromRequestParts<S> for MacrosAccessLevelExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
@@ -40,7 +38,6 @@ where
#[tracing::instrument(ret, err, skip(parts, state))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let Extension(user_context) = <Extension<UserContext>>::from_request_parts(parts, state)
.await
.map_err(|_| AccessLevelErr::UnAuthorized)?;
@@ -48,15 +45,10 @@ where
.await
.map_err(|_| AccessLevelErr::BadRequest)?;
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- &macro_prompt_id,
- "macro",
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, &macro_prompt_id, "macro")
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired_level = T::into_access_level();
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/mod.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/mod.rs
index d95cf0d76d..ad9d180de9 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/mod.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/mod.rs
@@ -8,11 +8,10 @@ pub mod thread;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
+use models_permissions::share_permission::access_level::ViewAccessLevel;
use models_permissions::share_permission::access_level::{
AccessLevel, CommentAccessLevel, EditAccessLevel, OwnerAccessLevel,
};
-use models_permissions::share_permission::channel_share_permission::ChannelSharePermission;
-use models_permissions::share_permission::{SharePermissionV2, access_level::ViewAccessLevel};
use std::str::FromStr;
use std::time::Instant;
use thiserror::Error;
@@ -85,10 +84,9 @@ impl IntoResponse for AccessLevelErr {
/// Gets the users AccessLevel for a given item
/// This is for the new permission system
-#[tracing::instrument(skip(db, comms_service_client))]
+#[tracing::instrument(skip(db))]
pub async fn get_users_access_level_v2(
db: &Pool<Postgres>,
- comms_service_client: &comms_service_client::CommsServiceClient,
user_id: &str,
item_id: &str,
item_type: &str,
@@ -98,31 +96,26 @@ pub async fn get_users_access_level_v2(
return get_highest_access_level(db, user_id, item_id, item_type).await;
}
- let start_time = Instant::now();
- let share_permissions: Vec<SharePermissionV2> = match item_type {
- "macro" => {
- let share_permission =
- macro_db_client::share_permission::get::get_macro_share_permission(db, item_id)
- .await
- .map_err(|_e| {
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get macro share permission".to_string(),
- )
- })?;
-
- Ok(vec![share_permission])
- }
+ // We need to simply check if the user is part of the channel
+ match item_type {
"channel" => {
let channel_id = Uuid::from_str(item_id)
.map_err(|_| (StatusCode::BAD_REQUEST, "invalid channel id".to_string()))?;
- let user_channels = comms_service_client
- .check_channels_for_user(user_id, &[channel_id])
- .await
- .map_err(|err| {
- tracing::error!(error=?err, "internal server error checking channel membership");
- (StatusCode::INTERNAL_SERVER_ERROR, "internal server error".to_string())
- })?;
+
+ let user_channels = macro_db_client::share_permission::get::check_channels_for_user(
+ db,
+ user_id,
+ &[channel_id],
+ )
+ .await
+ .map_err(|err| {
+ tracing::error!(error=?err, "internal server error checking channel membership");
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ "internal server error".to_string(),
+ )
+ })?;
+
if !user_channels.contains(&channel_id) {
return Err((StatusCode::UNAUTHORIZED, "permission".to_string()));
}
@@ -135,100 +128,6 @@ pub async fn get_users_access_level_v2(
));
}
}
- .map_err(|e: (StatusCode, String)| {
- tracing::error!(error=?e, "failed to get user permission");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get user permission".to_string(),
- )
- })?;
-
- // Check if the user is an owner in any of the share permissions
- let is_owner = share_permissions
- .iter()
- .any(|share_permission| share_permission.owner == user_id);
-
- if is_owner {
- tracing::trace!("user is owner of a share permission");
- return Ok(Some(AccessLevel::Owner));
- }
-
- // Get all public share permission access levels
- let mut access_levels: Vec<AccessLevel> = share_permissions
- .iter()
- .filter_map(|share_permission| {
- if share_permission.is_public {
- Some(
- share_permission
- .public_access_level
- .unwrap_or(AccessLevel::View),
- )
- } else {
- None
- }
- })
- .collect();
-
- // Get all channel share permissions and get user's highest access level from it if it exists
- let channel_share_permissions: Vec<ChannelSharePermission> = share_permissions
- .into_iter()
- .flat_map(|share_permission| {
- share_permission
- .channel_share_permissions
- .unwrap_or_default()
- })
- .collect();
-
- // Add the highest access level from the channel if it exists
- if !channel_share_permissions.is_empty() {
- tracing::trace!("channel share permissions exist");
- let channel_ids: Vec<Uuid> = channel_share_permissions
- .iter()
- .filter_map(|channel_share_permission| {
- Uuid::from_str(channel_share_permission.channel_id.as_str()).ok()
- })
- .collect();
-
- let user_channels = comms_service_client
- .check_channels_for_user(user_id, &channel_ids)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get user channels");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- "failed to get user channels".to_string(),
- )
- })?;
-
- tracing::trace!("user has channels");
- let user_channels: Vec<String> = user_channels
- .iter()
- .map(|channel| channel.to_string())
- .collect();
-
- let user_access_levels: Vec<AccessLevel> = channel_share_permissions
- .iter()
- .filter_map(|channel_share_permission| {
- if user_channels.contains(&channel_share_permission.channel_id.to_string()) {
- Some(channel_share_permission.access_level)
- } else {
- None
- }
- })
- .collect();
-
- access_levels.extend(user_access_levels);
- }
-
- tracing::trace!(elapsed_time = ?start_time.elapsed(), "get_users_access_level_v2 took");
-
- if access_levels.is_empty() {
- Ok(None)
- } else {
- // Sort access levels from lowest to highest
- access_levels.sort();
- Ok(Some(*access_levels.last().unwrap()))
- }
}
/// Gets the users AccessLevel for a given item using UserItemAccess and SharePermissions
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/pin.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/pin.rs
index f4a7db9847..98aa3c72e1 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/pin.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/pin.rs
@@ -1,5 +1,4 @@
use std::marker::PhantomData;
-use std::sync::Arc;
use crate::cloud_storage::ensure_access::{
AccessLevelErr, BuildAccessLevel, get_users_access_level_v2,
@@ -10,7 +9,6 @@ use axum::{
extract::{FromRequest, Path, Request},
};
use axum::{Json, RequestExt};
-use comms_service_client::CommsServiceClient;
use model::user::UserContext;
use models_permissions::share_permission::access_level::AccessLevel;
use serde::de::DeserializeOwned;
@@ -43,7 +41,6 @@ impl<T, S, V> FromRequest<S> for PinAccessLevelExtractor<T, V>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
V: DeserializeOwned + std::fmt::Debug,
S: Send + Sync + 'static,
{
@@ -52,7 +49,6 @@ where
#[tracing::instrument(ret, err, skip(req, state))]
async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let user_context: Extension<UserContext> = req
.extract_parts()
@@ -74,15 +70,10 @@ where
let JsonBodyWithPinType { pin_type } =
serde_json::from_value(json).map_err(|_| AccessLevelErr::BadRequest)?;
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- &pinned_item_id,
- &pin_type,
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, &pinned_item_id, &pin_type)
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired = T::into_access_level();
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/project.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/project.rs
index 9980665a73..d7ad781be9 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/project.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/project.rs
@@ -5,7 +5,6 @@ use axum::{
extract::{FromRef, FromRequest, FromRequestParts, Request},
http::request::Parts,
};
-use comms_service_client::CommsServiceClient;
use model::{
project::BasicProject,
user::{UserContext, axum_extractor::MacroUserExtractor},
@@ -13,7 +12,7 @@ use model::{
use models_permissions::share_permission::access_level::AccessLevel;
use serde::{Deserialize, de::DeserializeOwned};
use sqlx::PgPool;
-use std::{marker::PhantomData, sync::Arc};
+use std::marker::PhantomData;
/// Validates the user has the desired access level to the item
#[derive(Debug)]
@@ -27,7 +26,6 @@ impl<T, S> FromRequestParts<S> for ProjectAccessLevelExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
@@ -35,7 +33,6 @@ where
#[tracing::instrument(ret, err, skip(parts, state))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let MacroUserExtractor {
macro_user_id,
@@ -65,15 +62,10 @@ where
));
}
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- &project_context.id,
- "project",
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, &project_context.id, "project")
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired = T::into_access_level();
@@ -146,7 +138,6 @@ impl<T, S, V> FromRequest<S> for ProjectBodyAccessLevelExtractor<T, V>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
V: DeserializeOwned,
{
@@ -154,7 +145,6 @@ where
async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let user_context: Extension<UserContext> = req
.extract_parts()
@@ -174,15 +164,10 @@ where
return Ok(Self::ProjectNotInBody { body: cb()? });
};
- let access_level: Option<AccessLevel> = get_users_access_level_v2(
- &db,
- &comms_client,
- &user_context.user_id,
- project.id(),
- "project",
- )
- .await
- .map_err(AccessLevelErr::DbErr)?;
+ let access_level: Option<AccessLevel> =
+ get_users_access_level_v2(&db, &user_context.user_id, project.id(), "project")
+ .await
+ .map_err(AccessLevelErr::DbErr)?;
let desired = T::into_access_level();
diff --git a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/thread.rs b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/thread.rs
index 7671a063ad..93142e8973 100644
--- a/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/thread.rs
+++ b/rust/cloud-storage/macro_middleware/src/cloud_storage/ensure_access/thread.rs
@@ -1,4 +1,4 @@
-use std::{marker::PhantomData, sync::Arc};
+use std::marker::PhantomData;
use super::get_users_access_level_v2;
use crate::cloud_storage::ensure_access::{AccessLevelErr, BuildAccessLevel};
@@ -7,7 +7,6 @@ use axum::{
extract::{FromRef, FromRequestParts},
http::request::Parts,
};
-use comms_service_client::CommsServiceClient;
use model::thread::EmailThreadPermission;
use model::user::UserContext;
use models_permissions::share_permission::access_level::AccessLevel;
@@ -25,7 +24,6 @@ impl<T, S> FromRequestParts<S> for ThreadAccessLevelExtractor<T>
where
T: BuildAccessLevel,
PgPool: FromRef<S>,
- Arc<CommsServiceClient>: FromRef<S>,
S: Send + Sync + 'static,
{
type Rejection = AccessLevelErr;
@@ -33,7 +31,6 @@ where
#[tracing::instrument(ret, err, skip(parts, state))]
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let db = PgPool::from_ref(state);
- let comms_client = <Arc<CommsServiceClient>>::from_ref(state);
let user_context: Extension<UserContext> = parts
.extract()
@@ -47,7 +44,6 @@ where
let access_level: Option<AccessLevel> = get_users_access_level_v2(
&db,
- &comms_client,
&user_context.user_id,
&thread_context.thread_id,
"thread",
diff --git a/rust/cloud-storage/macro_share_permissions/Cargo.toml b/rust/cloud-storage/macro_share_permissions/Cargo.toml
index 84a95d599f..e700311112 100644
--- a/rust/cloud-storage/macro_share_permissions/Cargo.toml
+++ b/rust/cloud-storage/macro_share_permissions/Cargo.toml
@@ -9,6 +9,7 @@ version = "0.1.0"
anyhow = { workspace = true }
comms_service_client = { path = "../comms_service_client" }
macro_db_client = { path = "../macro_db_client" }
+comms_db_client = { path = "../comms_db_client" }
macro_user_id = { path = "../macro_user_id" }
model = { path = "../model" }
model-entity = { path = "../model-entity" }
diff --git a/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs b/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs
index f2e377dcfc..fbb509521a 100644
--- a/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs
+++ b/rust/cloud-storage/macro_share_permissions/src/user_item_access.rs
@@ -1,5 +1,4 @@
use anyhow::Context;
-use comms_service_client::CommsServiceClient;
use models_permissions::share_permission::UpdateSharePermissionRequestV2;
use models_permissions::share_permission::access_level::AccessLevel;
use models_permissions::share_permission::channel_share_permission::UpdateOperation;
@@ -10,10 +9,9 @@ use sqlx::types::uuid;
///
/// This function handles the logic for adding/removing user access items based on
/// channel share permissions in the UpdateSharePermissionRequestV2
-#[tracing::instrument(skip(transaction, comms_service_client))]
+#[tracing::instrument(skip(transaction))]
pub async fn update_user_item_access<'t>(
transaction: &mut sqlx::Transaction<'t, Postgres>,
- comms_service_client: &CommsServiceClient,
user_id: &str,
item_id: &str,
item_type: &str,
@@ -24,8 +22,11 @@ pub async fn update_user_item_access<'t>(
let channel_id = uuid::Uuid::parse_str(&csp.channel_id)
.with_context(|| format!("Failed to parse channel_id {}", &csp.channel_id))?;
- let channel_participants = comms_service_client
- .get_channel_participants(&csp.channel_id)
+ let channel_participants =
+ comms_db_client::participants::get_participants::get_participants_tsx(
+ transaction,
+ &channel_id,
+ )
.await
.with_context(|| {
format!(
diff --git a/rust/cloud-storage/properties/Cargo.toml b/rust/cloud-storage/properties/Cargo.toml
index a2ef3a6b9a..8703085556 100644
--- a/rust/cloud-storage/properties/Cargo.toml
+++ b/rust/cloud-storage/properties/Cargo.toml
@@ -6,7 +6,6 @@ version = "0.1.0"
[dependencies]
anyhow = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
futures = { workspace = true }
email_db_client = { path = "../email_db_client" }
macro_db_client = { path = "../macro_db_client" }
diff --git a/rust/cloud-storage/properties/src/outbound/permission_service.rs b/rust/cloud-storage/properties/src/outbound/permission_service.rs
index e5a523ff97..f408c37c8d 100644
--- a/rust/cloud-storage/properties/src/outbound/permission_service.rs
+++ b/rust/cloud-storage/properties/src/outbound/permission_service.rs
@@ -7,21 +7,16 @@ use sqlx::{Pool, Postgres};
use uuid::Uuid;
use crate::domain::ports::PermissionService;
-use comms_service_client::CommsServiceClient;
use email_db_client::threads::get::get_macro_id_from_thread_id;
-/// Permission service implementation using database and comms service client.
+/// Permission service implementation using database.
pub struct PermissionServiceImpl {
db: Pool<Postgres>,
- comms_service_client: CommsServiceClient,
}
impl PermissionServiceImpl {
- pub fn new(db: Pool<Postgres>, comms_service_client: CommsServiceClient) -> Self {
- Self {
- db,
- comms_service_client,
- }
+ pub fn new(db: Pool<Postgres>) -> Self {
+ Self { db }
}
}
@@ -50,11 +45,7 @@ impl PermissionService for PermissionServiceImpl {
let access_level =
macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(
- &self.db,
- &self.comms_service_client,
- user_id,
- entity_id,
- item_type,
+ &self.db, user_id, entity_id, item_type,
)
.await
.map_err(|(status_code, message)| {
diff --git a/rust/cloud-storage/properties_service/src/api/permissions.rs b/rust/cloud-storage/properties_service/src/api/permissions.rs
index 6354ee540f..94c823a9b3 100644
--- a/rust/cloud-storage/properties_service/src/api/permissions.rs
+++ b/rust/cloud-storage/properties_service/src/api/permissions.rs
@@ -85,7 +85,6 @@ async fn get_access_level(
let access_level = macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(
&context.db,
- &context.comms_service_client,
user_id,
&entity_ref.entity_id,
item_type,
diff --git a/rust/cloud-storage/properties_service/src/main.rs b/rust/cloud-storage/properties_service/src/main.rs
index de2034d5e5..5823f8ed46 100644
--- a/rust/cloud-storage/properties_service/src/main.rs
+++ b/rust/cloud-storage/properties_service/src/main.rs
@@ -68,8 +68,7 @@ async fn main() -> anyhow::Result<()> {
// Initialize properties service
let properties_repository = properties::PropertiesPgRepo::new(db.clone());
- let permission_service =
- properties::PermissionServiceImpl::new(db.clone(), comms_service_client.clone());
+ let permission_service = properties::PermissionServiceImpl::new(db.clone());
// Initialize notification service
let notification_queue = std::env::var("NOTIFICATION_QUEUE")