Skip to content

Commit 89e7a91

Browse files
committed
Fix "stuck moderator" problem
With various combinations of the blinded setting, older Session dev versions, and the cli tool, you could end up with a "stuck" unblinded moderator that can't be removed (when blinding is enabled) because the blinded ID already exists, so when you try to remove it it removes moderator status from the *blinded* user instead. The resolves a few things around this: - the cli tool now tries to remove *both* the blinded and unblinded mod/admin permissions if given an unblinded ID with a known blinded ID, to "unstick" this moderator. - the cli tool was wrongly showing the given session id, rather than the actual resolved session id, so was showing that it was removing "05..." when actually it was removing the blinded user "15...". - legacy endpoints for adding a moderator (and bans) now try blinding the ID. This hopefully won't matter as I don't believe the legacy endpoints will get used with the updated Session client, but might make a difference if blinding gets flipped on and then off again.
1 parent 57bfcf0 commit 89e7a91

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

sogs/__main__.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
from . import web
153153
from .model.room import Room, get_rooms
154154
from .model.user import User, SystemUser, get_all_global_moderators
155-
from .model.exc import AlreadyExists, NoSuchRoom
155+
from .model.exc import AlreadyExists, NoSuchRoom, NoSuchUser
156156

157157
web.appdb = db.get_conn()
158158

@@ -322,7 +322,20 @@ def print_room(room: Room):
322322
print(f"{u.session_id} was not a global moderator")
323323
else:
324324
u.remove_moderator(removed_by=sysadmin)
325-
print(f"Removed {sid} as global {'admin' if was_admin else 'moderator'}")
325+
print(f"Removed {u.session_id} as global {'admin' if was_admin else 'moderator'}")
326+
327+
if u.is_blinded and sid.startswith('05'):
328+
try:
329+
u2 = User(session_id=sid, try_blinding=False, autovivify=False)
330+
if u2.global_admin or u2.global_moderator:
331+
was_admin = u2.global_admin
332+
u2.remove_moderator(removed_by=sysadmin)
333+
print(
334+
f"Removed {u2.session_id} as global "
335+
f"{'admin' if was_admin else 'moderator'}"
336+
)
337+
except NoSuchUser:
338+
pass
326339
else:
327340
if args.rooms == ['*']:
328341
rooms = get_rooms()
@@ -334,9 +347,22 @@ def print_room(room: Room):
334347

335348
for sid in args.delete_moderators:
336349
u = User(session_id=sid, try_blinding=True)
350+
u2 = None
351+
if u.is_blinded and sid.startswith('05'):
352+
try:
353+
u2 = User(session_id=sid, try_blinding=False, autovivify=False)
354+
except NoSuchUser:
355+
pass
356+
337357
for room in rooms:
338358
room.remove_moderator(u, removed_by=sysadmin)
339359
print(f"Removed {u.session_id} as moderator/admin of {room.name} ({room.token})")
360+
if u2 is not None:
361+
room.remove_moderator(u2, removed_by=sysadmin)
362+
print(
363+
f"Removed {u2.session_id} as moderator/admin of {room.name} ({room.token})"
364+
)
365+
340366
elif args.list_rooms:
341367
rooms = get_rooms()
342368
if rooms:

sogs/routes/legacy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def handle_legacy_single_delete(msgid):
331331
@legacy.post("/block_list")
332332
def handle_legacy_ban():
333333
user, room = legacy_check_user_room(moderator=True)
334-
ban = User(session_id=request.json['public_key'], autovivify=True)
334+
ban = User(session_id=request.json['public_key'], autovivify=True, try_blinding=True)
335335

336336
room.ban_user(to_ban=ban, mod=user)
337337

@@ -341,7 +341,7 @@ def handle_legacy_ban():
341341
@legacy.post("/ban_and_delete_all")
342342
def handle_legacy_banhammer():
343343
mod, room = legacy_check_user_room(moderator=True)
344-
ban = User(session_id=request.json['public_key'], autovivify=True)
344+
ban = User(session_id=request.json['public_key'], autovivify=True, try_blinding=True)
345345

346346
with db.transaction():
347347
room.ban_user(to_ban=ban, mod=mod)
@@ -353,7 +353,7 @@ def handle_legacy_banhammer():
353353
@legacy.delete("/block_list/<SessionID:session_id>")
354354
def handle_legacy_unban(session_id):
355355
user, room = legacy_check_user_room(moderator=True)
356-
to_unban = User(session_id=session_id, autovivify=False)
356+
to_unban = User(session_id=session_id, autovivify=False, try_blinding=True)
357357
if room.unban_user(to_unban, mod=user):
358358
return jsonify({"status_code": http.OK})
359359

@@ -395,7 +395,7 @@ def handle_legacy_add_admin():
395395
if len(session_id) != 66 or not session_id.startswith("05"):
396396
abort(http.BAD_REQUEST)
397397

398-
mod = User(session_id=session_id, autovivify=True)
398+
mod = User(session_id=session_id, autovivify=True, try_blinding=True)
399399
room.set_moderator(mod, admin=True, visible=True, added_by=user)
400400

401401
return jsonify({"status_code": http.OK})
@@ -408,7 +408,7 @@ def handle_legacy_add_admin():
408408
def handle_legacy_remove_admin(session_id):
409409
user, room = legacy_check_user_room(admin=True)
410410

411-
mod = User(session_id=session_id, autovivify=False)
411+
mod = User(session_id=session_id, autovivify=False, try_blinding=True)
412412
room.remove_moderator(mod, removed_by=user)
413413

414414
return jsonify({"status_code": http.OK})

0 commit comments

Comments
 (0)