Skip to content

Commit 2e13b30

Browse files
committed
fix docstrings
1 parent 0f7670b commit 2e13b30

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
@@ -433,47 +433,19 @@ def ban_checks():
433433
@app.post("/legacy/block_list")
434434
def handle_legacy_ban():
435435
user, room, to_ban = ban_checks()
436-
436+
code = http.OK
437437
if not model.ban_user(user, room, to_ban):
438-
abort(http.FORBIDDEN)
439-
440-
return jsonify({"status_code": 200})
438+
code = http.FORBIDDEN
439+
return jsonify({"status_code": code})
441440

442441

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

478450

479451
@app.delete("/legacy/block_list/<SessionID:session_id>")
@@ -494,7 +466,7 @@ def handle_legacy_unban(session_id):
494466
updated = cur.rowcount
495467

496468
if updated > 0:
497-
return jsonify({"status_code": 200})
469+
return jsonify({"status_code": http.OK})
498470

499471
abort(http.NOT_FOUND)
500472

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:
@@ -637,7 +637,7 @@ def get_message_deprecated(room_id, since, limit=256):
637637
return msgs
638638

639639

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

0 commit comments

Comments
 (0)