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

Fix "add user" admin api error when request contains a "msisdn" threepid #13263

Merged
merged 4 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13263.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix error when adding a User through the Synapse Admin API with a "msisdn" threepid, when "enable_email_notifs" and "email_notifs_for_new_users" are both enabled. Contributed by @thomasweston12.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ async def on_PUT(
if (
self.hs.config.email.email_enable_notifs
and self.hs.config.email.email_notif_for_new_users
and medium == "email"
):
await self.pusher_pool.add_pusher(
user_id=user_id,
Expand Down
35 changes: 35 additions & 0 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,41 @@ def test_create_user_email_no_notif_for_new_users(self) -> None:
)
self.assertEqual(len(pushers), 0)

@override_config(
{
"email": {
"enable_notifs": True,
"notif_for_new_users": True,
"notif_from": "[email protected]",
},
"public_baseurl": "https://example.com",
}
)
def test_create_user_email_notif_for_new_users_with_msisdn_threepid(self) -> None:
"""
Check that a new regular user is created successfully when they have a msisdn
threepid and email notif_for_new_users is set to True.
"""
url = self.url_prefix % "@bob:test"

# Create user
body = {
"password": "abc123",
"threepids": [{"medium": "msisdn", "address": "1234567890"}],
}

channel = self.make_request(
"PUT",
url,
access_token=self.admin_user_tok,
content=body,
)

self.assertEqual(201, channel.code, msg=channel.json_body)
self.assertEqual("@bob:test", channel.json_body["name"])
self.assertEqual("msisdn", channel.json_body["threepids"][0]["medium"])
self.assertEqual("1234567890", channel.json_body["threepids"][0]["address"])

def test_set_password(self) -> None:
"""
Test setting a new password for another user.
Expand Down