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
Add creation_ts
to list users admin API
#10448
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9cf4576
Add `creation_ts` to list users admin API
dklimpel a93f681
newsfile and typo
dklimpel 0c08483
correct timestamp to s
dklimpel 5cbac42
update `self.pump(1.0)` to `self.reactor.advance`
dklimpel 773fec6
change to time in ms
dklimpel b13174d
revert small changes
dklimpel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
Add `creation_ts` to list users 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
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 |
---|---|---|
|
@@ -473,7 +473,7 @@ def test_no_auth(self): | |
""" | ||
channel = self.make_request("GET", self.url, b"{}") | ||
|
||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(401, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"]) | ||
|
||
def test_requester_is_no_admin(self): | ||
|
@@ -485,7 +485,7 @@ def test_requester_is_no_admin(self): | |
|
||
channel = self.make_request("GET", self.url, access_token=other_user_token) | ||
|
||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(403, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"]) | ||
|
||
def test_all_users(self): | ||
|
@@ -497,11 +497,11 @@ def test_all_users(self): | |
channel = self.make_request( | ||
"GET", | ||
self.url + "?deactivated=true", | ||
b"{}", | ||
{}, | ||
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(3, len(channel.json_body["users"])) | ||
self.assertEqual(3, channel.json_body["total"]) | ||
|
||
|
@@ -532,7 +532,7 @@ def _search_test( | |
) | ||
channel = self.make_request( | ||
"GET", | ||
url.encode("ascii"), | ||
url, | ||
access_token=self.admin_user_tok, | ||
) | ||
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body) | ||
|
@@ -598,7 +598,7 @@ def test_invalid_parameter(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(400, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"]) | ||
|
||
# negative from | ||
|
@@ -608,7 +608,7 @@ def test_invalid_parameter(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(400, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"]) | ||
|
||
# invalid guests | ||
|
@@ -618,7 +618,7 @@ def test_invalid_parameter(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(400, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"]) | ||
|
||
# invalid deactivated | ||
|
@@ -628,7 +628,7 @@ def test_invalid_parameter(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(400, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"]) | ||
|
||
# unkown order_by | ||
|
@@ -648,7 +648,7 @@ def test_invalid_parameter(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(400, channel.code, msg=channel.json_body) | ||
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"]) | ||
|
||
def test_limit(self): | ||
|
@@ -666,7 +666,7 @@ def test_limit(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), 5) | ||
self.assertEqual(channel.json_body["next_token"], "5") | ||
|
@@ -687,7 +687,7 @@ def test_from(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), 15) | ||
self.assertNotIn("next_token", channel.json_body) | ||
|
@@ -708,7 +708,7 @@ def test_limit_and_from(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(channel.json_body["next_token"], "15") | ||
self.assertEqual(len(channel.json_body["users"]), 10) | ||
|
@@ -731,7 +731,7 @@ def test_next_token(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), number_users) | ||
self.assertNotIn("next_token", channel.json_body) | ||
|
@@ -744,7 +744,7 @@ def test_next_token(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), number_users) | ||
self.assertNotIn("next_token", channel.json_body) | ||
|
@@ -757,7 +757,7 @@ def test_next_token(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), 19) | ||
self.assertEqual(channel.json_body["next_token"], "19") | ||
|
@@ -771,7 +771,7 @@ def test_next_token(self): | |
access_token=self.admin_user_tok, | ||
) | ||
|
||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"]) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
self.assertEqual(channel.json_body["total"], number_users) | ||
self.assertEqual(len(channel.json_body["users"]), 1) | ||
self.assertNotIn("next_token", channel.json_body) | ||
|
@@ -781,7 +781,10 @@ def test_order_by(self): | |
Testing order list with parameter `order_by` | ||
""" | ||
|
||
# make sure that the users do not have the same timestamps | ||
self.pump(1.0) | ||
user1 = self.register_user("user1", "pass1", admin=False, displayname="Name Z") | ||
self.pump(1.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to use |
||
user2 = self.register_user("user2", "pass2", admin=False, displayname="Name Y") | ||
|
||
# Modify user | ||
|
@@ -841,6 +844,11 @@ def test_order_by(self): | |
self._order_test([self.admin_user, user2, user1], "avatar_url", "f") | ||
self._order_test([user1, user2, self.admin_user], "avatar_url", "b") | ||
|
||
# order by creation_ts | ||
self._order_test([self.admin_user, user1, user2], "creation_ts") | ||
self._order_test([self.admin_user, user1, user2], "creation_ts", "f") | ||
self._order_test([user2, user1, self.admin_user], "creation_ts", "b") | ||
|
||
def _order_test( | ||
self, | ||
expected_user_list: List[str], | ||
|
@@ -863,7 +871,7 @@ def _order_test( | |
url += "dir=%s" % (dir,) | ||
channel = self.make_request( | ||
"GET", | ||
url.encode("ascii"), | ||
url, | ||
access_token=self.admin_user_tok, | ||
) | ||
self.assertEqual(200, channel.code, msg=channel.json_body) | ||
|
@@ -887,6 +895,7 @@ def _check_fields(self, content: JsonDict): | |
self.assertIn("shadow_banned", u) | ||
self.assertIn("displayname", u) | ||
self.assertIn("avatar_url", u) | ||
self.assertIn("creation_ts", u) | ||
|
||
def _create_users(self, number_users: int): | ||
""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make it return a value in milliseconds instead of seconds please? The
users
table is an old one and as such as a few inconsistencies with the rest of Synapse, one of them being using seconds instead of milliseconds. The rest of Synapse uses milliseconds, so I think it'd be nice if we could try to head towards consistency here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I can do that, but then there is a mismatch to Query user API
What do we do with the Query user API? Also change to
ms
? With a version increment?I would like to prefer that both APIs returns the same values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah somehow I've missed that the query user API also returns a value in seconds. Ideally I'd like it to change to ms too (with a v3 of the endpoint in order not to confuse users). I'd suggest doing that in a separate PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like a
v3
for this small change.But we can start here to use
ms
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes definitely. And agreed that v3 is maybe a bit overkill for such a small change, but I also don't think we should change the unit in the v2 endpoint, lest we break existing scripts using it.