π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server][contacts] revive deleted contacts on update
Neeraj Guptac46dca1e86b9
diff --git a/server/pkg/controller/contact/controller_test.go b/server/pkg/controller/contact/controller_test.goindex 8ccae19b7e..c499ea75bd 100644--- a/server/pkg/controller/contact/controller_test.go+++ b/server/pkg/controller/contact/controller_test.go@@ -329,6 +329,40 @@ func TestContactCRUDAndDiff(t *testing.T) {}}+func TestUpdateRevivesDeletedContact(t *testing.T) {+ ctrl, db, ctx, _ := setupContactControllerTest(t)+ mustInsertTestUser(t, db, 1)++ created := createContactForTest(t, db, ctrl, ctx, 31, "wrapped-key-1", "payload-1")+ if err := ctrl.Delete(ctx, created.ID); err != nil {+ t.Fatalf("Delete() error = %v", err)+ }++ mustInsertTestUser(t, db, 32)+ mustInsertEmergencyContact(t, db, 1, 32, ente.UserInvitedContact)++ revived, err := ctrl.Update(ctx, created.ID, contactmodel.UpdateRequest{+ ContactUserID: 32,+ EncryptedData: []byte("payload-2"),+ })+ if err != nil {+ t.Fatalf("Update() revive error = %v", err)+ }+ if revived.IsDeleted {+ t.Fatal("revived contact should not remain deleted")+ }+ if revived.ContactUserID != 32 {+ t.Fatalf("revived contactUserID = %d, want 32", revived.ContactUserID)+ }+ if revived.EncryptedData == nil || string(*revived.EncryptedData) != "payload-2" {+ t.Fatalf("revived encrypted data = %v, want payload-2", revived.EncryptedData)+ }+ expectedEmail := "[email protected]"+ if revived.Email == nil || *revived.Email != expectedEmail {+ t.Fatalf("revived email = %v, want %q", revived.Email, expectedEmail)+ }+}+func TestCreateContactRejectsDuplicateContactUserID(t *testing.T) {ctrl, db, ctx, _ := setupContactControllerTest(t)mustInsertTestUser(t, db, 1)diff --git a/server/pkg/repo/contact/contact.go b/server/pkg/repo/contact/contact.goindex 955ae98db2..82995ffa99 100644--- a/server/pkg/repo/contact/contact.go+++ b/server/pkg/repo/contact/contact.go@@ -183,8 +183,10 @@ func (r *Repository) Update(ctx context.Context, userID int64, id string, req coresult, err := r.DB.ExecContext(ctx,`UPDATE contact_entity- SET contact_user_id = $1, encrypted_data = $2- WHERE id = $3 AND user_id = $4 AND is_deleted = FALSE`,+ SET contact_user_id = $1,+ encrypted_data = $2,+ is_deleted = FALSE+ WHERE id = $3 AND user_id = $4`,req.ContactUserID,req.EncryptedData,id,@@ -207,13 +209,9 @@ func (r *Repository) Update(ctx context.Context, userID int64, id string, req coif rowsAffected == 1 {return nil}- entity, getErr := r.Get(ctx, userID, id)- if getErr != nil {+ if _, getErr := r.Get(ctx, userID, id); getErr != nil {return stacktrace.Propagate(getErr, "failed to fetch contact after update miss")}- if entity.IsDeleted {- return stacktrace.Propagate(ente.NewBadRequestWithMessage("contact is already deleted"), "")- }return stacktrace.NewError("exactly one row should be updated")}