This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove not needed database updates in modify user admin API (#10627)
- Loading branch information
Showing
5 changed files
with
118 additions
and
33 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 @@ | ||
Remove not needed database updates in modify user 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
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 |
---|---|---|
|
@@ -754,16 +754,18 @@ async def get_user_id_by_threepid(self, medium: str, address: str) -> Optional[s | |
) | ||
return user_id | ||
|
||
def get_user_id_by_threepid_txn(self, txn, medium, address): | ||
def get_user_id_by_threepid_txn( | ||
self, txn, medium: str, address: str | ||
) -> Optional[str]: | ||
"""Returns user id from threepid | ||
Args: | ||
txn (cursor): | ||
medium (str): threepid medium e.g. email | ||
address (str): threepid address e.g. [email protected] | ||
medium: threepid medium e.g. email | ||
address: threepid address e.g. [email protected] | ||
Returns: | ||
str|None: user id or None if no user id/threepid mapping exists | ||
user id, or None if no user id/threepid mapping exists | ||
""" | ||
ret = self.db_pool.simple_select_one_txn( | ||
txn, | ||
|
@@ -776,22 +778,31 @@ def get_user_id_by_threepid_txn(self, txn, medium, address): | |
return ret["user_id"] | ||
return None | ||
|
||
async def user_add_threepid(self, user_id, medium, address, validated_at, added_at): | ||
async def user_add_threepid( | ||
self, | ||
user_id: str, | ||
medium: str, | ||
address: str, | ||
validated_at: int, | ||
added_at: int, | ||
) -> None: | ||
await self.db_pool.simple_upsert( | ||
"user_threepids", | ||
{"medium": medium, "address": address}, | ||
{"user_id": user_id, "validated_at": validated_at, "added_at": added_at}, | ||
) | ||
|
||
async def user_get_threepids(self, user_id): | ||
async def user_get_threepids(self, user_id) -> List[Dict[str, Any]]: | ||
return await self.db_pool.simple_select_list( | ||
"user_threepids", | ||
{"user_id": user_id}, | ||
["medium", "address", "validated_at", "added_at"], | ||
"user_get_threepids", | ||
) | ||
|
||
async def user_delete_threepid(self, user_id, medium, address) -> None: | ||
async def user_delete_threepid( | ||
self, user_id: str, medium: str, address: str | ||
) -> None: | ||
await self.db_pool.simple_delete( | ||
"user_threepids", | ||
keyvalues={"user_id": user_id, "medium": medium, "address": address}, | ||
|
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 |
---|---|---|
|
@@ -1431,12 +1431,14 @@ def test_create_user(self): | |
self.assertEqual("Bob's name", channel.json_body["displayname"]) | ||
self.assertEqual("email", channel.json_body["threepids"][0]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
self.assertEqual(1, len(channel.json_body["threepids"])) | ||
self.assertEqual( | ||
"external_id1", channel.json_body["external_ids"][0]["external_id"] | ||
) | ||
self.assertEqual( | ||
"auth_provider1", channel.json_body["external_ids"][0]["auth_provider"] | ||
) | ||
self.assertEqual(1, len(channel.json_body["external_ids"])) | ||
self.assertFalse(channel.json_body["admin"]) | ||
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"]) | ||
self._check_fields(channel.json_body) | ||
|
@@ -1676,18 +1678,53 @@ def test_set_threepid(self): | |
Test setting threepid for an other user. | ||
""" | ||
|
||
# Delete old and add new threepid to user | ||
# Add two threepids to user | ||
channel = self.make_request( | ||
"PUT", | ||
self.url_other_user, | ||
access_token=self.admin_user_tok, | ||
content={"threepids": [{"medium": "email", "address": "[email protected]"}]}, | ||
content={ | ||
"threepids": [ | ||
{"medium": "email", "address": "[email protected]"}, | ||
{"medium": "email", "address": "[email protected]"}, | ||
], | ||
}, | ||
) | ||
|
||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual("@user:test", channel.json_body["name"]) | ||
self.assertEqual(2, len(channel.json_body["threepids"])) | ||
# result does not always have the same sort order, therefore it becomes sorted | ||
sorted_result = sorted( | ||
channel.json_body["threepids"], key=lambda k: k["address"] | ||
) | ||
self.assertEqual("email", sorted_result[0]["medium"]) | ||
self.assertEqual("[email protected]", sorted_result[0]["address"]) | ||
self.assertEqual("email", sorted_result[1]["medium"]) | ||
self.assertEqual("[email protected]", sorted_result[1]["address"]) | ||
self._check_fields(channel.json_body) | ||
|
||
# Set a new and remove a threepid | ||
channel = self.make_request( | ||
"PUT", | ||
self.url_other_user, | ||
access_token=self.admin_user_tok, | ||
content={ | ||
"threepids": [ | ||
{"medium": "email", "address": "[email protected]"}, | ||
{"medium": "email", "address": "[email protected]"}, | ||
], | ||
}, | ||
) | ||
|
||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual("@user:test", channel.json_body["name"]) | ||
self.assertEqual(2, len(channel.json_body["threepids"])) | ||
self.assertEqual("email", channel.json_body["threepids"][0]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
self.assertEqual("email", channel.json_body["threepids"][1]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][1]["address"]) | ||
self._check_fields(channel.json_body) | ||
|
||
# Get user | ||
channel = self.make_request( | ||
|
@@ -1698,8 +1735,24 @@ def test_set_threepid(self): | |
|
||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual("@user:test", channel.json_body["name"]) | ||
self.assertEqual(2, len(channel.json_body["threepids"])) | ||
self.assertEqual("email", channel.json_body["threepids"][0]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][0]["address"]) | ||
self.assertEqual("email", channel.json_body["threepids"][1]["medium"]) | ||
self.assertEqual("[email protected]", channel.json_body["threepids"][1]["address"]) | ||
self._check_fields(channel.json_body) | ||
|
||
# Remove threepids | ||
channel = self.make_request( | ||
"PUT", | ||
self.url_other_user, | ||
access_token=self.admin_user_tok, | ||
content={"threepids": []}, | ||
) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual("@user:test", channel.json_body["name"]) | ||
self.assertEqual(0, len(channel.json_body["threepids"])) | ||
self._check_fields(channel.json_body) | ||
|
||
def test_set_external_id(self): | ||
""" | ||
|
@@ -1778,6 +1831,7 @@ def test_set_external_id(self): | |
|
||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual("@user:test", channel.json_body["name"]) | ||
self.assertEqual(2, len(channel.json_body["external_ids"])) | ||
self.assertEqual( | ||
channel.json_body["external_ids"], | ||
[ | ||
|