Phase 13, part 8: a team's data is theirs
The owner exports everything from Settings → Your data (the keys only with their password), and can delete the team: it closes at once, everyone in it is told, it can be undone for 30 days, and then its schema, files, agents and memberships go for good. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -197,3 +197,27 @@ func TeamCounts(d *db.DB, team int64) (members, invited int, err error) {
|
||||
WHERE m.team_id = ? AND u.kind = 'person'`, team).Scan(&members, &invited)
|
||||
return members, invited, err
|
||||
}
|
||||
|
||||
// DeleteTeam forgets a team: its memberships, its sessions, and its row
|
||||
// (its schema is the caller's to drop). People in no other team keep their
|
||||
// account.
|
||||
func DeleteTeam(d *db.DB, id int64) error {
|
||||
tx, err := d.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
// Its agents belong to it alone.
|
||||
if _, err := tx.Exec(`DELETE FROM agent_keys WHERE user_id IN (SELECT user_id FROM memberships m JOIN users u ON u.id = m.user_id WHERE m.team_id = ? AND u.kind = 'agent')`, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(`DELETE FROM users WHERE kind = 'agent' AND id IN (SELECT user_id FROM memberships WHERE team_id = ?)`, id); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, q := range []string{`DELETE FROM sessions WHERE team_id = ?`, `DELETE FROM memberships WHERE team_id = ?`, `DELETE FROM teams WHERE id = ?`} {
|
||||
if _, err := tx.Exec(q, id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user