Merge pull request #46 from globekeeper/fix/GK-3226884592

🐛 Delete 3PID association upon deactivating user
This commit is contained in:
Daniel Aloni 2022-10-31 17:00:10 +02:00 committed by GitHub
commit 49a93736ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -549,14 +549,25 @@ func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *a
return err
}
threepids, err := a.DB.GetThreePIDsForLocalpart(ctx, req.Localpart)
if err != nil {
return err
}
for i := 0; i < len(threepids); i++ {
err = a.DB.RemoveThreePIDAssociation(ctx, threepids[i].Address, threepids[i].Medium)
if err != nil {
return err
}
}
pusherReq := &api.PerformPusherDeletionRequest{
Localpart: req.Localpart,
}
if err := a.PerformPusherDeletion(ctx, pusherReq, &struct{}{}); err != nil {
if err = a.PerformPusherDeletion(ctx, pusherReq, &struct{}{}); err != nil {
return err
}
err := a.DB.DeactivateAccount(ctx, req.Localpart)
err = a.DB.DeactivateAccount(ctx, req.Localpart)
res.AccountDeactivated = err == nil
return err
}

View file

@ -128,6 +128,11 @@ func Test_Accounts(t *testing.T) {
_, err = db.GetAccountByPassword(ctx, aliceLocalpart, "newPassword")
assert.Error(t, err, "expected an error, got none")
// This should return an empty slice, as the account is deactivated and the 3pid is unbound
threepids, err := db.GetThreePIDsForLocalpart(ctx, aliceLocalpart)
assert.NoError(t, err, "failed to get 3pid for account")
assert.Equal(t, len(threepids), 0)
_, err = db.GetAccountByLocalpart(ctx, "unusename")
assert.Error(t, err, "expected an error for non existent localpart")