Skip to content

Commit 56b4f0b

Browse files
committed
fix docstrings
1 parent 4f897c1 commit 56b4f0b

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

sogs/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
TOO_MANY_REQUESTS = 429
99
ERROR_INTERNAL_SERVER_ERROR = 500
1010
ERROR_INSUFFICIENT_STORAGE = 507
11-
11+
OK = 200
1212

1313
# HTTP methods containing bodies
1414
BODY_METHODS = ('POST', 'PUT')

sogs/legacy_routes.py

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -430,47 +430,19 @@ def ban_checks():
430430
@app.post("/legacy/block_list")
431431
def handle_legacy_ban():
432432
user, room, to_ban = ban_checks()
433-
433+
code = http.OK
434434
if not model.ban_user(user, room, to_ban):
435-
abort(http.FORBIDDEN)
436-
437-
return jsonify({"status_code": 200})
435+
code = http.FORBIDDEN
436+
return jsonify({"status_code": code})
438437

439438

440439
@app.post("/legacy/ban_and_delete_all")
441440
def handle_legacy_banhammer():
442441
user, room, to_ban = ban_checks()
443-
if not model.ban_user(user, room, to_ban):
444-
abort(http.FORBIDDEN)
445-
446-
with db.conn as conn:
447-
cur = conn.cursor()
448-
cur.execute(
449-
"""
450-
UPDATE messages SET data = NULL, data_size = NULL, signature = NULL
451-
WHERE room = ? AND user = ?
452-
""",
453-
(room.id, to_ban.id),
454-
)
455-
456-
posts_removed = cur.rowcount
457-
458-
# We don't actually delete from disk right now, but clear the room (so that they aren't
459-
# retrievable) and set them to be expired (so that the next file pruning will delete them
460-
# from disk).
461-
cur.execute(
462-
"UPDATE files SET room = NULL, expiry = ? WHERE room = ? AND uploader = ?",
463-
(time.time(), room.id, to_ban.id),
464-
)
465-
files_removed = cur.rowcount
466-
467-
app.logger.info(
468-
"Banned {} from room {}: {} messages and {} files deleted".format(
469-
to_ban.session_id, room.token, posts_removed, files_removed
470-
)
471-
)
472-
473-
return jsonify({"status_code": 200})
442+
code = http.OK
443+
if not model.ban_user(user, room, to_ban, also_delete_posts=True):
444+
code = http.FORBIDDEN
445+
return jsonify({"status_code": code})
474446

475447

476448
@app.delete("/legacy/block_list/<SessionID:session_id>")
@@ -491,7 +463,7 @@ def handle_legacy_unban(session_id):
491463
updated = cur.rowcount
492464

493465
if updated > 0:
494-
return jsonify({"status_code": 200})
466+
return jsonify({"status_code": http.OK})
495467

496468
abort(http.NOT_FOUND)
497469

sogs/model.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ def __init__(self, row=None, *, id=None, session_id=None, autovivify=True, touch
394394

395395
@property
396396
def rooms(self):
397-
result = list()
398397
""" return the rooms this user is in by their id """
398+
result = list()
399399
with db.conn as conn:
400400
rows = conn.execute("SELECT room FROM room_users WHERE user = ?", (self.id,))
401401
for row in rows:
@@ -636,7 +636,7 @@ def get_message_deprecated(room_id, since, limit=256):
636636
return msgs
637637

638638

639-
def ban_user(mod_user, room, ban_user):
639+
def ban_user(mod_user, room, ban_user, also_delete_posts=False):
640640
"""as a moderator mod_user ban a user from a room
641641
return True if the user was banned, otherwise return False
642642
"""
@@ -669,4 +669,31 @@ def ban_user(mod_user, room, ban_user):
669669
""",
670670
(room.id, ban_user.id),
671671
)
672+
if also_delete_posts:
673+
cur = conn.cursor()
674+
cur.execute(
675+
"""
676+
UPDATE messages SET data = NULL, data_size = NULL, signature = NULL
677+
WHERE room = ? AND user = ?
678+
""",
679+
(room.id, ban_user.id),
680+
)
681+
682+
posts_removed = cur.rowcount
683+
684+
# We don't actually delete from disk right now, but clear the room (so that they aren't
685+
# retrievable) and set them to be expired (so that the next file pruning will delete them
686+
# from disk).
687+
cur.execute(
688+
"UPDATE files SET room = NULL, expiry = ? WHERE room = ? AND uploader = ?",
689+
(time.time(), room.id, ban_user.id),
690+
)
691+
files_removed = cur.rowcount
692+
693+
app.logger.info(
694+
"Banned {} from room {}: {} messages and {} files deleted".format(
695+
to_ban.session_id, room.token, posts_removed, files_removed
696+
)
697+
)
698+
672699
return True

0 commit comments

Comments
 (0)