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

Admin api to add an email address #6789

Merged
merged 9 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,14 @@ def delete_access_tokens_for_user(

@defer.inlineCallbacks
def add_threepid(self, user_id, medium, address, validated_at):
# check if medium has a valid value
if medium not in ["email", "msisdn"]:
raise SynapseError(
code=400,
msg=("'%s' is not a valid value for 'medium'" % (medium)),
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
errcode=Codes.INVALID_PARAM,
)

# 'Canonicalise' email addresses down to lower case.
# We've now moving towards the homeserver being the entity that
# is responsible for validating threepids used for resetting passwords
Expand Down
8 changes: 8 additions & 0 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ async def on_PUT(self, request, user_id):
)

if "threepids" in body:
# check for required parameters for each threepid
for threepid in body["threepids"]:
assert_params_in_dict(threepid, ["medium", "address"])

# remove old threepids from user
threepids = await self.store.user_get_threepids(user_id)
for threepid in threepids:
Expand Down Expand Up @@ -257,6 +261,10 @@ async def on_PUT(self, request, user_id):
)

if "threepids" in body:
# check for required parameters for each threepid
for threepid in body["threepids"]:
assert_params_in_dict(threepid, ["medium", "address"])

current_time = self.hs.get_clock().time_msec()
for threepid in body["threepids"]:
await self.auth_handler.add_threepid(
Expand Down
2 changes: 0 additions & 2 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,6 @@ def test_requester_is_admin(self):
self.assertEqual("foobar", channel.json_body["displayname"])
self.assertEqual(True, channel.json_body["deactivated"])
# the user is deactivated, the threepid will be deleted
# self.assertEqual("email", channel.json_body["threepids"][0]["medium"])
# self.assertEqual("bob2@bob.bob", channel.json_body["threepids"][0]["address"])

# Get user
request, channel = self.make_request(
Expand Down