@@ -1019,6 +1019,51 @@ router.get("/flagged", async (req, res) => {
10191019 }
10201020} ) ;
10211021
1022+ router . get ( "/bans" , async ( req , res ) => {
1023+ res . setHeader ( "Content-Type" , "application/json" ) ;
1024+ try {
1025+ var userId = await routeUtils . verifyLoggedIn ( req ) ;
1026+ var userIdToActOn = String ( req . query . userId || "" ) . trim ( ) ;
1027+ var perm = "seeModPanel" ;
1028+
1029+ if ( ! ( await routeUtils . verifyPermission ( res , userId , perm ) ) ) return ;
1030+
1031+ if ( ! userIdToActOn ) {
1032+ res . status ( 400 ) ;
1033+ res . send ( "User ID is required." ) ;
1034+ return ;
1035+ }
1036+
1037+ var user = await models . User . findOne ( {
1038+ id : userIdToActOn ,
1039+ } ) . select ( "id" ) ;
1040+
1041+ if ( ! user ) {
1042+ res . status ( 404 ) ;
1043+ res . send ( "User does not exist." ) ;
1044+ return ;
1045+ }
1046+
1047+ var activeBans = await models . Ban . find ( {
1048+ userId : userIdToActOn ,
1049+ type : { $ne : "ipFlag" } ,
1050+ $or : [ { expires : 0 } , { expires : { $gt : Date . now ( ) } } ] ,
1051+ } ) . select ( "type expires -_id" ) ;
1052+
1053+ var formattedBans = activeBans . map ( ( ban ) => ( {
1054+ type : ban . type ,
1055+ expires : ban . expires ,
1056+ permanent : ban . expires === 0 ,
1057+ } ) ) ;
1058+
1059+ res . send ( formattedBans ) ;
1060+ } catch ( e ) {
1061+ logger . error ( e ) ;
1062+ res . status ( 500 ) ;
1063+ res . send ( "Error loading active bans." ) ;
1064+ }
1065+ } ) ;
1066+
10221067router . post ( "/clearSetupName" , async ( req , res ) => {
10231068 res . setHeader ( "Content-Type" , "application/json" ) ;
10241069 try {
@@ -3482,6 +3527,24 @@ router.post("/appeals/:id/approve", async (req, res) => {
34823527 violationTicket . appealedBy = userId ;
34833528 await violationTicket . save ( ) ;
34843529
3530+ // Remove the active ban associated with this violation
3531+ if ( violationTicket . linkedBanId ) {
3532+ await models . Ban . deleteMany ( {
3533+ id : violationTicket . linkedBanId ,
3534+ } ) . exec ( ) ;
3535+
3536+ // Handle site bans - update User.banned flag
3537+ if ( violationTicket . banType === "site" ) {
3538+ await models . User . updateOne (
3539+ { id : violationTicket . userId } ,
3540+ { $set : { banned : false } }
3541+ ) . exec ( ) ;
3542+ }
3543+
3544+ // Refresh user permissions cache
3545+ await redis . cacheUserPermissions ( violationTicket . userId ) ;
3546+ }
3547+
34853548 // Update appeal
34863549 appeal . status = "approved" ;
34873550 appeal . reviewedBy = userId ;
0 commit comments