Fixed bug in perm check middleware caused by last refactor
This commit is contained in:
parent
5ad1c99ead
commit
805387b3da
19 changed files with 30 additions and 26 deletions
|
|
@ -21,7 +21,7 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
//Local Imports
|
||||
const server = require('../../server');
|
||||
const statModel = require('../statSchema');
|
||||
const userModel = require('../userSchema');
|
||||
const {userModel} = require('../userSchema');
|
||||
const permissionModel = require('../permissionSchema');
|
||||
const channelPermissionSchema = require('./channelPermissionSchema');
|
||||
const channelBanSchema = require('./channelBanSchema');
|
||||
|
|
|
|||
|
|
@ -119,8 +119,11 @@ permissionSchema.statics.rankToNum = function(rank){
|
|||
}
|
||||
|
||||
permissionSchema.statics.permCheck = async function(user, perm){
|
||||
//Check if the user is null
|
||||
if(user != null){
|
||||
const userDB = await userModel.findOne({user: user.user});
|
||||
//This specific call is why we export the userModel the way we do
|
||||
//Someone will yell at me for circular dependencies but the fucking interpreter isn't :P
|
||||
const userDB = await userModel.userModel.findOne({user: user.user});
|
||||
return await this.permCheckByUserDoc(userDB, perm);
|
||||
}else{
|
||||
return await this.permCheckByUserDoc(null, perm);
|
||||
|
|
@ -154,13 +157,14 @@ permissionSchema.statics.permCheckByUserDoc = async function(user, perm){
|
|||
|
||||
//Middleware for rank checks
|
||||
permissionSchema.statics.reqPermCheck = function(perm){
|
||||
return async (req, res, next)=>{
|
||||
|
||||
if(await permissionSchema.statics.permCheck(req.session.user, perm)){
|
||||
next();
|
||||
}else{
|
||||
return errorHandler(res, "You do not have a high enough rank to access this resource.", 'Unauthorized', 401);
|
||||
}
|
||||
return (req, res, next)=>{
|
||||
permissionSchema.statics.permCheck(req.session.user, perm).then((access) => {
|
||||
if(access){
|
||||
next();
|
||||
}else{
|
||||
return errorHandler(res, "You do not have a high enough rank to access this resource.", 'Unauthorized', 401);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const {mongoose} = require('mongoose');
|
||||
|
||||
//Local Imports
|
||||
const userModel = require('./userSchema');
|
||||
const {userModel} = require('./userSchema');
|
||||
|
||||
const userBanSchema = new mongoose.Schema({
|
||||
user: {
|
||||
|
|
|
|||
|
|
@ -402,4 +402,4 @@ userSchema.methods.nuke = async function(pass){
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = mongoose.model("user", userSchema);
|
||||
module.exports.userModel = mongoose.model("user", userSchema);
|
||||
Loading…
Add table
Add a link
Reference in a new issue