Skip to content

Commit 57bfcf0

Browse files
committed
Check for blinding when de-modding/unbanning
This allows a Session client to remove a user by *unblinded* ID to have the server convert that id to the blinded ID (when blinding is enabled). Without this, you have to use the blinded id to unban or remove a moderator. (And this makes it work like the *adding* a mod or banning).
1 parent b8c1bb3 commit 57bfcf0

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

sogs/model/room.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,22 +1398,23 @@ def remove_moderator(self, user: User, *, removed_by: User, remove_admin_only: b
13981398
raise BadPermission()
13991399

14001400
with db.transaction():
1401-
query(
1402-
f"""
1403-
UPDATE user_permission_overrides
1404-
SET admin = FALSE
1405-
{', moderator = FALSE, visible_mod = TRUE' if not remove_admin_only else ''}
1406-
WHERE room = :r AND "user" = :u
1407-
""",
1408-
r=self.id,
1409-
u=user.id,
1410-
)
1401+
with user.check_blinding() as u:
1402+
query(
1403+
f"""
1404+
UPDATE user_permission_overrides
1405+
SET admin = FALSE
1406+
{', moderator = FALSE, visible_mod = TRUE' if not remove_admin_only else ''}
1407+
WHERE room = :r AND "user" = :u
1408+
""",
1409+
r=self.id,
1410+
u=user.id,
1411+
)
14111412

1412-
self._refresh()
1413-
if user.id in self._perm_cache:
1414-
del self._perm_cache[user.id]
1413+
self._refresh()
1414+
if user.id in self._perm_cache:
1415+
del self._perm_cache[user.id]
14151416

1416-
app.logger.info(f"{removed_by} removed {user} as mod/admin of {self}")
1417+
app.logger.info(f"{removed_by} removed {u} as mod/admin of {self}")
14171418

14181419
def ban_user(self, to_ban: User, *, mod: User, timeout: Optional[float] = None):
14191420
"""
@@ -1496,24 +1497,28 @@ def unban_user(self, to_unban: User, *, mod: User):
14961497
app.logger.warning(f"Error unbanning {to_unban} from {self} by {mod}: not a moderator")
14971498
raise BadPermission()
14981499

1499-
result = query(
1500-
"""
1501-
UPDATE user_permission_overrides SET banned = FALSE
1502-
WHERE room = :r AND "user" = :unban AND banned
1503-
""",
1504-
r=self.id,
1505-
unban=to_unban.id,
1506-
)
1507-
if result.rowcount > 0:
1508-
app.logger.debug(f"{mod} unbanned {to_unban} from {self}")
1500+
with db.transaction():
1501+
with to_unban.check_blinding() as to_unban:
1502+
result = query(
1503+
"""
1504+
UPDATE user_permission_overrides SET banned = FALSE
1505+
WHERE room = :r AND "user" = :unban AND banned
1506+
""",
1507+
r=self.id,
1508+
unban=to_unban.id,
1509+
)
1510+
if result.rowcount > 0:
1511+
app.logger.debug(f"{mod} unbanned {to_unban} from {self}")
15091512

1510-
if to_unban.id in self._perm_cache:
1511-
del self._perm_cache[to_unban.id]
1513+
if to_unban.id in self._perm_cache:
1514+
del self._perm_cache[to_unban.id]
15121515

1513-
return True
1516+
return True
15141517

1515-
app.logger.debug(f"{mod} unbanned {to_unban} from {self} (but user was already unbanned)")
1516-
return False
1518+
app.logger.debug(
1519+
f"{mod} unbanned {to_unban} from {self} (but user was already unbanned)"
1520+
)
1521+
return False
15171522

15181523
def get_bans(self):
15191524
"""

0 commit comments

Comments
 (0)