Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
remove dss from comms (#1247)
Will Hutchinson2a756974881e
diff --git a/infra/stacks/comms-service/index.ts b/infra/stacks/comms-service/index.tsindex 2103225fff..6c7d459b56 100644--- a/infra/stacks/comms-service/index.ts+++ b/infra/stacks/comms-service/index.ts@@ -179,10 +179,6 @@ const commsService = new CommsService(`comms-service-${stack}`, {name: 'NOTIFICATION_QUEUE',value: pulumi.interpolate`${notificationQueueName}`,},- {- name: 'DOCUMENT_STORAGE_SERVICE_URL',- value: `https://cloud-storage${stack === 'prod' ? '' : `-${stack}`}.macro.com`,- },{name: 'CONTACTS_QUEUE',value: pulumi.interpolate`${contactsQueueName}`,diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 7aa8ba33d2..27091e659d 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -1929,7 +1929,6 @@ dependencies = ["comms","comms_db_client","connection_gateway",- "document_storage_service_client","doppleganger","frecency","futures",@@ -1939,12 +1938,14 @@ dependencies = ["macro_aws_config","macro_axum_utils","macro_cors",+ "macro_db_client","macro_entrypoint","macro_env","macro_env_var","macro_middleware","macro_notify","macro_user_id",+ "macro_uuid","model","model-entity","model_notifications",diff --git a/rust/cloud-storage/comms_service/Cargo.toml b/rust/cloud-storage/comms_service/Cargo.tomlindex 296f4e05ee..7e6720c42b 100644--- a/rust/cloud-storage/comms_service/Cargo.toml+++ b/rust/cloud-storage/comms_service/Cargo.toml@@ -38,7 +38,7 @@ chrono = { workspace = true }comms = { path = "../comms", features = ["inbound", "outbound"] }comms_db_client = { path = "../comms_db_client", optional = true }connection_gateway = { path = "../connection_gateway" }-document_storage_service_client = { path = "../document_storage_service_client" }+macro_db_client = { path = "../macro_db_client" }doppleganger = { workspace = true }frecency = { path = "../frecency", features = ["postgres"] }futures = { workspace = true }@@ -53,7 +53,9 @@ macro_env = { path = "../macro_env" }macro_env_var = { path = "../macro_env_var" }macro_middleware = { path = "../macro_middleware", default-features = false, features = ["auth",+ "cloud_storage",] }+macro_uuid = { path = "../macro_uuid" }macro_notify = { path = "../macro_notify" }macro_user_id = { path = "../macro_user_id" }model = { path = "../model" }diff --git a/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs b/rust/cloud-storage/comms_service/src/api/channels/add_participants.rsindex 01deadb9a7..f6907e5b75 100644--- a/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/add_participants.rs@@ -3,6 +3,7 @@ use crate::api::context::{AppState, ChannelImpl};use crate::api::extractors::{ChannelId, ChannelMember, ChannelName, ChannelParticipants, ChannelTypeExtractor,};+use crate::channel_permissions;use crate::notification as comms_notification;use anyhow::Result;use axum::extract::Json;@@ -12,10 +13,8 @@ use comms_db_client::participants::add_participant::{AddParticipantOptions, add_use doppleganger::Mirror;use macro_user_id::cowlike::CowLike;use macro_user_id::user_id::MacroUserIdStr;-use model::document_storage_service_internal::UpdateUserChannelPermissionsRequest;use model_notifications::CommonChannelMetadata;use models_comms::channel::ChannelType;-use models_permissions::share_permission::channel_share_permission::UpdateOperation;use serde::{Deserialize, Serialize};use utoipa::ToSchema;@@ -81,20 +80,19 @@ pub async fn handler(}let start = std::time::Instant::now();- ctx.document_storage_service_client- .update_user_channel_permissions(UpdateUserChannelPermissionsRequest {- user_ids: participants.clone(),- channel_id: channel_id.to_string(),- operation: UpdateOperation::Add,- })- .await- .map_err(|e| {- tracing::error!(error=?e, "unable to add permissions for channel items");- (- StatusCode::INTERNAL_SERVER_ERROR,- "unable to remove participant from channel".to_string(),- )- })?;+ channel_permissions::add_permissions_for_channel_users(+ &ctx.db,+ &channel_id.to_string(),+ &participants,+ )+ .await+ .map_err(|e| {+ tracing::error!(error=?e, "unable to add permissions for channel items");+ (+ StatusCode::INTERNAL_SERVER_ERROR,+ "unable to add permissions for channel items".to_string(),+ )+ })?;tracing::info!(elapsed=?start.elapsed(), "added user channel permissions");// There should always be participants, but better safe than sorrydiff --git a/rust/cloud-storage/comms_service/src/api/channels/post_message.rs b/rust/cloud-storage/comms_service/src/api/channels/post_message.rsindex 46a9077182..d7d371f450 100644--- a/rust/cloud-storage/comms_service/src/api/channels/post_message.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/post_message.rs@@ -1,5 +1,6 @@use crate::api::context::ChannelImpl;use crate::api::{context::AppState, extractors::ChannelName};+use crate::channel_permissions;use crate::notification as comms_notification;use crate::{api::extractors::{ChannelId, ChannelMember, ChannelParticipants, ChannelTypeExtractor},@@ -25,9 +26,9 @@ use comms_db_client::{use doppleganger::Mirror;use macro_user_id::cowlike::CowLike;use model::comms::ChannelParticipant;-use model::document_storage_service_internal::UpdateChannelSharePermissionRequest;use model_notifications::CommonChannelMetadata;use serde::{Deserialize, Serialize};+use sqlx::PgPool;use std::time::Instant;use utoipa::ToSchema;use uuid::Uuid;@@ -120,94 +121,35 @@ pub async fn post_message_handler(}).ok();- // TODO: start -- the following two blocks are duplicated and cope, I don't want to fix in my current pr- // but either myself or someone else needs to fix this - @synoet-- // If there are attachments we need to update channel share permissions through DSS- if !req.attachments.is_empty() {- let document_storage_service_client = ctx.document_storage_service_client.clone();- let channel_id: uuid::Uuid = channel_id;- let attachments = req.attachments.clone();- let user_id = message.sender_id.clone();- let db = ctx.db.clone();- tokio::spawn(async move {- tracing::trace!(attachments=?attachments, "updating channel share permissions for attachments");- let channel_info = match comms_db_client::channels::get_channel_info::get_channel_info(- &db,- &channel_id,- )- .await- {- Ok(info) => info,- Err(e) => {- tracing::error!(error=?e, "unable to get channel info");- return;- }- };-- for attachment in attachments {- if attachment.entity_type == "user" {- continue;- }- document_storage_service_client- .update_channel_share_permission(UpdateChannelSharePermissionRequest {- user_id: user_id.clone(),- channel_id: channel_id.to_string().clone(),- item_id: attachment.entity_id,- item_type: attachment.entity_type,- channel_type: channel_info.channel_type.to_string(),- })- .await- .unwrap_or_else(|e| {- tracing::error!("unable to update channel share permission: {e}");- });- }- });- }+ // Update channel share permissions for attachments and mentions+ let items_to_share: Vec<(String, String)> = req+ .attachments+ .iter()+ .filter(|a| a.entity_type != "user")+ .map(|a| (a.entity_id.clone(), a.entity_type.clone()))+ .chain(+ req.mentions+ .iter()+ .filter(|m| m.entity_type != "user")+ .map(|m| (m.entity_id.clone(), m.entity_type.clone())),+ )+ .collect();- // If there are mentions we need to update channel share permissions through DSS- if !req.mentions.is_empty() {- let document_storage_service_client = ctx.document_storage_service_client.clone();- let channel_id: uuid::Uuid = channel_id;- let mentions = req.mentions.clone();+ if !items_to_share.is_empty() {+ let channel_id_str = channel_id.to_string();let user_id = message.sender_id.clone();let db = ctx.db.clone();tokio::spawn(async move {- tracing::trace!(mentions=?mentions, "updating channel share permissions for mentions");- let channel_info = match comms_db_client::channels::get_channel_info::get_channel_info(+ update_channel_share_permissions_for_items(&db,- &channel_id,+ user_id.0.as_ref(),+ &channel_id_str,+ items_to_share,)- .await- {- Ok(info) => info,- Err(e) => {- tracing::error!(error=?e, "unable to get channel info");- return;- }- };- for mention in mentions {- if mention.entity_type == "user" {- continue;- }- document_storage_service_client- .update_channel_share_permission(UpdateChannelSharePermissionRequest {- user_id: user_id.clone(),- channel_id: channel_id.to_string().clone(),- item_id: mention.entity_id,- item_type: mention.entity_type,- channel_type: channel_info.channel_type.to_string(),- })- .await- .unwrap_or_else(|e| {- tracing::error!("unable to update channel share permission: {e}");- });- }+ .await;});}- // TODO: -- end-let participants: Vec<_> = channel_participants.iter().map(|p| p.user_id.copied())@@ -330,3 +272,22 @@ pub fn dispatch_notification_task(}});}++/// Updates channel share permissions for a list of items shared in a message.+async fn update_channel_share_permissions_for_items(+ db: &PgPool,+ user_id: &str,+ channel_id: &str,+ items: Vec<(String, String)>,+) {+ tracing::trace!(items=?items, "updating channel share permissions for items");+ for (item_id, item_type) in items {+ if let Err(e) = channel_permissions::update_channel_share_permission(+ db, user_id, channel_id, &item_id, &item_type,+ )+ .await+ {+ tracing::error!(error=?e, "unable to update channel share permission");+ }+ }+}diff --git a/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs b/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rsindex 5fcd3d5de6..b47f7deeeb 100644--- a/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/remove_participants.rs@@ -1,5 +1,6 @@use crate::api::context::AppState;use crate::api::extractors::{ChannelId, ChannelMember, ChannelTypeExtractor};+use crate::channel_permissions;use anyhow::Result;use axum::extract::Json;use axum::{extract::State, http::StatusCode};@@ -7,8 +8,6 @@ use axum_extra::extract::Cached;use comms_db_client::participants::remove_participant::{RemoveParticipantOptions, remove_participant,};-use model::document_storage_service_internal::UpdateUserChannelPermissionsRequest;-use models_permissions::share_permission::channel_share_permission::UpdateOperation;use serde::{Deserialize, Serialize};use utoipa::ToSchema;@@ -68,20 +67,19 @@ pub async fn handler(}let start = std::time::Instant::now();- ctx.document_storage_service_client- .update_user_channel_permissions(UpdateUserChannelPermissionsRequest {- user_ids: req.participants.clone(),- channel_id: channel_id.to_string(),- operation: UpdateOperation::Remove,- })- .await- .map_err(|e| {- tracing::error!(error=?e, "unable to remove permissions for channel items");- (- StatusCode::INTERNAL_SERVER_ERROR,- "unable to remove participant from channel".to_string(),- )- })?;+ channel_permissions::remove_permissions_for_channel_users(+ &ctx.db,+ &channel_id.to_string(),+ &req.participants,+ )+ .await+ .map_err(|e| {+ tracing::error!(error=?e, "unable to remove permissions for channel items");+ (+ StatusCode::INTERNAL_SERVER_ERROR,+ "unable to remove permissions for channel items".to_string(),+ )+ })?;tracing::info!(elapsed=?start.elapsed(), "removed user channel permissions");Ok(StatusCode::OK)diff --git a/rust/cloud-storage/comms_service/src/api/context.rs b/rust/cloud-storage/comms_service/src/api/context.rsindex 59c29b7843..ab8be38656 100644--- a/rust/cloud-storage/comms_service/src/api/context.rs+++ b/rust/cloud-storage/comms_service/src/api/context.rs@@ -25,8 +25,6 @@ pub struct AppState {pub db: PgPool,pub connection_gateway_client: Arc<ConnectionGatewayClient>,pub macro_notify_client: Arc<macro_notify::MacroNotify>,- pub document_storage_service_client:- Arc<document_storage_service_client::DocumentStorageServiceClient>,pub sqs_client: Arc<sqs_client::SQS>,pub permissions_token_secret: LocalOrRemoteSecret<DocumentPermissionJwtSecretKey>,pub frecency_storage: FrecencyPgStorage,diff --git a/rust/cloud-storage/comms_service/src/channel_permissions.rs b/rust/cloud-storage/comms_service/src/channel_permissions.rsnew file mode 100644index 0000000000..8c17b09f48--- /dev/null+++ b/rust/cloud-storage/comms_service/src/channel_permissions.rs@@ -0,0 +1,208 @@+//! Channel share permissions handling.+//!+//! This module contains the logic for managing channel share permissions,+//! which was previously handled via calls to the document storage service.++use anyhow::Context;+use models_permissions::share_permission::access_level::AccessLevel;+use models_permissions::user_item_access::UserItemAccess;+use sqlx::PgPool;+use std::str::FromStr;+use uuid::Uuid;++/// Updates the channel share permission for an item shared in a channel message.+///+/// When a user shares an item (document, chat, project, thread) in a channel message,+/// this function:+/// 1. Validates the user has access to the item+/// 2. Creates a channel share permission linking the item to the channel+/// 3. Grants all channel participants view access to the item+#[tracing::instrument(skip(db))]+pub async fn update_channel_share_permission(+ db: &PgPool,+ user_id: &str,+ channel_id: &str,+ item_id: &str,+ item_type: &str,+) -> anyhow::Result<()> {+ // If the item type is not a supported shareable item type, return success early+ if model::item::ShareableItemType::from_str(item_type).is_err() {+ return Ok(());+ }++ // Ensure thread share permissions exist before getting access level+ if item_type == "thread" {+ macro_middleware::cloud_storage::thread::ensure_thread_exists::insert_thread_share_permissions(db, item_id)+ .await+ .context("failed to insert thread share permissions")?;+ }++ // Get user's max access level to the item+ let user_access_level =+ macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2(+ db, user_id, item_id, item_type,+ )+ .await+ .map_err(|e| anyhow::anyhow!("failed to get user access level: {}", e.1))?;++ if user_access_level.is_none() {+ tracing::info!("user does not have access to the item, not modifying share permissions");+ return Ok(());+ }++ let channel_share_permission_access_level = AccessLevel::View;++ // Get share permission id+ let share_permission_id =+ macro_db_client::share_permission::get::get_share_permission_id(db, item_id, item_type)+ .await+ .context("failed to get share permission id")?;++ // Insert channel share permission+ if let Err(e) =+ macro_db_client::share_permission::channel_permission::create::insert_channel_share_permission(+ db,+ &share_permission_id,+ channel_id,+ &channel_share_permission_access_level,+ )+ .await+ {+ if e.to_string() == "channel permission already exists" {+ // fail silently. this flow happens when the patch item call made by the FE inserts the CSP+ // before this.+ return Ok(());+ } else {+ return Err(e).context("failed to insert channel share permission");+ }+ }++ // This flow means the channel share permission is new - the user shared the item directly+ // through a channel message. Grant all channel participants view access.+ let channel_uuid = Uuid::parse_str(channel_id).context("failed to parse channel_id as UUID")?;++ let channel_participants =+ comms_db_client::participants::get_participants::get_participants(db, &channel_uuid)+ .await+ .context("failed to get channel participants")?+ .into_iter()+ .filter_map(|p| match p.left_at {+ // If the user left we should not update their user item access+ Some(_) => None,+ None => Some(p.user_id),+ })+ .collect::<Vec<_>>();++ macro_db_client::item_access::insert::upsert_user_item_access_bulk(+ db,+ &channel_participants,+ item_id,+ item_type,+ channel_share_permission_access_level,+ Some(channel_uuid),+ )+ .await+ .context("failed to insert user item access rows")?;++ Ok(())+}++/// Adds permissions for users who have been added to a channel.+///+/// When users are added to a channel, they need to be granted access to all items+/// that have been shared with that channel.+#[tracing::instrument(skip(db))]+pub async fn add_permissions_for_channel_users(+ db: &PgPool,+ channel_id: &str,+ user_ids: &[String],+) -> anyhow::Result<()> {+ if user_ids.is_empty() {+ return Ok(());+ }++ let channel_uuid =+ macro_uuid::string_to_uuid(channel_id).context("failed to parse channel_id as UUID")?;++ let mut items_to_insert: Vec<UserItemAccess> = Vec::new();++ // Get all channel share permissions for the channel+ let csps = macro_db_client::share_permission::channel_permission::get::get_channel_share_permissions_by_channel_id(+ db,+ channel_id,+ )+ .await+ .context("failed to get channel share permissions for channel")?;++ let csp_ids = csps+ .iter()+ .map(|csp| csp.share_permission_id.clone())+ .collect::<Vec<_>>();++ if csp_ids.is_empty() {+ return Ok(());+ }++ // Get all items matching the channel share permission IDs+ let item_type_map =+ macro_db_client::share_permission::get::get_items_by_share_permission_ids(db, &csp_ids)+ .await+ .context("failed to get items for share permission ids")?;++ // For each item, add an entry for each user into UserItemAccess+ for csp in csps {+ if let Some((item_id, item_type)) = item_type_map.get(&csp.share_permission_id) {+ for user_id in user_ids.iter() {+ items_to_insert.push(UserItemAccess {+ id: macro_uuid::generate_uuid_v7(),+ user_id: user_id.to_string(),+ item_id: item_id.to_string(),+ item_type: item_type.to_string(),+ access_level: csp.access_level,+ granted_from_channel_id: Some(channel_uuid),+ created_at: chrono::Utc::now(),+ updated_at: chrono::Utc::now(),+ });+ }+ }+ }++ if !items_to_insert.is_empty() {+ // Insert into database+ macro_db_client::item_access::insert::insert_user_item_access_batch(db, &items_to_insert)+ .await+ .context("failed to insert user item access records")?;+ }++ Ok(())+}++/// Removes permissions for users who have been removed from a channel.+///+/// When users are removed from a channel, their access to items granted through+/// that channel should be revoked.+#[tracing::instrument(skip(db))]+pub async fn remove_permissions_for_channel_users(+ db: &PgPool,+ channel_id: &str,+ user_ids: &[String],+) -> anyhow::Result<u64> {+ if user_ids.is_empty() {+ return Ok(0);+ }++ let channel_uuid =+ macro_uuid::string_to_uuid(channel_id).context("failed to parse channel_id as UUID")?;++ // Delete all UserItemAccess records for these users granted from this channel+ let rows_affected =+ macro_db_client::item_access::delete::delete_user_item_access_by_channel_and_users(+ db,+ channel_uuid,+ user_ids,+ )+ .await+ .context("failed to delete user item access records")?;++ Ok(rows_affected)+}diff --git a/rust/cloud-storage/comms_service/src/config.rs b/rust/cloud-storage/comms_service/src/config.rsindex 0661b0bdc0..b72843e716 100644--- a/rust/cloud-storage/comms_service/src/config.rs+++ b/rust/cloud-storage/comms_service/src/config.rs@@ -25,9 +25,6 @@ pub struct Config {/// The SQS queue to send notifications topub notification_queue: String,- /// The url of the document storage service- pub document_storage_service_url: String,-/// The contacts SQS queuepub contacts_queue: String,@@ -58,9 +55,6 @@ impl Config {let notification_queue =std::env::var("NOTIFICATION_QUEUE").context("NOTIFICATION_QUEUE must be provided")?;- let document_storage_service_url = std::env::var("DOCUMENT_STORAGE_SERVICE_URL")- .context("DOCUMENT_STORAGE_SERVICE_URL must be provided")?;-let contacts_queue =std::env::var("CONTACTS_QUEUE").context("CONTACTS_QUEUE must be provided")?;@@ -82,7 +76,6 @@ impl Config {internal_auth_key,connection_gateway_url,notification_queue,- document_storage_service_url,contacts_queue,auth_service_url,auth_service_secret_key,diff --git a/rust/cloud-storage/comms_service/src/main.rs b/rust/cloud-storage/comms_service/src/main.rsindex be96b354cb..d531c5bfbb 100644--- a/rust/cloud-storage/comms_service/src/main.rs+++ b/rust/cloud-storage/comms_service/src/main.rs@@ -17,6 +17,7 @@ use std::sync::Arc;use tokio::net::TcpListener;mod api;+mod channel_permissions;mod config;mod constants;mod notification;@@ -70,12 +71,6 @@ async fn main() -> anyhow::Result<()> {.await;tracing::trace!("initialized macro_notify client");- let document_storage_service_client =- document_storage_service_client::DocumentStorageServiceClient::new(- config.internal_auth_key.as_ref().to_string(),- config.document_storage_service_url.clone(),- );-let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(&aws_config)).contacts_queue(&config.contacts_queue).search_event_queue(&config.search_event_queue);@@ -136,7 +131,6 @@ async fn main() -> anyhow::Result<()> {db,sqs_client: Arc::new(sqs_client),macro_notify_client: Arc::new(macro_notify_client),- document_storage_service_client: Arc::new(document_storage_service_client),connection_gateway_client: Arc::new(connection_gateway_client),permissions_token_secret,comms_state: CommsRouterState::new(ChannelServiceImpl::new(diff --git a/rust/cloud-storage/comms_service/src/notification.rs b/rust/cloud-storage/comms_service/src/notification.rsindex 2116cfb6aa..301403ad81 100644--- a/rust/cloud-storage/comms_service/src/notification.rs+++ b/rust/cloud-storage/comms_service/src/notification.rs@@ -5,8 +5,9 @@ use comms_db_client::{model::{Message, SimpleMention},participants::get_participants::get_channel_participants_for_thread_id,};+use macro_db_client::notification::BasicCloudStorageItemMetadata;use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};-use model::{comms::ChannelParticipant, document_storage_service_internal::DocumentMetadata};+use model::comms::ChannelParticipant;use model_entity::EntityType;use model_notifications::{ChannelInviteMetadata, ChannelMentionMetadata, ChannelMessageDocumentMetadata,@@ -22,7 +23,7 @@ pub struct ChannelMessageEvent<'a> {channel_metadata: &'a CommonChannelMetadata,channel_message_count: usize,user_mentions: &'a [String],- document_mentions: &'a [DocumentMetadata],+ document_mentions: &'a [BasicCloudStorageItemMetadata],participants: &'a [ChannelParticipant],thread_participants: &'a [MacroUserIdStr<'static>],thread_parent_sender_id: Option<MacroUserIdStr<'static>>,@@ -242,14 +243,15 @@ pub async fn dispatch_notifications_for_message((users, docs)});- let document_mentions = api_context- .document_storage_service_client- .get_documents_metadata(document_mention_ids)+ let document_mentions =+ macro_db_client::notification::get_basic_cloud_storage_documents_metadata(+ &api_context.db,+ &document_mention_ids,+ ).await.inspect_err(|e| {- tracing::error!("unable to get documents metadata: {e}");+ tracing::error!(error=?e, "unable to get documents metadata");})- .map(|response| response.documents).unwrap_or_default();let (thread_participants, thread_parent_sender_id) = if let Some(thread_id) = message.thread_id@@ -329,8 +331,8 @@ mod tests {}}- fn doc_metadata(name: &str) -> DocumentMetadata {- DocumentMetadata {+ fn doc_metadata(name: &str) -> BasicCloudStorageItemMetadata {+ BasicCloudStorageItemMetadata {item_name: name.to_string(),item_owner: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap()diff --git a/rust/cloud-storage/comms_service/src/openapi.rs b/rust/cloud-storage/comms_service/src/openapi.rsindex 1e228683b4..8f84ef8cc9 100644--- a/rust/cloud-storage/comms_service/src/openapi.rs+++ b/rust/cloud-storage/comms_service/src/openapi.rs@@ -1,6 +1,7 @@#![allow(unused)]mod api;+mod channel_permissions;mod config;mod constants;mod notification;diff --git a/rust/cloud-storage/document_storage_service/src/api/channel/mod.rs b/rust/cloud-storage/document_storage_service/src/api/channel/mod.rsdeleted file mode 100644index 992f6a1d94..0000000000--- a/rust/cloud-storage/document_storage_service/src/api/channel/mod.rs+++ /dev/null@@ -1 +0,0 @@-pub mod update_channel_share_permission;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.rsdeleted file mode 100644index 0ba1d819a5..0000000000--- a/rust/cloud-storage/document_storage_service/src/api/channel/update_channel_share_permission.rs+++ /dev/null@@ -1,175 +0,0 @@-use std::str::FromStr;--use crate::api::context::ApiContext;-use axum::{- extract::State,- http::StatusCode,- response::{IntoResponse, Json, Response},-};-use macro_middleware::cloud_storage::ensure_access::get_users_access_level_v2;-use macro_middleware::cloud_storage::thread::ensure_thread_exists::insert_thread_share_permissions;-use model::{- document_storage_service_internal::UpdateChannelSharePermissionRequest,- item::ShareableItemType,- response::{ErrorResponse, GenericSuccessResponse},-};-use models_permissions::share_permission::access_level::AccessLevel;--/// Attaches/Removes a given channel from a DSS items share permissions-#[tracing::instrument(skip(ctx, req), fields(channel_id=%req.channel_id, item_id=%req.item_id, item_type=%req.item_type, user_id=%req.user_id))]-pub async fn handler(- State(ctx): State<ApiContext>,- Json(req): Json<UpdateChannelSharePermissionRequest>,-) -> Result<Response, Response> {- tracing::info!("update_channel_share_permission");-- // if the item type is not a supported shareable item type, return success early- if ShareableItemType::from_str(&req.item_type).is_err() {- return Ok((StatusCode::OK, Json(GenericSuccessResponse::default())).into_response());- }-- // ensure thread share permissions exist before getting access level- if req.item_type == "thread" {- insert_thread_share_permissions(&ctx.db, &req.item_id)- .await- .map_err(|e| {- tracing::error!(error=?e, "failed to insert thread share permissions");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to insert thread share permissions",- }),- )- .into_response()- })?;- }-- // Get users max access level to the item- let user_access_level = get_users_access_level_v2(- &ctx.db,- req.user_id.0.as_ref(),- &req.item_id,- &req.item_type,- )- .await- .map_err(|e| {- tracing::error!(error=?e, "failed to get user access level");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to get user access level",- }),- )- .into_response()- })?;-- if user_access_level.is_none() {- tracing::info!("user does not have access to the item, not modifying share permissions");- return Ok((- StatusCode::NOT_MODIFIED,- Json(ErrorResponse {- message: "user does not have access to the item, not modifying share permissions",- }),- )- .into_response());- }-- let channel_share_permission_access_level = AccessLevel::View;-- // Get share permission id- let share_permission_id = macro_db_client::share_permission::get::get_share_permission_id(- &ctx.db,- &req.item_id,- &req.item_type,- )- .await- .map_err(|e| {- tracing::error!(error=?e, "failed to get share permission id");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to get share permission id",- }),- )- .into_response()- })?;-- if let Err(e) = macro_db_client::share_permission::channel_permission::create::insert_channel_share_permission(- &ctx.db,- &share_permission_id,- &req.channel_id,- &channel_share_permission_access_level,- )- .await- {- if e.to_string() == "channel permission already exists" {- // fail silently. this flow happens when the patch item call made by the FE inserts the CSP- // before this.- } else {- tracing::error!(error=?e, "failed to insert channel share permission");- return Err((- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to insert channel share permission",- }),- ).into_response());- }- } else {- // this flow means the channel share permission is new - the user shared the item directly- // through a channel message.-- let channel_id = uuid::Uuid::parse_str(&req.channel_id).map_err(|e| {- tracing::error!(error=?e, "failed to parse channel_id as UUID");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to parse channel_id as UUID",- }),- )- .into_response()- })?;-- 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");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to get channel participants",- }),- )- .into_response()- })?- .into_iter()- .filter_map(|p| match p.left_at {- // If the user left we should not update their user item access- Some(_) => None,- None => Some(p.user_id)- })- .collect::<Vec<_>>();--- macro_db_client::item_access::insert::upsert_user_item_access_bulk(- &ctx.db,- &channel_participants,- &req.item_id,- &req.item_type,- channel_share_permission_access_level,- Some(channel_id))- .await- .map_err(|e| {- tracing::error!(error=?e, "failed to insert user item access rows");- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "failed to insert user item access rows",- }),- )- .into_response()- })?;-- }-- Ok((StatusCode::OK, Json(GenericSuccessResponse::default())).into_response())-}diff --git a/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs b/rust/cloud-storage/document_storage_service/src/api/internal/mod.rsindex 76cde7c1ee..e9bd88779c 100644--- a/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs+++ b/rust/cloud-storage/document_storage_service/src/api/internal/mod.rs@@ -1,5 +1,4 @@use super::{- channel,context::ApiContext,documents::{export_document, get_document_version},history::upsert_history,@@ -40,11 +39,6 @@ pub fn router(state: ApiContext) -> Router<ApiContext> {axum::middleware::from_fn_with_state(state.clone(), ensure_user_exists::handler);Router::new()- // Channel routes- .route(- "/channel/update_share_permission",- post(channel::update_channel_share_permission::handler),- )// User routes.route("/channel/update_user_channel_permissions",diff --git a/rust/cloud-storage/document_storage_service/src/api/mod.rs b/rust/cloud-storage/document_storage_service/src/api/mod.rsindex 3227c1b775..c2e85bde62 100644--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs@@ -26,7 +26,6 @@ mod middleware;// Routesmod activity;mod annotations;-mod channel;mod documents;mod health;mod history;