@@ -1045,21 +1045,33 @@ def set_moderator(self, user: User, *, added_by: User, admin=False, visible=True
1045
1045
)
1046
1046
raise BadPermission ()
1047
1047
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 ()
1063
1075
1064
1076
if user .id in self ._perm_cache :
1065
1077
del self ._perm_cache [user .id ]
@@ -1107,23 +1119,31 @@ def ban_user(self, to_ban: User, *, mod: User, timeout: Optional[float] = None):
1107
1119
primarily provided for testing.
1108
1120
"""
1109
1121
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 ()
1123
1144
1124
- # TODO: log the banning action for auditing
1145
+ # TODO: log the banning action for auditing
1125
1146
1126
- with db .transaction ():
1127
1147
query (
1128
1148
"""
1129
1149
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):
1152
1172
at = time .time () + timeout ,
1153
1173
)
1154
1174
1175
+ if need_blinding :
1176
+ to_ban .record_needs_blinding ()
1177
+
1155
1178
if to_ban .id in self ._perm_cache :
1156
1179
del self ._perm_cache [to_ban .id ]
1157
1180
@@ -1234,6 +1257,14 @@ def set_permissions(self, user: User, *, mod: User, **perms):
1234
1257
raise BadPermission ()
1235
1258
1236
1259
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
+
1237
1268
set_perms = perms .keys ()
1238
1269
query (
1239
1270
f"""
@@ -1250,6 +1281,9 @@ def set_permissions(self, user: User, *, mod: User, **perms):
1250
1281
upload = perms .get ('upload' ),
1251
1282
)
1252
1283
1284
+ if need_blinding :
1285
+ user .record_needs_blinding ()
1286
+
1253
1287
if user .id in self ._perm_cache :
1254
1288
del self ._perm_cache [user .id ]
1255
1289
0 commit comments