Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
901b1fa5
Unverified
Commit
901b1fa5
authored
4 years ago
by
Dirk Klimpel
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Email notifications for new users when creating via the Admin API. (#7267)
parent
df8a3cef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/7267.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/7267.bugfix
synapse/rest/admin/users.py
+16
-0
16 additions, 0 deletions
synapse/rest/admin/users.py
tests/rest/admin/test_user.py
+75
-0
75 additions, 0 deletions
tests/rest/admin/test_user.py
with
92 additions
and
0 deletions
changelog.d/7267.bugfix
0 → 100644
+
1
−
0
View file @
901b1fa5
Fix email notifications not being enabled for new users when created via the Admin API.
This diff is collapsed.
Click to expand it.
synapse/rest/admin/users.py
+
16
−
0
View file @
901b1fa5
...
...
@@ -142,6 +142,7 @@ class UserRestServletV2(RestServlet):
self
.
set_password_handler
=
hs
.
get_set_password_handler
()
self
.
deactivate_account_handler
=
hs
.
get_deactivate_account_handler
()
self
.
registration_handler
=
hs
.
get_registration_handler
()
self
.
pusher_pool
=
hs
.
get_pusherpool
()
async
def
on_GET
(
self
,
request
,
user_id
):
await
assert_requester_is_admin
(
self
.
auth
,
request
)
...
...
@@ -281,6 +282,21 @@ class UserRestServletV2(RestServlet):
await
self
.
auth_handler
.
add_threepid
(
user_id
,
threepid
[
"
medium
"
],
threepid
[
"
address
"
],
current_time
)
if
(
self
.
hs
.
config
.
email_enable_notifs
and
self
.
hs
.
config
.
email_notif_for_new_users
):
await
self
.
pusher_pool
.
add_pusher
(
user_id
=
user_id
,
access_token
=
None
,
kind
=
"
email
"
,
app_id
=
"
m.email
"
,
app_display_name
=
"
Email Notifications
"
,
device_display_name
=
threepid
[
"
address
"
],
pushkey
=
threepid
[
"
address
"
],
lang
=
None
,
# We don't know a user's language here
data
=
{},
)
if
"
avatar_url
"
in
body
and
type
(
body
[
"
avatar_url
"
])
==
str
:
await
self
.
profile_handler
.
set_avatar_url
(
...
...
This diff is collapsed.
Click to expand it.
tests/rest/admin/test_user.py
+
75
−
0
View file @
901b1fa5
...
...
@@ -516,6 +516,81 @@ class UserRestTestCase(unittest.HomeserverTestCase):
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
"
:
"
bob@bob.bob
"
}],
}
)
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
(
"
bob@bob.bob
"
,
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
"
:
"
bob@bob.bob
"
}],
}
)
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
(
"
bob@bob.bob
"
,
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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment