mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-01-19 14:31:28 -05:00
Add the shadow-banning status to the display user admin API. (#9400)
This commit is contained in:
parent
a25661b2eb
commit
c8d9383cfb
1
changelog.d/9400.feature
Normal file
1
changelog.d/9400.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add the shadow-banning status to the display user admin API.
|
@ -29,8 +29,9 @@ It returns a JSON body like the following:
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"avatar_url": "<avatar_url>",
|
"avatar_url": "<avatar_url>",
|
||||||
"admin": false,
|
"admin": 0,
|
||||||
"deactivated": false,
|
"deactivated": 0,
|
||||||
|
"shadow_banned": 0,
|
||||||
"password_hash": "$2b$12$p9B4GkqYdRTPGD",
|
"password_hash": "$2b$12$p9B4GkqYdRTPGD",
|
||||||
"creation_ts": 1560432506,
|
"creation_ts": 1560432506,
|
||||||
"appservice_id": null,
|
"appservice_id": null,
|
||||||
@ -150,6 +151,7 @@ A JSON body is returned with the following shape:
|
|||||||
"admin": 0,
|
"admin": 0,
|
||||||
"user_type": null,
|
"user_type": null,
|
||||||
"deactivated": 0,
|
"deactivated": 0,
|
||||||
|
"shadow_banned": 0,
|
||||||
"displayname": "<User One>",
|
"displayname": "<User One>",
|
||||||
"avatar_url": null
|
"avatar_url": null
|
||||||
}, {
|
}, {
|
||||||
@ -158,6 +160,7 @@ A JSON body is returned with the following shape:
|
|||||||
"admin": 1,
|
"admin": 1,
|
||||||
"user_type": null,
|
"user_type": null,
|
||||||
"deactivated": 0,
|
"deactivated": 0,
|
||||||
|
"shadow_banned": 0,
|
||||||
"displayname": "<User Two>",
|
"displayname": "<User Two>",
|
||||||
"avatar_url": "<avatar_url>"
|
"avatar_url": "<avatar_url>"
|
||||||
}
|
}
|
||||||
@ -262,7 +265,7 @@ The following actions are performed when deactivating an user:
|
|||||||
- Reject all pending invites
|
- Reject all pending invites
|
||||||
- Remove all account validity information related to the user
|
- Remove all account validity information related to the user
|
||||||
|
|
||||||
The following additional actions are performed during deactivation if``erase``
|
The following additional actions are performed during deactivation if ``erase``
|
||||||
is set to ``true``:
|
is set to ``true``:
|
||||||
|
|
||||||
- Remove the user's display name
|
- Remove the user's display name
|
||||||
|
@ -340,7 +340,7 @@ class DataStore(
|
|||||||
count = txn.fetchone()[0]
|
count = txn.fetchone()[0]
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT name, user_type, is_guest, admin, deactivated, displayname, avatar_url "
|
"SELECT name, user_type, is_guest, admin, deactivated, shadow_banned, displayname, avatar_url "
|
||||||
+ sql_base
|
+ sql_base
|
||||||
+ " ORDER BY u.name LIMIT ? OFFSET ?"
|
+ " ORDER BY u.name LIMIT ? OFFSET ?"
|
||||||
)
|
)
|
||||||
|
@ -113,6 +113,7 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore):
|
|||||||
"creation_ts",
|
"creation_ts",
|
||||||
"user_type",
|
"user_type",
|
||||||
"deactivated",
|
"deactivated",
|
||||||
|
"shadow_banned",
|
||||||
],
|
],
|
||||||
allow_none=True,
|
allow_none=True,
|
||||||
desc="get_user_by_id",
|
desc="get_user_by_id",
|
||||||
@ -372,23 +373,25 @@ class RegistrationWorkerStore(CacheInvalidationWorkerStore):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def set_shadow_banned_txn(txn):
|
def set_shadow_banned_txn(txn):
|
||||||
|
user_id = user.to_string()
|
||||||
self.db_pool.simple_update_one_txn(
|
self.db_pool.simple_update_one_txn(
|
||||||
txn,
|
txn,
|
||||||
table="users",
|
table="users",
|
||||||
keyvalues={"name": user.to_string()},
|
keyvalues={"name": user_id},
|
||||||
updatevalues={"shadow_banned": shadow_banned},
|
updatevalues={"shadow_banned": shadow_banned},
|
||||||
)
|
)
|
||||||
# In order for this to apply immediately, clear the cache for this user.
|
# In order for this to apply immediately, clear the cache for this user.
|
||||||
tokens = self.db_pool.simple_select_onecol_txn(
|
tokens = self.db_pool.simple_select_onecol_txn(
|
||||||
txn,
|
txn,
|
||||||
table="access_tokens",
|
table="access_tokens",
|
||||||
keyvalues={"user_id": user.to_string()},
|
keyvalues={"user_id": user_id},
|
||||||
retcol="token",
|
retcol="token",
|
||||||
)
|
)
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
self._invalidate_cache_and_stream(
|
self._invalidate_cache_and_stream(
|
||||||
txn, self.get_user_by_access_token, (token,)
|
txn, self.get_user_by_access_token, (token,)
|
||||||
)
|
)
|
||||||
|
self._invalidate_cache_and_stream(txn, self.get_user_by_id, (user_id,))
|
||||||
|
|
||||||
await self.db_pool.runInteraction("set_shadow_banned", set_shadow_banned_txn)
|
await self.db_pool.runInteraction("set_shadow_banned", set_shadow_banned_txn)
|
||||||
|
|
||||||
|
@ -769,6 +769,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
|||||||
self.assertIn("admin", u)
|
self.assertIn("admin", u)
|
||||||
self.assertIn("user_type", u)
|
self.assertIn("user_type", u)
|
||||||
self.assertIn("deactivated", u)
|
self.assertIn("deactivated", u)
|
||||||
|
self.assertIn("shadow_banned", u)
|
||||||
self.assertIn("displayname", u)
|
self.assertIn("displayname", u)
|
||||||
self.assertIn("avatar_url", u)
|
self.assertIn("avatar_url", u)
|
||||||
|
|
||||||
@ -1146,6 +1147,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
|||||||
self.assertEqual(False, channel.json_body["admin"])
|
self.assertEqual(False, channel.json_body["admin"])
|
||||||
self.assertEqual(False, channel.json_body["is_guest"])
|
self.assertEqual(False, channel.json_body["is_guest"])
|
||||||
self.assertEqual(False, channel.json_body["deactivated"])
|
self.assertEqual(False, channel.json_body["deactivated"])
|
||||||
|
self.assertEqual(False, channel.json_body["shadow_banned"])
|
||||||
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
||||||
|
|
||||||
@override_config(
|
@override_config(
|
||||||
|
@ -52,6 +52,7 @@ class RegistrationStoreTestCase(unittest.TestCase):
|
|||||||
"creation_ts": 1000,
|
"creation_ts": 1000,
|
||||||
"user_type": None,
|
"user_type": None,
|
||||||
"deactivated": 0,
|
"deactivated": 0,
|
||||||
|
"shadow_banned": 0,
|
||||||
},
|
},
|
||||||
(yield defer.ensureDeferred(self.store.get_user_by_id(self.user_id))),
|
(yield defer.ensureDeferred(self.store.get_user_by_id(self.user_id))),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user