Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit bdccfd2

Browse files
Refactor arguments of try_unbind_threepid(_with_id_server) from dict to separate args (#15053)
1 parent c10e131 commit bdccfd2

5 files changed

Lines changed: 28 additions & 39 deletions

File tree

changelog.d/15053.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor arguments of `try_unbind_threepid` and `_try_unbind_threepid_with_id_server` to not use dictionaries.

synapse/handlers/auth.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,8 @@ async def delete_threepid(
15931593
if medium == "email":
15941594
address = canonicalise_email(address)
15951595

1596-
identity_handler = self.hs.get_identity_handler()
1597-
result = await identity_handler.try_unbind_threepid(
1598-
user_id, {"medium": medium, "address": address, "id_server": id_server}
1596+
result = await self.hs.get_identity_handler().try_unbind_threepid(
1597+
user_id, medium, address, id_server
15991598
)
16001599

16011600
await self.store.user_delete_threepid(user_id, medium, address)

synapse/handlers/deactivate_account.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,7 @@ async def deactivate_account(
106106
for threepid in threepids:
107107
try:
108108
result = await self._identity_handler.try_unbind_threepid(
109-
user_id,
110-
{
111-
"medium": threepid["medium"],
112-
"address": threepid["address"],
113-
"id_server": id_server,
114-
},
109+
user_id, threepid["medium"], threepid["address"], id_server
115110
)
116111
identity_server_supports_unbinding &= result
117112
except Exception:

synapse/handlers/identity.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,28 +219,31 @@ async def bind_threepid(
219219
data = json_decoder.decode(e.msg) # XXX WAT?
220220
return data
221221

222-
async def try_unbind_threepid(self, mxid: str, threepid: dict) -> bool:
223-
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all
224-
identity servers we're aware the binding is present on
222+
async def try_unbind_threepid(
223+
self, mxid: str, medium: str, address: str, id_server: Optional[str]
224+
) -> bool:
225+
"""Attempt to remove a 3PID from one or more identity servers.
225226
226227
Args:
227228
mxid: Matrix user ID of binding to be removed
228-
threepid: Dict with medium & address of binding to be
229-
removed, and an optional id_server.
229+
medium: The medium of the third-party ID.
230+
address: The address of the third-party ID.
231+
id_server: An identity server to attempt to unbind from. If None,
232+
attempt to remove the association from all identity servers
233+
known to potentially have it.
230234
231235
Raises:
232-
SynapseError: If we failed to contact the identity server
236+
SynapseError: If we failed to contact one or more identity servers.
233237
234238
Returns:
235-
True on success, otherwise False if the identity
236-
server doesn't support unbinding (or no identity server found to
237-
contact).
239+
True on success, otherwise False if the identity server doesn't
240+
support unbinding (or no identity server to contact was found).
238241
"""
239-
if threepid.get("id_server"):
240-
id_servers = [threepid["id_server"]]
242+
if id_server:
243+
id_servers = [id_server]
241244
else:
242245
id_servers = await self.store.get_id_servers_user_bound(
243-
user_id=mxid, medium=threepid["medium"], address=threepid["address"]
246+
mxid, medium, address
244247
)
245248

246249
# We don't know where to unbind, so we don't have a choice but to return
@@ -249,20 +252,21 @@ async def try_unbind_threepid(self, mxid: str, threepid: dict) -> bool:
249252

250253
changed = True
251254
for id_server in id_servers:
252-
changed &= await self.try_unbind_threepid_with_id_server(
253-
mxid, threepid, id_server
255+
changed &= await self._try_unbind_threepid_with_id_server(
256+
mxid, medium, address, id_server
254257
)
255258

256259
return changed
257260

258-
async def try_unbind_threepid_with_id_server(
259-
self, mxid: str, threepid: dict, id_server: str
261+
async def _try_unbind_threepid_with_id_server(
262+
self, mxid: str, medium: str, address: str, id_server: str
260263
) -> bool:
261264
"""Removes a binding from an identity server
262265
263266
Args:
264267
mxid: Matrix user ID of binding to be removed
265-
threepid: Dict with medium & address of binding to be removed
268+
medium: The medium of the third-party ID
269+
address: The address of the third-party ID
266270
id_server: Identity server to unbind from
267271
268272
Raises:
@@ -286,7 +290,7 @@ async def try_unbind_threepid_with_id_server(
286290

287291
content = {
288292
"mxid": mxid,
289-
"threepid": {"medium": threepid["medium"], "address": threepid["address"]},
293+
"threepid": {"medium": medium, "address": address},
290294
}
291295

292296
# we abuse the federation http client to sign the request, but we have to send it
@@ -319,12 +323,7 @@ async def try_unbind_threepid_with_id_server(
319323
except RequestTimedOutError:
320324
raise SynapseError(500, "Timed out contacting identity server")
321325

322-
await self.store.remove_user_bound_threepid(
323-
user_id=mxid,
324-
medium=threepid["medium"],
325-
address=threepid["address"],
326-
id_server=id_server,
327-
)
326+
await self.store.remove_user_bound_threepid(mxid, medium, address, id_server)
328327

329328
return changed
330329

synapse/rest/client/account.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
737737
# Attempt to unbind the threepid from an identity server. If id_server is None, try to
738738
# unbind from all identity servers this threepid has been added to in the past
739739
result = await self.identity_handler.try_unbind_threepid(
740-
requester.user.to_string(),
741-
{
742-
"address": body.address,
743-
"medium": body.medium,
744-
"id_server": body.id_server,
745-
},
740+
requester.user.to_string(), body.medium, body.address, body.id_server
746741
)
747742
return 200, {"id_server_unbind_result": "success" if result else "no-support"}
748743

0 commit comments

Comments
 (0)