Skip to content

Commit 11bec5b

Browse files
Jeffjagerman
authored andcommitted
add function to fix up permissions in routes codepath
add extra members and delete redundant info from model
1 parent 0fbbfc3 commit 11bec5b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

sogs/routes/rooms.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ def update_room(room):
278278
return jsonify({})
279279

280280

281+
def addExtraPermInfo(perms):
282+
""" """
283+
if perms.get("moderator"):
284+
perms["hidden"] = not bool(perms.pop("visible_mod"))
285+
if perms.get("admin"):
286+
del perms["moderator"]
287+
# if banned is explicitly provided and set to false omit it entirely
288+
if perms.get("banned") is False:
289+
del perms["banned"]
290+
return perms
291+
292+
281293
@rooms.get("/room/<Room:room>/permInfo")
282294
@auth.mod_required
283295
def get_permission_info(room):
@@ -290,7 +302,8 @@ def get_permission_info(room):
290302
if compact is set to 1 this will be a string,
291303
otherwise it will be a dict containing the name of the permission mapped to a boolean value.
292304
"""
293-
return jsonify(room.permissions)
305+
perms = room.permissions
306+
return jsonify({key: addExtraPermInfo(perms[key]) for key in perms.keys()})
294307

295308

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

tests/test_room_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ def test_get_room_perms_as_mod(client, room, mod):
11511151
assert r.status_code == 200
11521152
assert mod.session_id in r.json
11531153
perm_info = r.json[mod.session_id]
1154-
assert perm_info['visible_mod'] is True
1154+
assert perm_info['moderator'] is True
11551155

11561156

11571157
def test_get_room_perms_as_admin(client, room, admin):

0 commit comments

Comments
 (0)