From f17e4801b821c00dc36db6ca60aab491e0286064 Mon Sep 17 00:00:00 2001 From: danielaloni Date: Wed, 26 Oct 2022 15:10:41 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Delete=203PID=20association?= =?UTF-8?q?=20upon=20deactivating=20user.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userapi/internal/api.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/userapi/internal/api.go b/userapi/internal/api.go index 2f7795dfe..3414747af 100644 --- a/userapi/internal/api.go +++ b/userapi/internal/api.go @@ -549,14 +549,24 @@ func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *a return err } - pusherReq := &api.PerformPusherDeletionRequest{ - Localpart: req.Localpart, - } - if err := a.PerformPusherDeletion(ctx, pusherReq, &struct{}{}); err != nil { + threepids, err := a.DB.GetThreePIDsForLocalpart(ctx, req.Localpart) + if err != nil { return err } - err := a.DB.DeactivateAccount(ctx, req.Localpart) + err = a.DB.RemoveThreePIDAssociation(ctx, threepids[0].Address, threepids[0].Medium) + if err != nil { + return err + } + + pusherReq := &api.PerformPusherDeletionRequest{ + Localpart: req.Localpart, + } + if err = a.PerformPusherDeletion(ctx, pusherReq, &struct{}{}); err != nil { + return err + } + + err = a.DB.DeactivateAccount(ctx, req.Localpart) res.AccountDeactivated = err == nil return err } From d1f3bf502e3fce9d01d46330f140a4e28da8e146 Mon Sep 17 00:00:00 2001 From: danielaloni Date: Mon, 31 Oct 2022 13:17:36 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Remove=20all=203pids=20and?= =?UTF-8?q?=20not=20just=20the=20first=20one.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userapi/internal/api.go | 9 +++++---- userapi/storage/storage_test.go | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/userapi/internal/api.go b/userapi/internal/api.go index ae4a69739..e22081a2f 100644 --- a/userapi/internal/api.go +++ b/userapi/internal/api.go @@ -553,10 +553,11 @@ func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *a if err != nil { return err } - - err = a.DB.RemoveThreePIDAssociation(ctx, threepids[0].Address, threepids[0].Medium) - 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{ diff --git a/userapi/storage/storage_test.go b/userapi/storage/storage_test.go index 42e35d1ab..53c51416b 100644 --- a/userapi/storage/storage_test.go +++ b/userapi/storage/storage_test.go @@ -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")