From 756c42ceaa9f88e17b1643b10ae2e55eb8e92822 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Tue, 31 Dec 2024 20:03:25 -0500 Subject: [PATCH] Added optional alt-inclusion to channel-wide bans. --- src/schemas/channel/channelSchema.js | 24 +++++++++++++++++++----- src/schemas/user/userSchema.js | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/schemas/channel/channelSchema.js b/src/schemas/channel/channelSchema.js index 8642aae..32eb67a 100644 --- a/src/schemas/channel/channelSchema.js +++ b/src/schemas/channel/channelSchema.js @@ -470,13 +470,27 @@ channelSchema.methods.permCheck = async function (user, perm){ channelSchema.methods.checkBanByUserDoc = async function(userDB){ var foundBan = null; - this.banList.forEach((ban) => { - if(ban.user != null){ - if(ban.user.toString() == userDB._id.toString()){ - foundBan = ban; + //this needs to be a for loop for async + //this.banList.forEach((ban) => { + for(banIndex in this.banList){ + + if(this.banList[banIndex].user != null){ + if(this.banList[banIndex].user.toString() == userDB._id.toString()){ + foundBan = this.banList[banIndex]; + } + + //If this bans alts are banned + if(this.banList[banIndex].banAlts){ + //Populate the user of the current ban being checked + await this.populate(`banList.${banIndex}.user`); + + //If this is an alt of the banned user + if(await this.banList[banIndex].user.altCheck(userDB)){ + foundBan = this.banList[banIndex]; + } } } - }); + } return foundBan; } diff --git a/src/schemas/user/userSchema.js b/src/schemas/user/userSchema.js index e6517f0..ab84e66 100644 --- a/src/schemas/user/userSchema.js +++ b/src/schemas/user/userSchema.js @@ -633,6 +633,21 @@ userSchema.methods.changePassword = async function(passChange){ } +userSchema.methods.altCheck = async function(userDB){ + //Found alt flag + let foundAlt = false; + + for(alt in this.alts){ + //If we found a match + if(this.alts[alt]._id.toString() == userDB._id.toString()){ + foundAlt = true; + } + } + + //return the results + return foundAlt; +} + userSchema.methods.nuke = async function(pass){ //Check we have a confirmation password if(pass == "" || pass == null){