Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(teams): delete team github app association on team delete (#3713)

Will Hutchinson5d1d90e9e15b
diff --git a/rust/cloud-storage/.sqlx/query-62e6fee27bdd5c6fb4d7d7037977655784e36ba1b3285b607ff59d9d88829f7a.json b/rust/cloud-storage/.sqlx/query-62e6fee27bdd5c6fb4d7d7037977655784e36ba1b3285b607ff59d9d88829f7a.json
new file mode 100644
index 0000000000..ab0474981a
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-62e6fee27bdd5c6fb4d7d7037977655784e36ba1b3285b607ff59d9d88829f7a.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM github_app_installation\n WHERE source_id = $1\n AND source_type = 'team'::github_app_installation_source_type\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "62e6fee27bdd5c6fb4d7d7037977655784e36ba1b3285b607ff59d9d88829f7a"
+}
diff --git a/rust/cloud-storage/teams/src/outbound/team_repo.rs b/rust/cloud-storage/teams/src/outbound/team_repo.rs
index 2c86fffb54..37382e5af7 100644
--- a/rust/cloud-storage/teams/src/outbound/team_repo.rs
+++ b/rust/cloud-storage/teams/src/outbound/team_repo.rs
@@ -695,6 +695,8 @@ impl TeamRepository for TeamRepositoryImpl {
#[tracing::instrument(skip(self), err)]
async fn delete_team(&self, team_id: &uuid::Uuid) -> Result<(), TeamError> {
+ let mut transaction = self.pool.begin().await?;
+
sqlx::query!(
r#"
DELETE FROM team
@@ -702,9 +704,22 @@ impl TeamRepository for TeamRepositoryImpl {
"#,
team_id,
)
- .execute(&self.pool)
+ .execute(&mut *transaction)
.await?;
+ sqlx::query!(
+ r#"
+ DELETE FROM github_app_installation
+ WHERE source_id = $1
+ AND source_type = 'team'::github_app_installation_source_type
+ "#,
+ team_id.to_string(),
+ )
+ .execute(&mut *transaction)
+ .await?;
+
+ transaction.commit().await?;
+
Ok(())
}
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 43b200fe4c..a9b5c19bbf 100644
--- a/rust/cloud-storage/teams/src/outbound/team_repo/test.rs
+++ b/rust/cloud-storage/teams/src/outbound/team_repo/test.rs
@@ -868,6 +868,22 @@ async fn test_delete_team(pool: Pool<Postgres>) -> anyhow::Result<()> {
let team_repo = TeamRepositoryImpl::new(pool.clone());
let team_id = macro_uuid::string_to_uuid("11111111-1111-1111-1111-111111111111")?;
+ let team_source_id = team_id.to_string();
+ let other_team_source_id = "22222222-2222-2222-2222-222222222222";
+
+ sqlx::query!(
+ r#"
+ INSERT INTO github_app_installation (id, source_id, source_type)
+ VALUES
+ ('deleted-team-installation', $1, 'team'::github_app_installation_source_type),
+ ('same-source-user-installation', $1, 'user'::github_app_installation_source_type),
+ ('other-team-installation', $2, 'team'::github_app_installation_source_type)
+ "#,
+ &team_source_id,
+ other_team_source_id,
+ )
+ .execute(&pool)
+ .await?;
team_repo.delete_team(&team_id).await?;
@@ -884,6 +900,48 @@ async fn test_delete_team(pool: Pool<Postgres>) -> anyhow::Result<()> {
assert!(team.is_none());
+ let deleted_installation = sqlx::query!(
+ r#"
+ SELECT id
+ FROM github_app_installation
+ WHERE id = 'deleted-team-installation'
+ "#,
+ )
+ .fetch_optional(&pool)
+ .await?;
+
+ assert!(deleted_installation.is_none());
+
+ let remaining_installations = sqlx::query!(
+ r#"
+ SELECT id, source_id, source_type::text AS "source_type!"
+ FROM github_app_installation
+ WHERE id IN ('other-team-installation', 'same-source-user-installation')
+ ORDER BY id
+ "#,
+ )
+ .fetch_all(&pool)
+ .await?
+ .into_iter()
+ .map(|row| (row.id, row.source_id, row.source_type))
+ .collect::<Vec<_>>();
+
+ assert_eq!(
+ remaining_installations,
+ vec![
+ (
+ "other-team-installation".to_string(),
+ other_team_source_id.to_string(),
+ "team".to_string(),
+ ),
+ (
+ "same-source-user-installation".to_string(),
+ team_source_id,
+ "user".to_string(),
+ ),
+ ]
+ );
+
Ok(())
}