@@ -430,47 +430,19 @@ def ban_checks():
430
430
@app .post ("/legacy/block_list" )
431
431
def handle_legacy_ban ():
432
432
user , room , to_ban = ban_checks ()
433
-
433
+ code = http . OK
434
434
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 })
438
437
439
438
440
439
@app .post ("/legacy/ban_and_delete_all" )
441
440
def handle_legacy_banhammer ():
442
441
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 })
474
446
475
447
476
448
@app .delete ("/legacy/block_list/<SessionID:session_id>" )
@@ -491,7 +463,7 @@ def handle_legacy_unban(session_id):
491
463
updated = cur .rowcount
492
464
493
465
if updated > 0 :
494
- return jsonify ({"status_code" : 200 })
466
+ return jsonify ({"status_code" : http . OK })
495
467
496
468
abort (http .NOT_FOUND )
497
469
0 commit comments