Refactor arguments of try_unbind_threepid(_with_id_server) from dict to separate args (#15053)

This commit is contained in:
Andrew Morgan 2023-02-13 12:12:48 +00:00 committed by GitHub
parent c10e131250
commit bdccfd2477
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 39 deletions

1
changelog.d/15053.misc Normal file
View file

@ -0,0 +1 @@
Refactor arguments of `try_unbind_threepid` and `_try_unbind_threepid_with_id_server` to not use dictionaries.

View file

@ -1593,9 +1593,8 @@ class AuthHandler:
if medium == "email": if medium == "email":
address = canonicalise_email(address) address = canonicalise_email(address)
identity_handler = self.hs.get_identity_handler() result = await self.hs.get_identity_handler().try_unbind_threepid(
result = await identity_handler.try_unbind_threepid( user_id, medium, address, id_server
user_id, {"medium": medium, "address": address, "id_server": id_server}
) )
await self.store.user_delete_threepid(user_id, medium, address) await self.store.user_delete_threepid(user_id, medium, address)

View file

@ -106,12 +106,7 @@ class DeactivateAccountHandler:
for threepid in threepids: for threepid in threepids:
try: try:
result = await self._identity_handler.try_unbind_threepid( result = await self._identity_handler.try_unbind_threepid(
user_id, user_id, threepid["medium"], threepid["address"], id_server
{
"medium": threepid["medium"],
"address": threepid["address"],
"id_server": id_server,
},
) )
identity_server_supports_unbinding &= result identity_server_supports_unbinding &= result
except Exception: except Exception:

View file

@ -219,28 +219,31 @@ class IdentityHandler:
data = json_decoder.decode(e.msg) # XXX WAT? data = json_decoder.decode(e.msg) # XXX WAT?
return data return data
async def try_unbind_threepid(self, mxid: str, threepid: dict) -> bool: async def try_unbind_threepid(
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all self, mxid: str, medium: str, address: str, id_server: Optional[str]
identity servers we're aware the binding is present on ) -> bool:
"""Attempt to remove a 3PID from one or more identity servers.
Args: Args:
mxid: Matrix user ID of binding to be removed mxid: Matrix user ID of binding to be removed
threepid: Dict with medium & address of binding to be medium: The medium of the third-party ID.
removed, and an optional id_server. address: The address of the third-party ID.
id_server: An identity server to attempt to unbind from. If None,
attempt to remove the association from all identity servers
known to potentially have it.
Raises: Raises:
SynapseError: If we failed to contact the identity server SynapseError: If we failed to contact one or more identity servers.
Returns: Returns:
True on success, otherwise False if the identity True on success, otherwise False if the identity server doesn't
server doesn't support unbinding (or no identity server found to support unbinding (or no identity server to contact was found).
contact).
""" """
if threepid.get("id_server"): if id_server:
id_servers = [threepid["id_server"]] id_servers = [id_server]
else: else:
id_servers = await self.store.get_id_servers_user_bound( id_servers = await self.store.get_id_servers_user_bound(
user_id=mxid, medium=threepid["medium"], address=threepid["address"] mxid, medium, address
) )
# We don't know where to unbind, so we don't have a choice but to return # We don't know where to unbind, so we don't have a choice but to return
@ -249,20 +252,21 @@ class IdentityHandler:
changed = True changed = True
for id_server in id_servers: for id_server in id_servers:
changed &= await self.try_unbind_threepid_with_id_server( changed &= await self._try_unbind_threepid_with_id_server(
mxid, threepid, id_server mxid, medium, address, id_server
) )
return changed return changed
async def try_unbind_threepid_with_id_server( async def _try_unbind_threepid_with_id_server(
self, mxid: str, threepid: dict, id_server: str self, mxid: str, medium: str, address: str, id_server: str
) -> bool: ) -> bool:
"""Removes a binding from an identity server """Removes a binding from an identity server
Args: Args:
mxid: Matrix user ID of binding to be removed mxid: Matrix user ID of binding to be removed
threepid: Dict with medium & address of binding to be removed medium: The medium of the third-party ID
address: The address of the third-party ID
id_server: Identity server to unbind from id_server: Identity server to unbind from
Raises: Raises:
@ -286,7 +290,7 @@ class IdentityHandler:
content = { content = {
"mxid": mxid, "mxid": mxid,
"threepid": {"medium": threepid["medium"], "address": threepid["address"]}, "threepid": {"medium": medium, "address": address},
} }
# we abuse the federation http client to sign the request, but we have to send it # we abuse the federation http client to sign the request, but we have to send it
@ -319,12 +323,7 @@ class IdentityHandler:
except RequestTimedOutError: except RequestTimedOutError:
raise SynapseError(500, "Timed out contacting identity server") raise SynapseError(500, "Timed out contacting identity server")
await self.store.remove_user_bound_threepid( await self.store.remove_user_bound_threepid(mxid, medium, address, id_server)
user_id=mxid,
medium=threepid["medium"],
address=threepid["address"],
id_server=id_server,
)
return changed return changed

View file

@ -737,12 +737,7 @@ class ThreepidUnbindRestServlet(RestServlet):
# Attempt to unbind the threepid from an identity server. If id_server is None, try to # Attempt to unbind the threepid from an identity server. If id_server is None, try to
# unbind from all identity servers this threepid has been added to in the past # unbind from all identity servers this threepid has been added to in the past
result = await self.identity_handler.try_unbind_threepid( result = await self.identity_handler.try_unbind_threepid(
requester.user.to_string(), requester.user.to_string(), body.medium, body.address, body.id_server
{
"address": body.address,
"medium": body.medium,
"id_server": body.id_server,
},
) )
return 200, {"id_server_unbind_result": "success" if result else "no-support"} return 200, {"id_server_unbind_result": "success" if result else "no-support"}