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

Commit 0312ff4

Browse files
thomasweston12Thomas WestonDMRobertson
authored
Fix "add user" admin api error when request contains a "msisdn" threepid (#13263)
Co-authored-by: Thomas Weston <[email protected]> Co-authored-by: David Robertson <[email protected]>
1 parent 1381563 commit 0312ff4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

changelog.d/13263.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.15.0 where adding a user through the Synapse Admin API with a phone number would fail if the "enable_email_notifs" and "email_notifs_for_new_users" options were enabled. Contributed by @thomasweston12.

synapse/rest/admin/users.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ async def on_PUT(
373373
if (
374374
self.hs.config.email.email_enable_notifs
375375
and self.hs.config.email.email_notif_for_new_users
376+
and medium == "email"
376377
):
377378
await self.pusher_pool.add_pusher(
378379
user_id=user_id,

tests/rest/admin/test_user.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,41 @@ def test_create_user_email_no_notif_for_new_users(self) -> None:
16361636
)
16371637
self.assertEqual(len(pushers), 0)
16381638

1639+
@override_config(
1640+
{
1641+
"email": {
1642+
"enable_notifs": True,
1643+
"notif_for_new_users": True,
1644+
"notif_from": "[email protected]",
1645+
},
1646+
"public_baseurl": "https://example.com",
1647+
}
1648+
)
1649+
def test_create_user_email_notif_for_new_users_with_msisdn_threepid(self) -> None:
1650+
"""
1651+
Check that a new regular user is created successfully when they have a msisdn
1652+
threepid and email notif_for_new_users is set to True.
1653+
"""
1654+
url = self.url_prefix % "@bob:test"
1655+
1656+
# Create user
1657+
body = {
1658+
"password": "abc123",
1659+
"threepids": [{"medium": "msisdn", "address": "1234567890"}],
1660+
}
1661+
1662+
channel = self.make_request(
1663+
"PUT",
1664+
url,
1665+
access_token=self.admin_user_tok,
1666+
content=body,
1667+
)
1668+
1669+
self.assertEqual(201, channel.code, msg=channel.json_body)
1670+
self.assertEqual("@bob:test", channel.json_body["name"])
1671+
self.assertEqual("msisdn", channel.json_body["threepids"][0]["medium"])
1672+
self.assertEqual("1234567890", channel.json_body["threepids"][0]["address"])
1673+
16391674
def test_set_password(self) -> None:
16401675
"""
16411676
Test setting a new password for another user.

0 commit comments

Comments
 (0)