Browse Source

Revert "Delete threepid assocs on unbind and remove existing with migration (#213)"

This reverts commits 04ac50230d577694dffc8be4d9349e24042b93fb and 0e01574970a8d582f57de35e4da2293721551697.
Richard van der Hoff 4 years ago
parent
commit
969d57e737

+ 0 - 1
CHANGELOG.md

@@ -12,7 +12,6 @@ Unreleased changes
  * Handle .well-known files when talking to homeservers
  * Fix a bug where multiple cleanup tasks would be unnecessary spawned
  * Fix logging so Sydent doesn't log 3PIDs when processing lookup requests
- * Correctly delete 3pid associations on unbind. [#213](https://github.com/matrix-org/sydent/pull/213)
  * Fix incorrect HTTP response from `/3pid/getValidated3pid` endpoint on
    failure. [#216](https://github.com/matrix-org/sydent/pull/216)
 

+ 0 - 11
sydent/db/sqlitedb.py

@@ -186,17 +186,6 @@ class SqliteDatabase:
             logger.info("v3 -> v4 schema migration complete")
             self._setSchemaVersion(4)
 
-        if curVer < 5:
-            # Remove all associations from the database that have a NULL MXID
-            # We set the MXID to NULL when we removed the binding but we've switched it to
-            # removing the whole row to minimize personal information
-            # https://github.com/matrix-org/sydent/issues/192
-            cur = self.db.cursor()
-            cur.execute("DELETE FROM local_threepid_associations WHERE mxid IS NULL")
-            self.db.commit()
-            logger.info("v4 -> v5 schema migration complete")
-            self._setSchemaVersion(5)
-
     def _getSchemaVersion(self):
         cur = self.db.cursor()
         res = cur.execute("PRAGMA user_version");

+ 7 - 5
sydent/db/threepid_associations.py

@@ -80,14 +80,16 @@ class LocalAssociationStore:
         )
         row = cur.fetchone()
         if row[0] > 0:
+            ts = time_msec()
             cur.execute(
-                "DELETE FROM local_threepid_associations "
-                " WHERE medium = ? AND address = ?",
-                (threepid['medium'], threepid['address']),
+                "REPLACE INTO local_threepid_associations "
+                "('medium', 'address', 'mxid', 'ts', 'notBefore', 'notAfter') "
+                " values (?, ?, NULL, ?, null, null)",
+                (threepid['medium'], threepid['address'], ts),
             )
             logger.info(
-                "Deleting local assoc for %s/%s/%s",
-                threepid['medium'], threepid['address'], mxid,
+                "Deleting local assoc for %s/%s/%s replaced %d rows",
+                threepid['medium'], threepid['address'], mxid, cur.rowcount,
             )
             self.sydent.db.commit()
         else:

+ 1 - 1
sydent/http/servlets/threepidunbindservlet.py

@@ -144,7 +144,7 @@ class ThreePidUnbindServlet(Resource):
                     request.finish()
                     return
 
-            self.sydent.threepidBinder.removeBinding(threepid, mxid)
+            res = self.sydent.threepidBinder.removeBinding(threepid, mxid)
 
             request.write(json.dumps({}))
             request.finish()