Skip to content

Commit 5eeb135

Browse files
committed
Tweak addExtraPermInfo to remove some stuff we can omit
1 parent 6e373ab commit 5eeb135

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

sogs/routes/rooms.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,23 @@ def update_room(room):
279279

280280

281281
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:
286296
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"]:
289299
del perms["banned"]
290300
return perms
291301

@@ -301,8 +311,7 @@ def get_permission_info(room):
301311
dict of session_id to current permissions,
302312
a dict containing the name of the permission mapped to a boolean value.
303313
"""
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()})
306315

307316

308317
@rooms.get("/room/<Room:room>/futurePermInfo")

0 commit comments

Comments
 (0)