Skip to content

Commit cc59aa5

Browse files
committed
Add /rooms/all/<SessionID:sid> for server-wide message deletion.
This causes all messages by the given Session id to be deleted from the server. The deleting user must be a global moderator on the server. This facility is needed to allow a server-wide 'Ban and Delete' feature for Session moderators and admins.
1 parent 34065c8 commit cc59aa5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

sogs/routes/rooms.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,33 @@ def delete_all_posts(room, sid):
960960
if not deleted:
961961
abort(http.NOT_FOUND)
962962
return jsonify({})
963+
964+
965+
@rooms.delete("/rooms/all/<SessionID:sid>")
966+
def delete_user_posts_from_all_rooms(sid):
967+
"""
968+
Deletes all posts from all rooms by a given user.
969+
970+
# URL Parameters
971+
972+
- `sid` — the session id of the user to ban
973+
974+
# Return value
975+
976+
A JSON dict with the keys:
977+
978+
- `total` — The total number of posts deleted across all rooms.
979+
- `rooms` — A dict of room tokens and their deletion counts.
980+
"""
981+
deletions = {}
982+
total = 0
983+
user = muser.User(session_id=sid, autovivify=False)
984+
for room in mroom.get_accessible_rooms(g.user):
985+
try:
986+
count, _ = room.delete_all_posts(user, deleter=g.user)
987+
total += count
988+
deletions[room.token] = count
989+
except exc.BadPermission:
990+
pass
991+
992+
return jsonify({"total": total, "rooms": deletions})

sogs/routes/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def ban_user(sid):
293293
294294
The user's messages are not deleted by this request. In order to ban and delete all messages
295295
use the [`/sequence`](#post-sequence) endpoint to bundle a `/user/.../ban` with a
296-
[`/user/.../deleteMessages`](#post-usersiddeleteMessages) request.
296+
[`/rooms/all/...`](#delete-roomsallsid) request.
297297
298298
# Return value
299299

0 commit comments

Comments
 (0)