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

Commit c8d9383

Browse files
authored
Add the shadow-banning status to the display user admin API. (#9400)
1 parent a25661b commit c8d9383

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

changelog.d/9400.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the shadow-banning status to the display user admin API.

docs/admin_api/user_admin_api.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ It returns a JSON body like the following:
2929
}
3030
],
3131
"avatar_url": "<avatar_url>",
32-
"admin": false,
33-
"deactivated": false,
32+
"admin": 0,
33+
"deactivated": 0,
34+
"shadow_banned": 0,
3435
"password_hash": "$2b$12$p9B4GkqYdRTPGD",
3536
"creation_ts": 1560432506,
3637
"appservice_id": null,
@@ -150,6 +151,7 @@ A JSON body is returned with the following shape:
150151
"admin": 0,
151152
"user_type": null,
152153
"deactivated": 0,
154+
"shadow_banned": 0,
153155
"displayname": "<User One>",
154156
"avatar_url": null
155157
}, {
@@ -158,6 +160,7 @@ A JSON body is returned with the following shape:
158160
"admin": 1,
159161
"user_type": null,
160162
"deactivated": 0,
163+
"shadow_banned": 0,
161164
"displayname": "<User Two>",
162165
"avatar_url": "<avatar_url>"
163166
}
@@ -262,7 +265,7 @@ The following actions are performed when deactivating an user:
262265
- Reject all pending invites
263266
- Remove all account validity information related to the user
264267

265-
The following additional actions are performed during deactivation if``erase``
268+
The following additional actions are performed during deactivation if ``erase``
266269
is set to ``true``:
267270

268271
- Remove the user's display name

synapse/storage/databases/main/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def get_users_paginate_txn(txn):
340340
count = txn.fetchone()[0]
341341

342342
sql = (
343-
"SELECT name, user_type, is_guest, admin, deactivated, displayname, avatar_url "
343+
"SELECT name, user_type, is_guest, admin, deactivated, shadow_banned, displayname, avatar_url "
344344
+ sql_base
345345
+ " ORDER BY u.name LIMIT ? OFFSET ?"
346346
)

synapse/storage/databases/main/registration.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ async def get_user_by_id(self, user_id: str) -> Optional[Dict[str, Any]]:
113113
"creation_ts",
114114
"user_type",
115115
"deactivated",
116+
"shadow_banned",
116117
],
117118
allow_none=True,
118119
desc="get_user_by_id",
@@ -372,23 +373,25 @@ async def set_shadow_banned(self, user: UserID, shadow_banned: bool) -> None:
372373
"""
373374

374375
def set_shadow_banned_txn(txn):
376+
user_id = user.to_string()
375377
self.db_pool.simple_update_one_txn(
376378
txn,
377379
table="users",
378-
keyvalues={"name": user.to_string()},
380+
keyvalues={"name": user_id},
379381
updatevalues={"shadow_banned": shadow_banned},
380382
)
381383
# In order for this to apply immediately, clear the cache for this user.
382384
tokens = self.db_pool.simple_select_onecol_txn(
383385
txn,
384386
table="access_tokens",
385-
keyvalues={"user_id": user.to_string()},
387+
keyvalues={"user_id": user_id},
386388
retcol="token",
387389
)
388390
for token in tokens:
389391
self._invalidate_cache_and_stream(
390392
txn, self.get_user_by_access_token, (token,)
391393
)
394+
self._invalidate_cache_and_stream(txn, self.get_user_by_id, (user_id,))
392395

393396
await self.db_pool.runInteraction("set_shadow_banned", set_shadow_banned_txn)
394397

tests/rest/admin/test_user.py

+2
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ def _check_fields(self, content: JsonDict):
769769
self.assertIn("admin", u)
770770
self.assertIn("user_type", u)
771771
self.assertIn("deactivated", u)
772+
self.assertIn("shadow_banned", u)
772773
self.assertIn("displayname", u)
773774
self.assertIn("avatar_url", u)
774775

@@ -1146,6 +1147,7 @@ def test_create_user(self):
11461147
self.assertEqual(False, channel.json_body["admin"])
11471148
self.assertEqual(False, channel.json_body["is_guest"])
11481149
self.assertEqual(False, channel.json_body["deactivated"])
1150+
self.assertEqual(False, channel.json_body["shadow_banned"])
11491151
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
11501152

11511153
@override_config(

tests/storage/test_registration.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_register(self):
5252
"creation_ts": 1000,
5353
"user_type": None,
5454
"deactivated": 0,
55+
"shadow_banned": 0,
5556
},
5657
(yield defer.ensureDeferred(self.store.get_user_by_id(self.user_id))),
5758
)

0 commit comments

Comments
 (0)