@@ -433,47 +433,19 @@ def ban_checks():
433
433
@app .post ("/legacy/block_list" )
434
434
def handle_legacy_ban ():
435
435
user , room , to_ban = ban_checks ()
436
-
436
+ code = http . OK
437
437
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 })
441
440
442
441
443
442
@app .post ("/legacy/ban_and_delete_all" )
444
443
def handle_legacy_banhammer ():
445
444
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 })
477
449
478
450
479
451
@app .delete ("/legacy/block_list/<SessionID:session_id>" )
@@ -494,7 +466,7 @@ def handle_legacy_unban(session_id):
494
466
updated = cur .rowcount
495
467
496
468
if updated > 0 :
497
- return jsonify ({"status_code" : 200 })
469
+ return jsonify ({"status_code" : http . OK })
498
470
499
471
abort (http .NOT_FOUND )
500
472
0 commit comments