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.

fix teams (#2237)

Will Hutchinsoneb964dc8f544
diff --git a/rust/cloud-storage/authentication_service/src/api/team/create_team.rs b/rust/cloud-storage/authentication_service/src/api/team/create_team.rs
deleted file mode 100644
index 7126b12a33..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/create_team.rs
+++ /dev/null
@@ -1,67 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{self, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use macro_user_id::user_id::MacroUserIdStr;
-use models_team::Team;
-use teams::domain::team_repo::TeamService;
-
-use crate::api::context::ApiContext;
-
-use model::{response::ErrorResponse, tracking::IPContext, user::UserContext};
-
-/// The request body to create a new team
-#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
-pub struct CreateTeamRequest {
- /// The name of the team
- pub name: String,
-}
-
-/// Creates a new team.
-#[utoipa::path(
- post,
- path = "/team",
- operation_id = "create_team",
- responses(
- (status = 200, body=Team),
- (status = 400, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context, req), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- extract::Json(req): extract::Json<CreateTeamRequest>,
-) -> Result<Response, Response> {
- tracing::info!("create_team");
-
- let macro_user_id = MacroUserIdStr::parse_from_str(&user_context.user_id).map_err(|_| {
- (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "invalid macro user id".into(),
- }),
- )
- .into_response()
- })?;
-
- let team = ctx
- .teams_service
- .create_team(&macro_user_id, &req.name)
- .await
- .map_err(|_| {
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to create team".into(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(team)).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/delete_team.rs b/rust/cloud-storage/authentication_service/src/api/team/delete_team.rs
deleted file mode 100644
index 13683d8da8..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/delete_team.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use teams::domain::{model::DeleteTeamError, team_repo::TeamService};
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{OwnerRole, TeamAccessRoleExtractor},
- team::TeamPathParam,
-};
-
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
- user::UserContext,
-};
-
-#[derive(Debug, thiserror::Error)]
-pub enum DeleteTeamHandlerError {
- #[error("Delete team error")]
- DeleteTeamError(#[from] DeleteTeamError),
-}
-
-impl IntoResponse for DeleteTeamHandlerError {
- fn into_response(self) -> Response {
- match self {
- DeleteTeamHandlerError::DeleteTeamError(e) => match e {
- DeleteTeamError::TeamError(_) | DeleteTeamError::StorageLayerError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to delete team".into(),
- }),
- ),
- DeleteTeamError::RemoveRolesFromUserError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "invalid roles provided".into(),
- }),
- ),
- DeleteTeamError::CustomerError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to delete team subscription".into(),
- }),
- ),
- },
- }
- .into_response()
- }
-}
-
-/// Deletes a team.
-/// This will update all team members roles and cancel your subscription for the team.
-/// This action is **irreversible** and you will not be able to recover the team afterwards.
-#[utoipa::path(
- delete,
- path = "/team/{team_id}",
- operation_id = "delete_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to delete")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), err, fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<OwnerRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- Path(TeamPathParam { team_id }): Path<TeamPathParam>,
-) -> Result<Json<EmptyResponse>, DeleteTeamHandlerError> {
- tracing::info!("delete_team");
-
- ctx.teams_service.delete_team(&team_id).await?;
-
- Ok(Json(EmptyResponse::default()))
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/delete_team_invite.rs b/rust/cloud-storage/authentication_service/src/api/team/delete_team_invite.rs
deleted file mode 100644
index 702d827001..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/delete_team_invite.rs
+++ /dev/null
@@ -1,97 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use teams::domain::{model::RemoveTeamInviteError, team_repo::TeamService};
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{OwnerRole, TeamAccessRoleExtractor},
-};
-
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
- user::UserContext,
-};
-
-#[derive(serde::Deserialize)]
-pub struct Param {
- pub team_id: uuid::Uuid,
- pub team_invite_id: uuid::Uuid,
-}
-
-#[derive(Debug, thiserror::Error)]
-pub enum DeleteTeamInviteError {
- #[error("unable to delete team invite")]
- RemoveTeamInviteError(#[from] RemoveTeamInviteError),
-}
-
-impl IntoResponse for DeleteTeamInviteError {
- fn into_response(self) -> Response {
- match self {
- DeleteTeamInviteError::RemoveTeamInviteError(e) => match e {
- RemoveTeamInviteError::TeamInviteDoesNotExist => (
- StatusCode::NOT_FOUND,
- Json(ErrorResponse {
- message: "team invite does not exist".into(),
- }),
- ),
- RemoveTeamInviteError::UserNotInTeam => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "user not in team".into(),
- }),
- ),
- RemoveTeamInviteError::StorageLayerError(_)
- | RemoveTeamInviteError::CustomerError(_)
- | RemoveTeamInviteError::TeamError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to delete team invite".into(),
- }),
- ),
- },
- }
- .into_response()
- }
-}
-
-/// Deletes a team invite from a team.
-#[utoipa::path(
- delete,
- path = "/team/{team_id}/remove/{team_invite_id}",
- operation_id = "delete_team_invite_handler",
- params(
- ("team_id" = String, Path, description = "The ID of the team to invite to"),
- ("team_invite_id" = String, Path, description = "The ID of the team invite to reinvite")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 404, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<OwnerRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- Path(Param {
- team_id,
- team_invite_id,
- }): Path<Param>,
-) -> Result<(StatusCode, Json<EmptyResponse>), DeleteTeamInviteError> {
- tracing::info!("delete_team_invite_handler");
-
- ctx.teams_service
- .delete_team_invite(&team_id, &team_invite_id)
- .await?;
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())))
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/get_team.rs b/rust/cloud-storage/authentication_service/src/api/team/get_team.rs
deleted file mode 100644
index 476448fc77..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/get_team.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use models_team::TeamWithUsers;
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{MemberRole, TeamAccessRoleExtractor},
- team::TeamPathParam,
-};
-
-use model::{response::ErrorResponse, tracking::IPContext, user::UserContext};
-
-/// Gets a team by ID.
-#[utoipa::path(
- get,
- path = "/team/{team_id}",
- operation_id = "get_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to retrieve")
- ),
- responses(
- (status = 200, body=TeamWithUsers),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 404, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<MemberRole>,
-
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- Path(TeamPathParam { team_id }): Path<TeamPathParam>,
-) -> Result<Response, Response> {
- tracing::info!("get_team");
-
- let team = macro_db_client::team::get::get_team_by_id(&ctx.db, &team_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get team");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to get team".into(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(team)).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/get_team_invites.rs b/rust/cloud-storage/authentication_service/src/api/team/get_team_invites.rs
deleted file mode 100644
index ffcf00f7fc..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/get_team_invites.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use models_team::TeamInvite;
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{AdminRole, TeamAccessRoleExtractor},
- team::TeamPathParam,
-};
-
-use model::{response::ErrorResponse, tracking::IPContext, user::UserContext};
-
-#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
-pub struct TeamInvitesResponse {
- pub invites: Vec<TeamInvite>,
-}
-
-/// Gets all invites for a team.
-#[utoipa::path(
- get,
- path = "/team/{team_id}/invites",
- operation_id = "get_team_invites",
- params(
- ("team_id" = String, Path, description = "The ID of the team to get invites for")
- ),
- responses(
- (status = 200, body=TeamInvitesResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<AdminRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- Path(TeamPathParam { team_id }): Path<TeamPathParam>,
-) -> Result<Response, Response> {
- tracing::info!("get_team_invites");
-
- let invites = macro_db_client::team::get::get_team_invites(&ctx.db, &team_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get team invites");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to get team invites".into(),
- }),
- )
- .into_response()
- })?;
-
- let response = TeamInvitesResponse { invites };
-
- Ok((StatusCode::OK, Json(response)).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/get_user_invites.rs b/rust/cloud-storage/authentication_service/src/api/team/get_user_invites.rs
deleted file mode 100644
index 50ec74e9af..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/get_user_invites.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-use axum::{
- Extension, Json,
- extract::State,
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-
-use crate::api::{context::ApiContext, team::get_team_invites::TeamInvitesResponse};
-
-use model::{response::ErrorResponse, tracking::IPContext, user::UserContext};
-
-/// Gets all of a user's invitations.
-#[utoipa::path(
- get,
- path = "/team/user/invites",
- operation_id = "get_user_invites",
- responses(
- (status = 200, body=TeamInvitesResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
-) -> Result<Response, Response> {
- tracing::info!("get_user_invites");
-
- let team_invites =
- macro_db_client::team::get::get_user_team_invites(&ctx.db, &user_context.user_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get user invites");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to get user invites".into(),
- }),
- )
- .into_response()
- })?;
-
- let response = TeamInvitesResponse {
- invites: team_invites,
- };
-
- Ok((StatusCode::OK, Json(response)).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/get_user_teams.rs b/rust/cloud-storage/authentication_service/src/api/team/get_user_teams.rs
deleted file mode 100644
index 9b53c9a97d..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/get_user_teams.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use axum::{
- Extension, Json,
- extract::State,
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use models_team::Team;
-
-use crate::api::context::ApiContext;
-
-use model::{response::ErrorResponse, tracking::IPContext, user::UserContext};
-
-/// Gets all teams for the authenticated user.
-#[utoipa::path(
- get,
- path = "/team/user",
- operation_id = "get_user_teams",
- responses(
- (status = 200, body=Vec<Team>),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
-) -> Result<Response, Response> {
- tracing::info!("get_user_teams");
-
- let teams = macro_db_client::team::get::get_user_teams(&ctx.db, &user_context.user_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get user teams");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to get user teams".into(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(teams)).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/invite_to_team.rs b/rust/cloud-storage/authentication_service/src/api/team/invite_to_team.rs
deleted file mode 100644
index 639f8bf7a4..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/invite_to_team.rs
+++ /dev/null
@@ -1,207 +0,0 @@
-use std::collections::HashSet;
-
-use axum::{
- Extension, Json,
- extract::{self, Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use macro_user_id::{
- cowlike::CowLike, email::Email, lowercased::Lowercase, user_id::MacroUserIdStr,
-};
-use model_entity::EntityType;
-use model_user::axum_extractor::MacroUserExtractor;
-use notification::domain::models::SendNotificationRequestBuilder;
-use notification::domain::service::NotificationIngress;
-use teams::domain::{
- model::{InviteUsersToTeamError, TeamInvite},
- team_repo::TeamService,
-};
-
-use crate::api::{
- context::ApiContext,
- middleware::{
- has_payment_source::StripeCustomerExtractor,
- team_access::{OwnerRole, TeamAccessRoleExtractor},
- },
- team::TeamPathParam,
-};
-use model_notifications::InviteToTeamMetadata;
-
-use model::{response::ErrorResponse, tracking::IPContext};
-
-/// The request body to invite a user to a team
-#[derive(serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
-pub struct InviteToTeamRequest {
- /// The emails of the users you want to invite to the team
- pub emails: Vec<String>,
-}
-
-#[derive(Debug, thiserror::Error)]
-pub enum InviteToTeamError {
- #[error("unable to invite users to team")]
- InviteUsersToTeamError(#[from] InviteUsersToTeamError),
- #[error("unable to parse email")]
- InvalidEmails,
- #[error("no valid emails provided")]
- NoValidEmailsProvided,
-}
-
-impl IntoResponse for InviteToTeamError {
- fn into_response(self) -> Response {
- match self {
- InviteToTeamError::InvalidEmails => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "invalid emails detected".into(),
- }),
- ),
- InviteToTeamError::NoValidEmailsProvided => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "no emails provided".into(),
- }),
- ),
- InviteToTeamError::InviteUsersToTeamError(e) => match e {
- InviteUsersToTeamError::TooManyEmails => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "too many emails".into(),
- }),
- ),
- _ => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to invite users to team".into(),
- }),
- ),
- },
- }
- .into_response()
- }
-}
-
-/// Invites a user to a team.
-#[utoipa::path(
- post,
- path = "/team/{team_id}/invite",
- operation_id = "invite_to_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to invite to")
- ),
- request_body = InviteToTeamRequest,
- responses(
- (status = 201), // created
- (status = 304), // not modified
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 404, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context, req), fields(client_ip=%ip_context.client_ip, user_id=%user_context.macro_user_id, fusion_user_id=%user_context.user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<OwnerRole>,
- stripe_customer: StripeCustomerExtractor,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: MacroUserExtractor,
- Path(TeamPathParam { team_id }): Path<TeamPathParam>,
- extract::Json(req): extract::Json<InviteToTeamRequest>,
-) -> Result<StatusCode, InviteToTeamError> {
- tracing::info!("invite_to_team");
-
- let emails: Vec<Result<Email<Lowercase>, _>> = req
- .emails
- .iter()
- .map(|email| Email::parse_from_str(email).map(|email| email.lowercase()))
- .collect();
-
- if emails.iter().any(|e| e.is_err()) {
- return Err(InviteToTeamError::InvalidEmails);
- }
-
- let emails = emails.into_iter().map(|e| e.unwrap()).collect::<Vec<_>>();
-
- let emails = non_empty::NonEmpty::new(emails.as_slice())
- .map_err(|_| InviteToTeamError::NoValidEmailsProvided)?;
-
- let team_invites = ctx
- .teams_service
- .invite_users_to_team(&team_id, &user_context.macro_user_id, emails)
- .await
- .map_err(InviteToTeamError::InviteUsersToTeamError)?;
-
- if team_invites.is_empty() {
- return Ok(StatusCode::NOT_MODIFIED);
- }
-
- let team_invites: Vec<TeamInvite<'_>> = team_invites
- .into_iter()
- .map(|e| TeamInvite {
- team_id: e.team_id,
- team_invite_id: e.team_invite_id,
- email: e.email.into_owned(),
- })
- .collect();
-
- // Send the invites
- tokio::spawn({
- let db = ctx.db.clone();
- let notification_ingress_service = ctx.notification_ingress_service.clone();
- let team_invites = team_invites.clone();
- let invited_by = user_context.macro_user_id;
- async move {
- let _ = notify_team_invite(
- &db,
- &*notification_ingress_service,
- &team_id,
- team_invites,
- invited_by,
- )
- .await
- .inspect_err(|e| tracing::error!(error=?e, "unable to send notification"));
- }
- });
-
- Ok(StatusCode::CREATED)
-}
-
-pub(in crate::api::team) async fn notify_team_invite(
- db: &sqlx::Pool<sqlx::Postgres>,
- notification_ingress_service: &impl NotificationIngress,
- team_id: &uuid::Uuid,
- team_invites: Vec<TeamInvite<'_>>,
- invited_by: MacroUserIdStr<'static>,
-) -> anyhow::Result<()> {
- let team_name = macro_db_client::team::get::get_team_name(db, team_id).await?;
-
- for team_invite in team_invites {
- let notification = InviteToTeamMetadata {
- invited_by: invited_by.clone(),
- team_name: team_name.clone(),
- team_id: team_id.to_string(),
- role: None,
- };
-
- let recipient = MacroUserIdStr::try_from_email(team_invite.email.as_ref())
- .map_err(|e| anyhow::anyhow!("failed to parse email as macro user id: {}", e))?;
-
- let entity_id = team_invite.team_invite_id.to_string();
- let request = SendNotificationRequestBuilder {
- notification_entity: EntityType::Team.with_entity_str(&entity_id),
- notification,
- sender_id: Some(invited_by.clone()),
- recipient_ids: HashSet::from([recipient]),
- }
- .into_request()
- .with_conn_gateway();
-
- notification_ingress_service
- .send_notification(request)
- .await
- .map_err(|e| anyhow::anyhow!("failed to send notification: {}", e))?;
- }
-
- Ok(())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/join_team.rs b/rust/cloud-storage/authentication_service/src/api/team/join_team.rs
deleted file mode 100644
index bead4c797c..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/join_team.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use model_user::axum_extractor::MacroUserExtractor;
-use teams::domain::{model::JoinTeamError, team_repo::TeamService};
-
-use crate::api::context::ApiContext;
-
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
-};
-
-#[derive(serde::Deserialize)]
-pub struct TeamInvitePathParam {
- pub team_invite_id: uuid::Uuid,
-}
-
-#[derive(Debug, thiserror::Error)]
-pub enum JoinTeamHandlerError {
- #[error("unable to join team")]
- JoinTeamError(#[from] JoinTeamError),
-}
-
-impl IntoResponse for JoinTeamHandlerError {
- fn into_response(self) -> Response {
- match self {
- JoinTeamHandlerError::JoinTeamError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to join team".into(),
- }),
- )
- .into_response(),
- }
- }
-}
-
-/// Joins a team by accepting an invite.
-#[utoipa::path(
- get,
- path = "/team/join/{team_invite_id}",
- operation_id = "join_team",
- params(
- ("team_invite_id" = String, Path, description = "The team invite id")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, user_context, ip_context), err, fields(user_id=%user_context.macro_user_id, client_ip=%ip_context.client_ip))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: MacroUserExtractor,
- Path(TeamInvitePathParam { team_invite_id }): Path<TeamInvitePathParam>,
-) -> Result<Json<EmptyResponse>, JoinTeamHandlerError> {
- tracing::info!("join_team");
-
- ctx.teams_service
- .join_team(&team_invite_id, &user_context.macro_user_id)
- .await?;
-
- Ok(Json(EmptyResponse::default()))
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/mod.rs b/rust/cloud-storage/authentication_service/src/api/team/mod.rs
deleted file mode 100644
index af0b487a12..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/mod.rs
+++ /dev/null
@@ -1,58 +0,0 @@
-use crate::api::context::ApiContext;
-use axum::{
- Router,
- routing::{delete, get, patch, post},
-};
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use tower::ServiceBuilder;
-
-pub(in crate::api) mod create_team;
-pub(in crate::api) mod delete_team;
-pub(in crate::api) mod delete_team_invite;
-pub(in crate::api) mod get_team;
-pub(in crate::api) mod get_team_invites;
-pub(in crate::api) mod get_user_invites;
-pub(in crate::api) mod get_user_teams;
-pub(in crate::api) mod invite_to_team;
-pub(in crate::api) mod join_team;
-pub(in crate::api) mod patch_team;
-pub(in crate::api) mod reinvite_to_team;
-pub(in crate::api) mod reject_invitation;
-pub(in crate::api) mod remove_user_from_team;
-
-pub fn router(jwt_args: JwtValidationArgs) -> Router<ApiContext> {
- Router::new()
- .route("/", post(create_team::handler))
- .route("/join/{team_invite_id}", get(join_team::handler))
- .route("/user", get(get_user_teams::handler))
- .route("/user/invites", get(get_user_invites::handler))
- .route("/{team_id}", get(get_team::handler))
- .route("/{team_id}", patch(patch_team::handler))
- .route("/{team_id}", delete(delete_team::handler))
- .route("/{team_id}/invites", get(get_team_invites::handler))
- .route("/{team_id}/invite", post(invite_to_team::handler))
- .route(
- "/{team_id}/reinvite/{team_invite_id}",
- get(reinvite_to_team::handler),
- )
- .route("/join/{team_invite_id}", delete(reject_invitation::handler))
- .route(
- "/{team_id}/remove/{remove_user_id}",
- delete(remove_user_from_team::handler),
- )
- .route(
- "/{team_id}/invite/{team_invite_id}",
- delete(delete_team_invite::handler),
- )
- .layer(
- ServiceBuilder::new().layer(axum::middleware::from_fn_with_state(
- jwt_args,
- macro_middleware::auth::decode_jwt::handler,
- )),
- )
-}
-
-#[derive(serde::Deserialize)]
-pub(in crate::api) struct TeamPathParam {
- pub team_id: uuid::Uuid,
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/patch_team.rs b/rust/cloud-storage/authentication_service/src/api/team/patch_team.rs
deleted file mode 100644
index 71ce83765a..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/patch_team.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-use axum::{
- Extension, Json,
- extract::{self, Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use models_team::PatchTeamRequest;
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{AdminRole, TeamAccessRoleExtractor},
- team::TeamPathParam,
-};
-
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
- user::UserContext,
-};
-
-/// Updates a team.
-#[utoipa::path(
- patch,
- path = "/team/{team_id}",
- operation_id = "patch_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to update")
- ),
- request_body = PatchTeamRequest,
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 404, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context, req), fields(client_ip=%ip_context.client_ip, user_id=%user_context.user_id, fusion_user_id=%user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<AdminRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: Extension<UserContext>,
- Path(TeamPathParam { team_id }): Path<TeamPathParam>,
- extract::Json(req): extract::Json<PatchTeamRequest>,
-) -> Result<Response, Response> {
- tracing::info!("patch_team");
-
- macro_db_client::team::patch::patch_team(&ctx.db, &team_id, &req)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to update team");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to update team".into(),
- }),
- )
- .into_response()
- })?;
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())).into_response())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/reinvite_to_team.rs b/rust/cloud-storage/authentication_service/src/api/team/reinvite_to_team.rs
deleted file mode 100644
index 82ec61f9d1..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/reinvite_to_team.rs
+++ /dev/null
@@ -1,165 +0,0 @@
-use std::collections::HashSet;
-
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use macro_user_id::user_id::MacroUserIdStr;
-use model_entity::EntityType;
-use notification::domain::models::SendNotificationRequestBuilder;
-use notification::domain::service::NotificationIngress;
-
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{AdminRole, TeamAccessRoleExtractor},
-};
-use model_notifications::InviteToTeamMetadata;
-
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
- user::axum_extractor::MacroUserExtractor,
-};
-
-#[derive(serde::Deserialize)]
-pub struct Param {
- pub team_id: uuid::Uuid,
- pub team_invite_id: uuid::Uuid,
-}
-
-/// Regenerates a team invite notifying the user again.
-#[utoipa::path(
- post,
- path = "/team/{team_id}/reinvite/{team_invite_id}",
- operation_id = "reinvite_to_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to invite to"),
- ("team_invite_id" = String, Path, description = "The ID of the team invite to reinvite")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 429, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.macro_user_id, fusion_user_id=%user_context.user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<AdminRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: MacroUserExtractor,
- Path(Param {
- team_id,
- team_invite_id,
- }): Path<Param>,
-) -> Result<Response, Response> {
- tracing::info!("reinvite_to_team");
-
- // check to see if we should re-invite yet (wait 5 mins for last_invite)
- // send new invite to team notification
-
- let team_invite = macro_db_client::team::get::get_team_invite_by_id(&ctx.db, &team_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to get team invite");
-
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to get team invite".into(),
- }),
- )
- .into_response()
- })?;
-
- if team_invite
- .last_sent_at
- .naive_utc()
- .ge(&(chrono::Utc::now().naive_utc() - chrono::Duration::minutes(5)))
- {
- return Err((
- StatusCode::TOO_MANY_REQUESTS,
- Json(ErrorResponse {
- message: "team invite was already sent within the last 5 minutes".into(),
- }),
- )
- .into_response());
- }
-
- macro_db_client::team::patch::update_team_invite_last_sent_at(&ctx.db, &team_id)
- .await
- .map_err(|e| {
- tracing::error!(error=?e, "failed to update team invite last sent at");
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to update team invite last sent at".into(),
- }),
- )
- .into_response()
- })?;
-
- tokio::spawn({
- let db = ctx.db.clone();
- let notification_ingress_service = ctx.notification_ingress_service.clone();
- let normalized_email = team_invite.email;
- let invited_by = user_context.macro_user_id;
- let team_invite_id = team_invite.id;
- async move {
- let _ = notify_team_invite(
- &db,
- &*notification_ingress_service,
- &team_id,
- &team_invite_id,
- invited_by,
- &normalized_email,
- )
- .await
- .inspect_err(|e| tracing::error!(error=?e, "unable to send notification"));
- }
- });
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())).into_response())
-}
-
-async fn notify_team_invite(
- db: &sqlx::Pool<sqlx::Postgres>,
- notification_ingress_service: &impl NotificationIngress,
- team_id: &uuid::Uuid,
- team_invite_id: &uuid::Uuid,
- invited_by: MacroUserIdStr<'static>,
- normalized_email: &str,
-) -> anyhow::Result<()> {
- let team_name = macro_db_client::team::get::get_team_name(db, team_id).await?;
-
- let notification = InviteToTeamMetadata {
- invited_by: invited_by.clone(),
- team_name: team_name.clone(),
- team_id: team_id.to_string(),
- role: None,
- };
-
- let recipient = MacroUserIdStr::try_from_email(normalized_email)
- .map_err(|e| anyhow::anyhow!("failed to parse email as macro user id: {}", e))?;
-
- let entity_id = team_invite_id.to_string();
- let request = SendNotificationRequestBuilder {
- notification_entity: EntityType::Team.with_entity_str(&entity_id),
- notification,
- sender_id: Some(invited_by),
- recipient_ids: HashSet::from([recipient]),
- }
- .into_request()
- .with_conn_gateway();
-
- notification_ingress_service
- .send_notification(request)
- .await
- .map_err(|e| anyhow::anyhow!("failed to send notification: {}", e))?;
-
- Ok(())
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/reject_invitation.rs b/rust/cloud-storage/authentication_service/src/api/team/reject_invitation.rs
deleted file mode 100644
index 45f13ef2af..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/reject_invitation.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-use crate::api::context::ApiContext;
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
-};
-use model_user::axum_extractor::MacroUserExtractor;
-use teams::domain::{model::RemoveTeamInviteError, team_repo::TeamService};
-
-#[derive(serde::Deserialize)]
-pub struct TeamInvitePathParam {
- pub team_invite_id: uuid::Uuid,
-}
-
-#[derive(Debug, thiserror::Error)]
-pub enum RejectInvitationError {
- #[error("unable to reject invitation")]
- RemoveTeamInviteError(#[from] RemoveTeamInviteError),
-}
-
-impl IntoResponse for RejectInvitationError {
- fn into_response(self) -> Response {
- match self {
- RejectInvitationError::RemoveTeamInviteError(e) => match e {
- RemoveTeamInviteError::TeamInviteDoesNotExist => (
- StatusCode::NOT_FOUND,
- Json(ErrorResponse {
- message: "team invite does not exist".into(),
- }),
- ),
- RemoveTeamInviteError::UserNotInTeam => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "user not in team".into(),
- }),
- ),
- RemoveTeamInviteError::StorageLayerError(_)
- | RemoveTeamInviteError::CustomerError(_)
- | RemoveTeamInviteError::TeamError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to reject invitation".into(),
- }),
- ),
- },
- }
- .into_response()
- }
-}
-
-/// Rejects an invitation to join a team.
-#[utoipa::path(
- delete,
- path = "/team/join/{team_invite_id}",
- operation_id = "reject_invitation",
- params(
- ("team_invite_id" = String, Path, description = "The team invite id")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.macro_user_id, fusion_user_id=%user_context.user_context.fusion_user_id))]
-pub async fn handler(
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: MacroUserExtractor,
- Path(TeamInvitePathParam { team_invite_id }): Path<TeamInvitePathParam>,
-) -> Result<(StatusCode, Json<EmptyResponse>), RejectInvitationError> {
- tracing::info!("reject_invitation");
-
- ctx.teams_service
- .reject_invitation(&user_context.macro_user_id, &team_invite_id)
- .await?;
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())))
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/team/remove_user_from_team.rs b/rust/cloud-storage/authentication_service/src/api/team/remove_user_from_team.rs
deleted file mode 100644
index 49c904702d..0000000000
--- a/rust/cloud-storage/authentication_service/src/api/team/remove_user_from_team.rs
+++ /dev/null
@@ -1,125 +0,0 @@
-use crate::api::{
- context::ApiContext,
- middleware::team_access::{OwnerRole, TeamAccessRoleExtractor},
-};
-use axum::{
- Extension, Json,
- extract::{Path, State},
- http::StatusCode,
- response::{IntoResponse, Response},
-};
-use model::{
- response::{EmptyResponse, ErrorResponse},
- tracking::IPContext,
-};
-use model_user::axum_extractor::MacroUserExtractor;
-use macro_user_id::user_id::MacroUserIdStr;
-use teams::domain::{model::RemoveUserFromTeamError, team_repo::TeamService};
-
-#[derive(serde::Deserialize)]
-pub struct Param {
- pub team_id: uuid::Uuid,
- pub remove_user_id: String,
-}
-
-#[derive(Debug, thiserror::Error)]
-pub enum RemoveFromTeamError {
- #[error("unable to remove user from team")]
- RemoveUserFromTeamError(#[from] RemoveUserFromTeamError),
- #[error("invalid user id")]
- InvalidUserId,
-}
-
-impl IntoResponse for RemoveFromTeamError {
- fn into_response(self) -> Response {
- match self {
- RemoveFromTeamError::RemoveUserFromTeamError(e) => match e {
- RemoveUserFromTeamError::TeamDoesNotExist => (
- StatusCode::NOT_FOUND,
- Json(ErrorResponse {
- message: "team does not exist".into(),
- }),
- ),
- RemoveUserFromTeamError::RemoveRolesFromUserError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to remove roles from user".into(),
- }),
- ),
- RemoveUserFromTeamError::NoSubscription => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "no subscription".into(),
- }),
- ),
- RemoveUserFromTeamError::CannotRemoveOwner => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "cannot remove owner".into(),
- }),
- ),
- RemoveUserFromTeamError::UserNotInTeam => (
- StatusCode::NOT_FOUND,
- Json(ErrorResponse {
- message: "user not in team".into(),
- }),
- ),
- RemoveUserFromTeamError::StorageLayerError(_)
- | RemoveUserFromTeamError::CustomerError(_)
- | RemoveUserFromTeamError::TeamError(_) => (
- StatusCode::INTERNAL_SERVER_ERROR,
- Json(ErrorResponse {
- message: "unable to remove user from team".into(),
- }),
- ),
- },
- RemoveFromTeamError::InvalidUserId => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "invalid user id".into(),
- }),
- ),
- }
- .into_response()
- }
-}
-
-/// Removes a user from a team.
-#[utoipa::path(
- delete,
- path = "/team/{team_id}/remove/{remove_user_id}",
- operation_id = "remove_user_from_team",
- params(
- ("team_id" = String, Path, description = "The ID of the team to invite to"),
- ("remove_user_id" = String, Path, description = "The ID of the user to remove")
- ),
- responses(
- (status = 200, body=EmptyResponse),
- (status = 400, body=ErrorResponse),
- (status = 401, body=ErrorResponse),
- (status = 429, body=ErrorResponse),
- (status = 500, body=ErrorResponse),
- ),
- )]
-#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context.client_ip, user_id=%user_context.macro_user_id, fusion_user_id=%user_context.user_context.fusion_user_id))]
-pub async fn handler(
- access: TeamAccessRoleExtractor<OwnerRole>,
- State(ctx): State<ApiContext>,
- ip_context: Extension<IPContext>,
- user_context: MacroUserExtractor,
- Path(Param {
- team_id,
- remove_user_id,
- }): Path<Param>,
-) -> Result<(StatusCode, Json<EmptyResponse>), RemoveFromTeamError> {
- tracing::info!("remove_user_from_team");
-
- let remove_user_id = MacroUserIdStr::try_from(remove_user_id)
- .map_err(|_| RemoveFromTeamError::InvalidUserId)?;
-
- ctx.teams_service
- .remove_user_from_team(&team_id, &remove_user_id)
- .await?;
-
- Ok((StatusCode::OK, Json(EmptyResponse::default())))
-}
diff --git a/rust/cloud-storage/teams/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json b/rust/cloud-storage/teams/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
new file mode 100644
index 0000000000..4c5afc274a
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_endpoint = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "06a72bfcfbcc5f5bbed6cd093436309607f9375d2ba7b151e9dc1a8493f88e44"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json b/rust/cloud-storage/teams/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
new file mode 100644
index 0000000000..01cece9642
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01.json
@@ -0,0 +1,33 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM notification_user_device_registration\n WHERE device_token = $1 AND device_type = $2\n RETURNING device_endpoint\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "270cd8ae6b47508cb7e4e920bd76cb0f6177d685bddedb06f1892d0014af6f01"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json b/rust/cloud-storage/teams/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
new file mode 100644
index 0000000000..e4a18ac5f0
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET done = $3\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "3293eab63193f1b3822a59e9a6a9621520f26e6ec8248abed103985281ef7ff1"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json b/rust/cloud-storage/teams/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
new file mode 100644
index 0000000000..6696253445
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS(\n SELECT 1 FROM notification_message_receipt\n WHERE user_id = $1\n AND notification_id = $2\n AND failed = false\n ) as \"exists!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "exists!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "3357165799ff1f7bf1de3891174668e0ab16c64bd9dfc905213681e6021474fa"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json b/rust/cloud-storage/teams/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
new file mode 100644
index 0000000000..c07ec0acbe
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification_type_preference (user_id, notification_event_type)\n VALUES ($1, $2)\n ON CONFLICT (user_id, notification_event_type) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Varchar"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "36dfcf982834f117d97d1ba332be6784c946f05120c7c228ff258389ceba97a1"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json b/rust/cloud-storage/teams/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
new file mode 100644
index 0000000000..55fcda1121
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "4e096eb7d3c507e3647685073fba7b3f36ef0e70c887db31f5cc5a8eb8ee1844"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json b/rust/cloud-storage/teams/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
new file mode 100644
index 0000000000..d0a749ebd2
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_mute_notification\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "621186dcec072b603a5f3d7b9e987a1638589d539c60d9dc5c2ab0865ff062d6"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json b/rust/cloud-storage/teams/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
new file mode 100644
index 0000000000..d374c2f79f
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM user_notification_type_preference\n WHERE user_id = $1 AND notification_event_type = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "625ee33d48768e369ee1fe3abe27811ad04313b1aa31f4b51abe5fd3bf569674"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json b/rust/cloud-storage/teams/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
new file mode 100644
index 0000000000..65459bcefd
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id\n FROM \"User\"\n WHERE email = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "73c67fbf678e1479d528adcc5bea7da3261d0a04e24cc16f96ec9f2dea3b2e98"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json b/rust/cloud-storage/teams/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
new file mode 100644
index 0000000000..34382e8725
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id, apns_collapse_key as \"apns_collapse_key!: String\"\n FROM notification\n WHERE id = ANY($1) AND apns_collapse_key IS NOT NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "apns_collapse_key!: String",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "74d33764e454fb9ab4f2775974462d6fdb092bffc720d929de5e7b50ecef5139"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json b/rust/cloud-storage/teams/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
new file mode 100644
index 0000000000..a8e7326c35
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_item_unsubscribe\n WHERE item_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "765650cab2b1a1d1abe6ca406438bf48968cebebc7316b87b192d649e096cd67"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json b/rust/cloud-storage/teams/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
new file mode 100644
index 0000000000..9e6f7f8877
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT d.device_endpoint\n FROM notification_user_device_registration d\n WHERE d.device_token = $1\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "78f1cf9da464937604c1a2d5115c014cab9de72bd88605ff47a316baa2c7acc2"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json b/rust/cloud-storage/teams/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
new file mode 100644
index 0000000000..721b0038f2
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, notification_event_type\n FROM user_notification_type_preference\n WHERE user_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "7c0b9d645a85e30577377e4d8c8a8f976e86c6251e12517a2b1e14d525e09198"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json b/rust/cloud-storage/teams/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
new file mode 100644
index 0000000000..a166680895
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc.json
@@ -0,0 +1,21 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification (id, notification_event_type, event_item_id, event_item_type, service_sender, metadata, sender_id, apns_collapse_key)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8)\n ON CONFLICT (id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Varchar",
+ "Text",
+ "Text",
+ "Text",
+ "Jsonb",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "7ccdaab5873129437c98581ac37eb4148255b83e18fad15349d06c54040fd6cc"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json b/rust/cloud-storage/teams/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json
new file mode 100644
index 0000000000..215280eac8
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53.json
@@ -0,0 +1,97 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($3::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($3, $4))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $2\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "7cd8368263b84e0dd25d0e7d1ae40b68d3cf69baaf036d2a17bf7d06176f8a53"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-81f96534cd4a7b52d4ec2948dce8052076a25eea0af92eae1908e0e068af2116.json b/rust/cloud-storage/teams/.sqlx/query-81f96534cd4a7b52d4ec2948dce8052076a25eea0af92eae1908e0e068af2116.json
new file mode 100644
index 0000000000..4cb16ae2df
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-81f96534cd4a7b52d4ec2948dce8052076a25eea0af92eae1908e0e068af2116.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO user_notification (notification_id, user_id)\n SELECT $1, user_id\n FROM UNNEST($2::text[]) as user_id\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "81f96534cd4a7b52d4ec2948dce8052076a25eea0af92eae1908e0e068af2116"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json b/rust/cloud-storage/teams/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
new file mode 100644
index 0000000000..eab49b91f7
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET sent = true\n WHERE notification_id = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "TextArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "86eee52e30e4168f4a7f319d1dcaa59144a5b3269120df892f161c74b5fe7436"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json b/rust/cloud-storage/teams/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
new file mode 100644
index 0000000000..a8520fdfd0
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_message_receipt (message_id, user_id, notification_id)\n VALUES ($1, $2, $3)\n ON CONFLICT (message_id) DO NOTHING\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "92edc80110af7b96f7f908989461a4abb11652671a95454969369a0484ed9239"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json b/rust/cloud-storage/teams/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
new file mode 100644
index 0000000000..4035617965
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = $2\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "94c019227741f6c4fe8411454cb7c0a3a97e5594c29f11fa893238656e161ff1"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json b/rust/cloud-storage/teams/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
new file mode 100644
index 0000000000..ad14cfedba
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1.json
@@ -0,0 +1,44 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id, device_endpoint, device_type as \"device_type: DbDeviceType\"\n FROM notification_user_device_registration\n WHERE user_id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "device_endpoint",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "device_type: DbDeviceType",
+ "type_info": {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "a0046a263c572915a8e14a8ac70479f1ba89549f1930f571bf278fcfe259cfd1"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json b/rust/cloud-storage/teams/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
new file mode 100644
index 0000000000..7626c0a06b
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET seen_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "a5d9f358b5382c0eaed918f903bc6aa328f527e6e47d649c37dfcf1c9f3a7139"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json b/rust/cloud-storage/teams/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
new file mode 100644
index 0000000000..e5d913399d
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n INSERT INTO notification_user_device_registration (id, user_id, device_token, device_endpoint, device_type)\n VALUES ($1, $2, $3, $4, $5)\n ON CONFLICT (device_endpoint) DO UPDATE SET user_id = $2, device_token = $3, device_type = $5, updated_at = NOW()\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ {
+ "Custom": {
+ "name": "notification_device_type_option",
+ "kind": {
+ "Enum": [
+ "ios",
+ "android"
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "b3f9f3696438bd2ad8754650d87d7bbf32e70d3d173a748a07eacdb4e42841eb"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json b/rust/cloud-storage/teams/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
new file mode 100644
index 0000000000..1168d26a34
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9.json
@@ -0,0 +1,28 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE notification_message_receipt\n SET failed = true, failed_at = NOW()\n WHERE message_id = $1\n RETURNING user_id, notification_id\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "b6705d3675950d0bbbd4a0ba10f7716a24694cfd98741fc0508d607684b1c8a9"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json b/rust/cloud-storage/teams/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json
new file mode 100644
index 0000000000..0b09fbeec2
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2.json
@@ -0,0 +1,98 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND n.event_item_id = ANY($2)\n AND un.deleted_at IS NULL\n AND un.done = false\n AND (($4::timestamptz IS NULL)\n OR (un.created_at, un.notification_id) < ($4, $5))\n ORDER BY un.created_at DESC, un.notification_id DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray",
+ "Int8",
+ "Timestamptz",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "b6cda5fd5ec775474b301aa8a7376ff2dfd8c5812db1b6d493cbb355685907f2"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-d9a13a9704a1f510f984862914c0fda59b2d50ec3e26b9bf2659cc8b85e4f5a1.json b/rust/cloud-storage/teams/.sqlx/query-d9a13a9704a1f510f984862914c0fda59b2d50ec3e26b9bf2659cc8b85e4f5a1.json
deleted file mode 100644
index 86b13f1dcb..0000000000
--- a/rust/cloud-storage/teams/.sqlx/query-d9a13a9704a1f510f984862914c0fda59b2d50ec3e26b9bf2659cc8b85e4f5a1.json
+++ /dev/null
@@ -1,56 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT user_id, \n team_role as \"team_role!: TeamRole\",\n tier as \"tier!: TeamUserTier\"\n FROM team_user\n WHERE team_id = $1 AND team_role NOT IN ('owner')\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "user_id",
- "type_info": "Text"
- },
- {
- "ordinal": 1,
- "name": "team_role!: TeamRole",
- "type_info": {
- "Custom": {
- "name": "team_role",
- "kind": {
- "Enum": [
- "member",
- "admin",
- "owner"
- ]
- }
- }
- }
- },
- {
- "ordinal": 2,
- "name": "tier!: TeamUserTier",
- "type_info": {
- "Custom": {
- "name": "team_user_tier",
- "kind": {
- "Enum": [
- "haiku",
- "sonnet",
- "opus"
- ]
- }
- }
- }
- }
- ],
- "parameters": {
- "Left": [
- "Uuid"
- ]
- },
- "nullable": [
- false,
- false,
- false
- ]
- },
- "hash": "d9a13a9704a1f510f984862914c0fda59b2d50ec3e26b9bf2659cc8b85e4f5a1"
-}
diff --git a/rust/cloud-storage/teams/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json b/rust/cloud-storage/teams/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
new file mode 100644
index 0000000000..d197caf563
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT user_id FROM user_notification_type_preference\n WHERE notification_event_type = $1 AND user_id = ANY($2)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "user_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "TextArray"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "db297e24e3ed1e94c27121977d81813bbe4cde5e5b7bec42e424c72db0e27e73"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json b/rust/cloud-storage/teams/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json
new file mode 100644
index 0000000000..b36882b3ae
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad.json
@@ -0,0 +1,95 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n un.user_id as owner_id,\n un.notification_id,\n n.event_item_id,\n n.event_item_type,\n un.sent,\n un.done,\n un.created_at::timestamptz,\n un.seen_at::timestamptz as viewed_at,\n un.created_at::timestamptz as updated_at,\n un.deleted_at::timestamptz,\n n.metadata as \"notification_metadata: serde_json::Value\",\n n.notification_event_type as notification_event_type,\n n.sender_id as sender_id\n FROM user_notification un\n JOIN notification n ON n.id = un.notification_id\n WHERE un.user_id = $1\n AND un.notification_id = $2\n AND un.deleted_at IS NULL\n LIMIT 1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "owner_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 1,
+ "name": "notification_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_item_id",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "event_item_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sent",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 5,
+ "name": "done",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "viewed_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 8,
+ "name": "updated_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "deleted_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "notification_metadata: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "notification_event_type",
+ "type_info": "Varchar"
+ },
+ {
+ "ordinal": 12,
+ "name": "sender_id",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ false,
+ false,
+ true
+ ]
+ },
+ "hash": "e231e279615526b33206979b400328d23be40ef9da49697ef6b75cdfcd69caad"
+}
diff --git a/rust/cloud-storage/teams/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json b/rust/cloud-storage/teams/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
new file mode 100644
index 0000000000..39180b3b0f
--- /dev/null
+++ b/rust/cloud-storage/teams/.sqlx/query-f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b.json
@@ -0,0 +1,15 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET deleted_at = NOW()\n WHERE user_id = $1 AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "f3e53dd531be738b881df199783a2beded3bd378038cbd6f012080ac77c5291b"
+}
diff --git a/rust/cloud-storage/teams/src/inbound/axum_router/remove_user_from_team.rs b/rust/cloud-storage/teams/src/inbound/axum_router/remove_user_from_team.rs
index 052a3e1210..d8af3b633c 100644
--- a/rust/cloud-storage/teams/src/inbound/axum_router/remove_user_from_team.rs
+++ b/rust/cloud-storage/teams/src/inbound/axum_router/remove_user_from_team.rs
@@ -1,6 +1,6 @@
use axum::extract::{Path, State};
+use macro_user_id::user_id::MacroUserIdStr;
use model_error_response::ErrorResponse;
-use model_user::axum_extractor::MacroUserExtractor;
use crate::domain::{model::RemoveUserFromTeamError, team_repo::TeamService};
@@ -12,7 +12,7 @@ pub struct Param {
/// The team ID.
pub team_id: uuid::Uuid,
/// The ID of the user to remove.
- pub remove_user_id: String,
+ pub remove_user_id: MacroUserIdStr<'static>,
}
/// Removes a user from a team.
@@ -35,15 +35,14 @@ pub struct Param {
pub async fn handler<T: TeamService>(
_access: TeamAccessRoleExtractor<super::middleware::OwnerRole, T>,
State(state): State<TeamRouterState<T>>,
- user_context: MacroUserExtractor,
Path(Param {
team_id,
- remove_user_id: _,
+ remove_user_id,
}): Path<Param>,
) -> Result<(), RemoveUserFromTeamError> {
state
.service
- .remove_user_from_team(&team_id, &user_context.macro_user_id)
+ .remove_user_from_team(&team_id, &remove_user_id)
.await?;
Ok(())
}
diff --git a/rust/cloud-storage/teams/src/outbound/team_repo.rs b/rust/cloud-storage/teams/src/outbound/team_repo.rs
index 84facb32bb..75e98d515d 100644
--- a/rust/cloud-storage/teams/src/outbound/team_repo.rs
+++ b/rust/cloud-storage/teams/src/outbound/team_repo.rs
@@ -592,7 +592,7 @@ impl TeamRepository for TeamRepositoryImpl {
team_role as "team_role!: TeamRole",
tier as "tier!: TeamUserTier"
FROM team_user
- WHERE team_id = $1 AND team_role NOT IN ('owner')
+ WHERE team_id = $1
"#,
team_id,
)
diff --git a/rust/cloud-storage/teams/src/outbound/team_repo/test.rs b/rust/cloud-storage/teams/src/outbound/team_repo/test.rs
index 79591ef378..cb4c0241ab 100644
--- a/rust/cloud-storage/teams/src/outbound/team_repo/test.rs
+++ b/rust/cloud-storage/teams/src/outbound/team_repo/test.rs
@@ -414,17 +414,18 @@ async fn test_get_team_members(pool: Pool<Postgres>) -> anyhow::Result<()> {
let members = team_repo.get_team_members(&team_id).await?;
- assert_eq!(members.len(), 1);
+ assert_eq!(members.len(), 2);
- let results = vec![("macro|[email protected]", TeamRole::Member)];
+ let expected = vec!["macro|[email protected]", "macro|[email protected]"];
- assert_eq!(
- members
- .iter()
- .map(|m| (m.user_id.as_ref(), m.role))
- .collect::<Vec<_>>(),
- results
- );
+ let mut results = members
+ .iter()
+ .map(|m| m.user_id.as_ref())
+ .collect::<Vec<&str>>();
+
+ results.sort();
+
+ assert_eq!(results, expected);
Ok(())
}