@@ -1045,21 +1045,33 @@ def set_moderator(self, user: User, *, added_by: User, admin=False, visible=True
10451045 )
10461046 raise BadPermission ()
10471047
1048- query (
1049- f"""
1050- INSERT INTO user_permission_overrides
1051- (room, "user", moderator, { 'admin,' if admin is not None else '' } visible_mod)
1052- VALUES (:r, :u, TRUE, { ':admin,' if admin is not None else '' } :visible)
1053- ON CONFLICT (room, "user") DO UPDATE SET
1054- moderator = excluded.moderator,
1055- { 'admin = excluded.admin,' if admin is not None else '' }
1056- visible_mod = excluded.visible_mod
1057- """ ,
1058- r = self .id ,
1059- u = user .id ,
1060- admin = admin ,
1061- visible = visible ,
1062- )
1048+ with db .transaction ():
1049+ need_blinding = False
1050+ if config .REQUIRE_BLIND_KEYS :
1051+ blinded = user .find_blinded ()
1052+ if blinded is not None :
1053+ user = blinded
1054+ else :
1055+ need_blinding = True
1056+
1057+ query (
1058+ f"""
1059+ INSERT INTO user_permission_overrides
1060+ (room, "user", moderator, { 'admin,' if admin is not None else '' } visible_mod)
1061+ VALUES (:r, :u, TRUE, { ':admin,' if admin is not None else '' } :visible)
1062+ ON CONFLICT (room, "user") DO UPDATE SET
1063+ moderator = excluded.moderator,
1064+ { 'admin = excluded.admin,' if admin is not None else '' }
1065+ visible_mod = excluded.visible_mod
1066+ """ ,
1067+ r = self .id ,
1068+ u = user .id ,
1069+ admin = admin ,
1070+ visible = visible ,
1071+ )
1072+
1073+ if need_blinding :
1074+ user .record_needs_blinding ()
10631075
10641076 if user .id in self ._perm_cache :
10651077 del self ._perm_cache [user .id ]
@@ -1107,23 +1119,31 @@ def ban_user(self, to_ban: User, *, mod: User, timeout: Optional[float] = None):
11071119 primarily provided for testing.
11081120 """
11091121
1110- fail = None
1111- if not self .check_moderator (mod ):
1112- fail = "user is not a moderator"
1113- elif to_ban .id == mod .id :
1114- fail = "self-ban not permitted"
1115- elif to_ban .global_moderator :
1116- fail = "global mods/admins cannot be banned"
1117- elif self .check_moderator (to_ban ) and not self .check_admin (mod ):
1118- fail = "only admins can ban room mods/admins"
1119-
1120- if fail is not None :
1121- app .logger .warning (f"Error banning { to_ban } from { self } by { mod } : { fail } " )
1122- raise BadPermission ()
1122+ with db .transaction ():
1123+ need_blinding = False
1124+ if config .REQUIRE_BLIND_KEYS :
1125+ blinded = to_ban .find_blinded ()
1126+ if blinded is not None :
1127+ to_ban = blinded
1128+ else :
1129+ need_blinding = True
1130+
1131+ fail = None
1132+ if not self .check_moderator (mod ):
1133+ fail = "user is not a moderator"
1134+ elif to_ban .id == mod .id :
1135+ fail = "self-ban not permitted"
1136+ elif to_ban .global_moderator :
1137+ fail = "global mods/admins cannot be banned"
1138+ elif self .check_moderator (to_ban ) and not self .check_admin (mod ):
1139+ fail = "only admins can ban room mods/admins"
1140+
1141+ if fail is not None :
1142+ app .logger .warning (f"Error banning { to_ban } from { self } by { mod } : { fail } " )
1143+ raise BadPermission ()
11231144
1124- # TODO: log the banning action for auditing
1145+ # TODO: log the banning action for auditing
11251146
1126- with db .transaction ():
11271147 query (
11281148 """
11291149 INSERT INTO user_permission_overrides (room, "user", banned, moderator, admin)
@@ -1152,6 +1172,9 @@ def ban_user(self, to_ban: User, *, mod: User, timeout: Optional[float] = None):
11521172 at = time .time () + timeout ,
11531173 )
11541174
1175+ if need_blinding :
1176+ to_ban .record_needs_blinding ()
1177+
11551178 if to_ban .id in self ._perm_cache :
11561179 del self ._perm_cache [to_ban .id ]
11571180
@@ -1234,6 +1257,14 @@ def set_permissions(self, user: User, *, mod: User, **perms):
12341257 raise BadPermission ()
12351258
12361259 with db .transaction ():
1260+ need_blinding = False
1261+ if config .REQUIRE_BLIND_KEYS :
1262+ blinded = user .find_blinded ()
1263+ if blinded is not None :
1264+ user = blinded
1265+ else :
1266+ need_blinding = True
1267+
12371268 set_perms = perms .keys ()
12381269 query (
12391270 f"""
@@ -1250,6 +1281,9 @@ def set_permissions(self, user: User, *, mod: User, **perms):
12501281 upload = perms .get ('upload' ),
12511282 )
12521283
1284+ if need_blinding :
1285+ user .record_needs_blinding ()
1286+
12531287 if user .id in self ._perm_cache :
12541288 del self ._perm_cache [user .id ]
12551289
0 commit comments