forked from matrix-org/synapse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email notifications for new users when creating via the Admin API. (m…
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix email notifications not being enabled for new users when created via the Admin API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -516,6 +516,81 @@ def test_create_user(self): | |
self.assertEqual(False, channel.json_body["is_guest"]) | ||
self.assertEqual(False, channel.json_body["deactivated"]) | ||
|
||
def test_create_user_email_notif_for_new_users(self): | ||
""" | ||
Check that a new regular user is created successfully and | ||
got an email pusher. | ||
""" | ||
self.hs.config.registration_shared_secret = None | ||
self.hs.config.email_enable_notifs = True | ||
self.hs.config.email_notif_for_new_users = True | ||
url = "/_synapse/admin/v2/users/@bob:test" | ||
|
||
# Create user | ||
body = json.dumps( | ||
{ | ||
"password": "abc123", | ||
"threepids": [{"medium": "email", "address": "[email protected]"}], | ||
} | ||
) | ||
|
||
request, channel = self.make_request( | ||
"PUT", | ||
url, | ||
access_token=self.admin_user_tok, | ||
content=body.encode(encoding="utf_8"), | ||
) | ||
self.render(request) | ||
|
||
self.assertEqual(201, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual("@bob:test", channel.json_body["name"]) | ||
self.assertEqual("email", channel.json_body["threepids"][0]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
|
||
pushers = self.get_success( | ||
self.store.get_pushers_by({"user_name": "@bob:test"}) | ||
) | ||
pushers = list(pushers) | ||
self.assertEqual(len(pushers), 1) | ||
self.assertEqual("@bob:test", pushers[0]["user_name"]) | ||
|
||
def test_create_user_email_no_notif_for_new_users(self): | ||
""" | ||
Check that a new regular user is created successfully and | ||
got not an email pusher. | ||
""" | ||
self.hs.config.registration_shared_secret = None | ||
self.hs.config.email_enable_notifs = False | ||
self.hs.config.email_notif_for_new_users = False | ||
url = "/_synapse/admin/v2/users/@bob:test" | ||
|
||
# Create user | ||
body = json.dumps( | ||
{ | ||
"password": "abc123", | ||
"threepids": [{"medium": "email", "address": "[email protected]"}], | ||
} | ||
) | ||
|
||
request, channel = self.make_request( | ||
"PUT", | ||
url, | ||
access_token=self.admin_user_tok, | ||
content=body.encode(encoding="utf_8"), | ||
) | ||
self.render(request) | ||
|
||
self.assertEqual(201, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual("@bob:test", channel.json_body["name"]) | ||
self.assertEqual("email", channel.json_body["threepids"][0]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
|
||
pushers = self.get_success( | ||
self.store.get_pushers_by({"user_name": "@bob:test"}) | ||
) | ||
pushers = list(pushers) | ||
self.assertEqual(len(pushers), 0) | ||
|
||
def test_set_password(self): | ||
""" | ||
Test setting a new password for another user. | ||
|