From 68a9ea3ec26e79317985e50ffa249e494cbe484d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 1 Feb 2023 17:38:43 +0000 Subject: [PATCH] Refactor deactivate code to use AuthHandler's delete_threepid method This deduplicates some code, as well as has the side-effect of ensuring Synapse modules are informed of a 3PID deletion even during user deactivation. --- synapse/handlers/deactivate_account.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/synapse/handlers/deactivate_account.py b/synapse/handlers/deactivate_account.py index d74d135c0c..aea0f8b7c2 100644 --- a/synapse/handlers/deactivate_account.py +++ b/synapse/handlers/deactivate_account.py @@ -100,30 +100,20 @@ class DeactivateAccountHandler: # unbinding identity_server_supports_unbinding = True - # Retrieve the 3PIDs this user has bound to an identity server - threepids = await self.store.user_get_bound_threepids(user_id) - + # Remove any threepids associated with this account locally and attempt to + # unbind them from identity server(s). + threepids = await self.store.user_get_threepids(user_id) for threepid in threepids: try: - result = await self._identity_handler.try_unbind_threepid( - user_id, - { - "medium": threepid["medium"], - "address": threepid["address"], - "id_server": id_server, - }, + result = await self._auth_handler.delete_threepid( + user_id, threepid["medium"], threepid["address"], id_server ) - identity_server_supports_unbinding &= result except Exception: # Do we want this to be a fatal error or should we carry on? logger.exception("Failed to remove threepid from ID server") raise SynapseError(400, "Failed to remove threepid from ID server") - await self.store.user_delete_threepid( - user_id, threepid["medium"], threepid["address"] - ) - # Remove all 3PIDs this user has bound to the homeserver - await self.store.user_delete_threepids(user_id) + identity_server_supports_unbinding &= result # delete any devices belonging to the user, which will also # delete corresponding access tokens.