mirror of https://gitlab.com/litecord/litecord.git
admin_api.users: add user deletion
- users: expose _force_disconnect as user_disconnect
This commit is contained in:
parent
efebd21cfb
commit
700e590e8b
|
|
@ -36,7 +36,18 @@ Returns a list of user objects.
|
||||||
|
|
||||||
### `DELETE /users/<user_id>`
|
### `DELETE /users/<user_id>`
|
||||||
|
|
||||||
**TODO**
|
Delete a single user. Does not *actually* remove the user from the users row,
|
||||||
|
it changes the username to `Deleted User <random hex>`, etc.
|
||||||
|
|
||||||
|
Also disconnects all of the users' devices from the gateway.
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
| field | type | description |
|
||||||
|
| --: | :-- | :-- |
|
||||||
|
| old | user object | old user object pre-delete |
|
||||||
|
| new | user object | new user object post-delete |
|
||||||
|
|
||||||
|
|
||||||
## Instance invites
|
## Instance invites
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ from litecord.schemas import validate
|
||||||
from litecord.admin_schemas import USER_CREATE
|
from litecord.admin_schemas import USER_CREATE
|
||||||
from litecord.errors import BadRequest
|
from litecord.errors import BadRequest
|
||||||
from litecord.utils import async_map
|
from litecord.utils import async_map
|
||||||
|
from litecord.blueprints.users import delete_user, user_disconnect
|
||||||
|
|
||||||
bp = Blueprint('users_admin', __name__)
|
bp = Blueprint('users_admin', __name__)
|
||||||
|
|
||||||
|
|
@ -98,3 +99,20 @@ async def _search_users():
|
||||||
return jsonify(
|
return jsonify(
|
||||||
await async_map(app.storage.get_user, rows)
|
await async_map(app.storage.get_user, rows)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<user_id:int>', methods=['DELETE'])
|
||||||
|
async def _delete_single_user(user_id: int):
|
||||||
|
await admin_check()
|
||||||
|
|
||||||
|
old_user = await app.storage.get_user(user_id)
|
||||||
|
|
||||||
|
await delete_user(user_id)
|
||||||
|
await user_disconnect(user_id)
|
||||||
|
|
||||||
|
new_user = await app.storage.get_user(user_id)
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'old': old_user,
|
||||||
|
'new': new_user
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -545,7 +545,8 @@ async def delete_user(user_id, *, db=None):
|
||||||
await _del_from_table(db, 'channel_overwrites', user_id)
|
await _del_from_table(db, 'channel_overwrites', user_id)
|
||||||
|
|
||||||
|
|
||||||
async def _force_disconnect(user_id):
|
async def user_disconnect(user_id):
|
||||||
|
"""Disconnects the given user's devices."""
|
||||||
# after removing the user from all tables, we need to force
|
# after removing the user from all tables, we need to force
|
||||||
# all known user states to reconnect, causing the user to not
|
# all known user states to reconnect, causing the user to not
|
||||||
# be online anymore.
|
# be online anymore.
|
||||||
|
|
@ -597,6 +598,6 @@ async def delete_account():
|
||||||
raise Unauthorized('password does not match')
|
raise Unauthorized('password does not match')
|
||||||
|
|
||||||
await delete_user(user_id)
|
await delete_user(user_id)
|
||||||
await _force_disconnect(user_id)
|
await user_disconnect(user_id)
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue