@@ -279,13 +279,23 @@ def update_room(room):
279
279
280
280
281
281
def addExtraPermInfo (perms ):
282
- """ """
283
- if perms .get ("moderator" ):
284
- perms ["hidden" ] = not bool (perms .pop ("visible_mod" ))
285
- if perms .get ("admin" ):
282
+ """
283
+ Apply some cleanups/simplifications for more digestable permission indicators by clients.
284
+
285
+ - We only include one of moderator/admin (admin if both, moderator if mod but not admin)
286
+ - Don't include moderator/admin at all when both are false
287
+ - We rewrite visible_mod=False to hidden=True (and omit both if not a mod/admin, or not hidden)
288
+ - Don't include banned unless true.
289
+ """
290
+ vis_mod = perms .pop ("visible_mod" , True )
291
+ if perms ["moderator" ]:
292
+ if not vis_mod :
293
+ perms ["hidden" ] = True
294
+ del perms ["moderator" if perms ["admin" ] else "admin" ]
295
+ else :
286
296
del perms ["moderator" ]
287
- # if banned is explicitly provided and set to false omit it entirely
288
- if perms . get ( "banned" ) is False :
297
+ del perms [ "admin" ]
298
+ if not perms [ "banned" ] :
289
299
del perms ["banned" ]
290
300
return perms
291
301
@@ -301,8 +311,7 @@ def get_permission_info(room):
301
311
dict of session_id to current permissions,
302
312
a dict containing the name of the permission mapped to a boolean value.
303
313
"""
304
- perms = room .permissions
305
- return jsonify ({key : addExtraPermInfo (perms [key ]) for key in perms .keys ()})
314
+ return jsonify ({k : addExtraPermInfo (v ) for k , v in room .permissions .items ()})
306
315
307
316
308
317
@rooms .get ("/room/<Room:room>/futurePermInfo" )
0 commit comments