Finished up implementing channel-based user bans.
This commit is contained in:
parent
ef79e9941c
commit
96953979a2
19 changed files with 518 additions and 202 deletions
|
|
@ -19,11 +19,12 @@ const {mongoose} = require('mongoose');
|
|||
const {validationResult, matchedData} = require('express-validator');
|
||||
|
||||
//Local Imports
|
||||
const statModel = require('../statSchema.js');
|
||||
const {userModel} = require('../userSchema.js');
|
||||
const permissionModel = require('../permissionSchema.js');
|
||||
const channelPermissionSchema = require('./channelPermissionSchema.js');
|
||||
const { exceptionHandler } = require('../../utils/loggerUtils.js');
|
||||
const statModel = require('../statSchema');
|
||||
const {userModel} = require('../userSchema');
|
||||
const permissionModel = require('../permissionSchema');
|
||||
const channelPermissionSchema = require('./channelPermissionSchema');
|
||||
const channelBanSchema = require('./channelBanSchema');
|
||||
const { exceptionHandler } = require('../../utils/loggerUtils');
|
||||
|
||||
const channelSchema = new mongoose.Schema({
|
||||
id: {
|
||||
|
|
@ -69,28 +70,7 @@ const channelSchema = new mongoose.Schema({
|
|||
}
|
||||
}],
|
||||
//Thankfully we don't have to keep track of alts, ips, or deleted users so this should be a little easier :P
|
||||
banList: [{
|
||||
user: {
|
||||
type: mongoose.SchemaTypes.ObjectID,
|
||||
required: true,
|
||||
ref: "user"
|
||||
},
|
||||
banDate: {
|
||||
type: mongoose.SchemaTypes.Date,
|
||||
required: true,
|
||||
default: new Date()
|
||||
},
|
||||
expirationDays: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
required: true,
|
||||
default: 14
|
||||
},
|
||||
banAlts: {
|
||||
type: mongoose.SchemaTypes.Boolean,
|
||||
required: true,
|
||||
default: false
|
||||
}
|
||||
}]
|
||||
banList: [channelBanSchema]
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -194,6 +174,21 @@ channelSchema.statics.reqPermCheck = function(perm, chanField = "chanName"){
|
|||
}
|
||||
}
|
||||
|
||||
channelSchema.statics.processExpiredBans = async function(){
|
||||
const chanDB = await this.find({});
|
||||
|
||||
chanDB.forEach((channel) => {
|
||||
channel.banList.forEach(async (ban, i) => {
|
||||
//ignore permanent and non-expired bans
|
||||
if(ban.expirationDays >= 0 && ban.getDaysUntilExpiration() <= 0){
|
||||
//Get the index of the ban
|
||||
channel.banList.splice(i,1);
|
||||
return await channel.save();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
channelSchema.methods.updateSettings = async function(settingsMap){
|
||||
settingsMap.forEach((value, key) => {
|
||||
|
|
@ -372,6 +367,7 @@ channelSchema.methods.getChanBans = async function(){
|
|||
var banObj = {
|
||||
banDate: ban.banDate,
|
||||
expirationDays: ban.expirationDays,
|
||||
banAlts: ban.banAlts,
|
||||
}
|
||||
|
||||
//Check if the ban was permanent (expiration set before ban date)
|
||||
|
|
@ -382,6 +378,7 @@ channelSchema.methods.getChanBans = async function(){
|
|||
|
||||
//Set calculated expiration date
|
||||
banObj.expirationDate = expirationDate;
|
||||
banObj.daysUntilExpiration = ban.getDaysUntilExpiration();
|
||||
}
|
||||
|
||||
//Setup user object (Do this last to keep it at bottom for human-readibility of json :P)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue