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
fix(teams): delete pending team invites on autojoin (#5420)
Will Hutchinson91270bfe2169
diff --git a/.sqlx/query-6a17ce198d5a019a9d0a5e0bcb8cad99745bdd22ed1b3f20a5449a5d81f426f9.json b/.sqlx/query-6a17ce198d5a019a9d0a5e0bcb8cad99745bdd22ed1b3f20a5449a5d81f426f9.jsonnew file mode 100644index 0000000000..976a3c4b8f--- /dev/null+++ b/.sqlx/query-6a17ce198d5a019a9d0a5e0bcb8cad99745bdd22ed1b3f20a5449a5d81f426f9.json@@ -0,0 +1,15 @@+{+ "db_name": "PostgreSQL",+ "query": "\n DELETE FROM team_invite\n WHERE team_id = $1 AND email = $2\n ",+ "describe": {+ "columns": [],+ "parameters": {+ "Left": [+ "Uuid",+ "Text"+ ]+ },+ "nullable": []+ },+ "hash": "6a17ce198d5a019a9d0a5e0bcb8cad99745bdd22ed1b3f20a5449a5d81f426f9"+}diff --git a/crates/teams/src/domain/team_repo.rs b/crates/teams/src/domain/team_repo.rsindex 525236391a..5dbd5bfd38 100644--- a/crates/teams/src/domain/team_repo.rs+++ b/crates/teams/src/domain/team_repo.rs@@ -292,9 +292,10 @@ pub trait TeamRepository: Clone + Send + Sync + 'static {user_id: &MacroUserIdStr<'_>,) -> impl Future<Output = Result<Option<uuid::Uuid>, TeamError>> + Send;- /// Adds the user directly to the team as a member (no invite involved),- /// bumping the team's seat count. Returns None when the user is already- /// on the team.+ /// Adds the user directly to the team as a member without requiring an+ /// invite, removes any pending invite for that user and team, and bumps+ /// the team's seat count. Returns None when the user is already on the+ /// team.////// NOTE: this only touches team membership — billing, roles, and/// channel membership are handled by the service (seediff --git a/crates/teams/src/outbound/team_repo.rs b/crates/teams/src/outbound/team_repo.rsindex 2071c62190..b4c442e64a 100644--- a/crates/teams/src/outbound/team_repo.rs+++ b/crates/teams/src/outbound/team_repo.rs@@ -1499,11 +1499,23 @@ impl TeamRepository for TeamRepositoryImpl {.execute(&mut *transaction).await?;- // Already a member — nothing was added, so don't touch the seat count.+ // Already a member — nothing was added, so don't touch the invite or seat count.if inserted.rows_affected() == 0 {return Ok(None);}+ let user_email = user_id.email_part().lowercase();+ sqlx::query!(+ r#"+ DELETE FROM team_invite+ WHERE team_id = $1 AND email = $2+ "#,+ team_id,+ user_email.as_ref(),+ )+ .execute(&mut *transaction)+ .await?;+TeamRepositoryImpl::bump_seat_count(&mut transaction, team_id, 1).await?;transaction.commit().await?;diff --git a/crates/teams/src/outbound/team_repo/test.rs b/crates/teams/src/outbound/team_repo/test.rsindex 4445066def..fe1a79d883 100644--- a/crates/teams/src/outbound/team_repo/test.rs+++ b/crates/teams/src/outbound/team_repo/test.rs@@ -1688,6 +1688,12 @@ async fn test_add_user_to_team(pool: Pool<Postgres>) -> anyhow::Result<()> {let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;let seat_count_before = team_repo.get_team_seat_count(&team_id).await?;+ let invites_before = team_repo.get_user_team_invites(&user_id).await?;+ assert!(+ invites_before+ .iter()+ .any(|invite| invite.team_id == team_id)+ );let member = team_repo.add_user_to_team(&team_id, &user_id)@@ -1704,6 +1710,9 @@ async fn test_add_user_to_team(pool: Pool<Postgres>) -> anyhow::Result<()> {let seat_count = team_repo.get_team_seat_count(&team_id).await?;assert_eq!(seat_count, seat_count_before + 1);+ let invites_after = team_repo.get_user_team_invites(&user_id).await?;+ assert!(!invites_after.iter().any(|invite| invite.team_id == team_id));+// Adding again is a no-op: no member returned, no extra seat counted.let member = team_repo.add_user_to_team(&team_id, &user_id).await?;assert!(member.is_none());