Added more granular permissions.
This commit is contained in:
parent
ef4894e409
commit
2dbf3b97d5
|
|
@ -98,7 +98,6 @@ module.exports.post = async function(req, res){
|
|||
res.send({errors: validResult.array()})
|
||||
}
|
||||
}catch(err){
|
||||
console.log(err);
|
||||
return exceptionHandler(res, err);
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,6 @@ module.exports.post = async function(req, res){
|
|||
res.send({errors: validResult.array()})
|
||||
}
|
||||
}catch(err){
|
||||
console.log(err);
|
||||
exceptionHandler(res, err);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,7 +107,6 @@ module.exports.post = async function(req, res){
|
|||
res.send({errors: validResult.array()})
|
||||
}
|
||||
}catch(err){
|
||||
console.log(err);
|
||||
return exceptionHandler(res, err);
|
||||
}
|
||||
}
|
||||
|
|
@ -32,18 +32,15 @@ const banController = require("../../controllers/api/admin/banController");
|
|||
//globals
|
||||
const router = Router();
|
||||
|
||||
//Use authentication middleware
|
||||
router.use(permissionSchema.reqPermCheck("adminAPI"));
|
||||
|
||||
//routing functions
|
||||
router.get('/listUsers', listUsersController.get);
|
||||
router.get('/listChannels', listChannelsController.get);
|
||||
router.get('/permissions', permissionsController.get);
|
||||
router.post('/permissions', checkExact([permissionsValidator.permissionsMap(), channelPermissionValidator.channelPermissionsMap()]), permissionsController.post);
|
||||
router.post('/changeRank', accountValidator.user(), accountValidator.rank(), changeRankController.post);
|
||||
router.get('/ban', banController.get);
|
||||
router.get('/listUsers', permissionSchema.reqPermCheck("adminPanel"), listUsersController.get);
|
||||
router.get('/listChannels', permissionSchema.reqPermCheck("adminPanel"), listChannelsController.get);
|
||||
router.get('/permissions', permissionSchema.reqPermCheck("adminPanel"), permissionsController.get);
|
||||
router.post('/permissions', permissionSchema.reqPermCheck("changePerms"), checkExact([permissionsValidator.permissionsMap(), channelPermissionValidator.channelPermissionsMap()]), permissionsController.post);
|
||||
router.post('/changeRank', permissionSchema.reqPermCheck("changeRank"), accountValidator.user(), accountValidator.rank(), changeRankController.post);
|
||||
router.get('/ban', permissionSchema.reqPermCheck("adminPanel"), banController.get);
|
||||
//Sometimes they're so simple you don't need to put your validators in their own special place :P
|
||||
router.post('/ban', accountValidator.user(), body("permanent").isBoolean(), body("expirationDays").isInt(), banController.post);
|
||||
router.delete('/ban', accountValidator.user(), banController.delete);
|
||||
router.post('/ban', permissionSchema.reqPermCheck("banUser"), accountValidator.user(), body("permanent").isBoolean(), body("expirationDays").isInt(), banController.post);
|
||||
router.delete('/ban', permissionSchema.reqPermCheck("banUser"), accountValidator.user(), banController.delete);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//npm imports
|
||||
const { body } = require('express-validator');
|
||||
const { body, checkExact } = require('express-validator');
|
||||
const { Router } = require('express');
|
||||
|
||||
//local imports
|
||||
|
|
@ -37,31 +37,31 @@ const router = Router();
|
|||
|
||||
//user authentication middleware
|
||||
router.use("/register",permissionSchema.reqPermCheck("registerChannel"));
|
||||
router.use("/settings", channelValidator.name('chanName'), channelModel.reqPermCheck("manageChannel"));
|
||||
router.use("/permissions", channelValidator.name('chanName'), channelModel.reqPermCheck("manageChannel"));
|
||||
router.use("/rank", channelValidator.name('chanName'), channelModel.reqPermCheck("manageChannel"));
|
||||
router.use("/delete", channelValidator.name('chanName'), channelModel.reqPermCheck("deleteChannel"));
|
||||
router.use("/ban", channelValidator.name('chanName'), channelModel.reqPermCheck("manageChannel"));
|
||||
router.use("/settings", channelValidator.name('chanName'));
|
||||
router.use("/permissions", channelValidator.name('chanName'));
|
||||
router.use("/rank", channelValidator.name('chanName'));
|
||||
router.use("/delete", channelValidator.name('chanName'));
|
||||
router.use("/ban", channelValidator.name('chanName'));
|
||||
|
||||
//routing functions
|
||||
//register
|
||||
router.post('/register', channelValidator.name(), channelValidator.description(), channelValidator.thumbnail(), registerController.post);
|
||||
//list
|
||||
router.get('/list', listController.get);
|
||||
router.get('/list', channelModel.reqPermCheck("manageChannel"), listController.get);
|
||||
//settings
|
||||
router.get('/settings', settingsController.get);
|
||||
router.post('/settings', channelValidator.settingsMap(), settingsController.post);
|
||||
router.get('/settings', channelModel.reqPermCheck("manageChannel"), settingsController.get);
|
||||
router.post('/settings', channelModel.reqPermCheck("changeSettings"), channelValidator.settingsMap(), settingsController.post);
|
||||
//permissions
|
||||
router.get('/permissions', permissionsController.get);
|
||||
router.post('/permissions', channelPermissionValidator.channelPermissionsMap(), permissionsController.post);
|
||||
router.get('/permissions', channelModel.reqPermCheck("manageChannel"), permissionsController.get);
|
||||
router.post('/permissions', channelModel.reqPermCheck("changePerms"), checkExact(channelPermissionValidator.channelPermissionsMap()), permissionsController.post);
|
||||
//rank
|
||||
router.get('/rank', rankController.get);
|
||||
router.post('/rank', accountValidator.user(), channelValidator.rank(), rankController.post);
|
||||
router.get('/rank', channelModel.reqPermCheck("manageChannel"), rankController.get);
|
||||
router.post('/rank', channelModel.reqPermCheck("changeRank"), accountValidator.user(), channelValidator.rank(), rankController.post);
|
||||
//delete
|
||||
router.post('/delete', channelValidator.name('confirm'), deleteController.post);
|
||||
router.post('/delete', channelModel.reqPermCheck("deleteChannel"), channelValidator.name('confirm'), deleteController.post);
|
||||
//ban
|
||||
router.get('/ban', banController.get);
|
||||
router.post('/ban', accountValidator.user(), body("banAlts").isBoolean(), body("expirationDays").isInt(), banController.post);
|
||||
router.delete('/ban', accountValidator.user(), banController.delete);
|
||||
router.get('/ban', channelModel.reqPermCheck("manageChannel"), banController.get);
|
||||
router.post('/ban', channelModel.reqPermCheck("banUser"), accountValidator.user(), body("banAlts").isBoolean(), body("expirationDays").isInt(), banController.post);
|
||||
router.delete('/ban', channelModel.reqPermCheck("banUser"), accountValidator.user(), banController.delete);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -28,6 +28,36 @@ const channelPermissionSchema = new mongoose.Schema({
|
|||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
changeRank: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
changePerms: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
changeSettings: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
kickUser: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
banUser: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
deleteChannel: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
|
|
|
|||
|
|
@ -84,55 +84,56 @@ channelSchema.pre('save', async function (next){
|
|||
|
||||
//Getting the affected user would be a million times easier elsewhere
|
||||
//But this ensures it happens every time channel rank gets changed no matter what
|
||||
if(this.isModified('rankList')){
|
||||
if(this.isModified('rankList') && this.rankList != null){
|
||||
//Get the rank list before it was modified (gross but works, find a better way if you dont like it :P)
|
||||
var chanDB = await module.exports.findOne({_id: this._id});
|
||||
//Create empty variable for the found rank object
|
||||
var foundRank = null;
|
||||
|
||||
//If we're removing one
|
||||
if(chanDB.rankList.length > this.rankList.length){
|
||||
//Child/Parent is *WAY* to atomic family for my tastes :P
|
||||
var top = chanDB;
|
||||
var bottom = this;
|
||||
}else{
|
||||
//otherwise reverse the loops
|
||||
var top = this;
|
||||
var bottom = chanDB;
|
||||
}
|
||||
|
||||
//Populate the top doc
|
||||
await top.populate('rankList.user');
|
||||
|
||||
|
||||
top.rankList.forEach((topObj) => {
|
||||
//Create empty variable for the matched rank
|
||||
var matchedRank = null;
|
||||
//For each rank in the old copy of the rank list
|
||||
bottom.rankList.forEach((bottomObj) => {
|
||||
if(topObj.user._id.toString() == bottomObj.user._id.toString()){
|
||||
matchedRank = bottomObj;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(matchedRank == null || matchedRank.rank != topObj.rank){
|
||||
foundRank = topObj;
|
||||
if(chanDB != null){
|
||||
//If we're removing one
|
||||
if(chanDB.rankList.length > this.rankList.length){
|
||||
//Child/Parent is *WAY* to atomic family for my tastes :P
|
||||
var top = chanDB;
|
||||
var bottom = this;
|
||||
}else{
|
||||
//otherwise reverse the loops
|
||||
var top = this;
|
||||
var bottom = chanDB;
|
||||
}
|
||||
|
||||
});
|
||||
//Populate the top doc
|
||||
await top.populate('rankList.user');
|
||||
|
||||
//get relevant active channel
|
||||
const activeChan = server.channelManager.activeChannels.get(this.name);
|
||||
|
||||
//if the channel is online
|
||||
if(activeChan != null){
|
||||
//Get the relevant user connection
|
||||
const userConn = activeChan.userList.get(foundRank.user.user);
|
||||
//if the user is online
|
||||
if(userConn != null){
|
||||
//kick the user
|
||||
userConn.disconnect("Your channel rank has changed!");
|
||||
top.rankList.forEach((topObj) => {
|
||||
//Create empty variable for the matched rank
|
||||
var matchedRank = null;
|
||||
//For each rank in the old copy of the rank list
|
||||
bottom.rankList.forEach((bottomObj) => {
|
||||
if(topObj.user._id.toString() == bottomObj.user._id.toString()){
|
||||
matchedRank = bottomObj;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(matchedRank == null || matchedRank.rank != topObj.rank){
|
||||
foundRank = topObj;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//get relevant active channel
|
||||
const activeChan = server.channelManager.activeChannels.get(this.name);
|
||||
|
||||
//if the channel is online
|
||||
if(activeChan != null){
|
||||
//Get the relevant user connection
|
||||
const userConn = activeChan.userList.get(foundRank.user.user);
|
||||
//if the user is online
|
||||
if(userConn != null){
|
||||
//kick the user
|
||||
userConn.disconnect("Your channel rank has changed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ flairSchema.statics.loadDefaults = async function(){
|
|||
}else{
|
||||
console.log("Error, null flair:");
|
||||
}
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,31 @@ const permissionSchema = new mongoose.Schema({
|
|||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
adminAPI: {
|
||||
changeRank: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
changePerms: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
banUser: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
nukeUser: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
required: true
|
||||
},
|
||||
genPasswordReset: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
enum: rankEnum,
|
||||
default: "admin",
|
||||
|
|
|
|||
|
|
@ -34,7 +34,31 @@ module.exports.permissionsValidator = {
|
|||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'permissionsMap.adminAPI': {
|
||||
'permissionsMap.changeRank': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'permissionsMap.changePerms': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'permissionsMap.banUser': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'permissionsMap.nukeUser': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'permissionsMap.genPasswordReset': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
|
|
@ -57,6 +81,36 @@ module.exports.channelPermissionValidator = {
|
|||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.changeRank': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.changePerms': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.changeSettings': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.kickUser': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.banUser': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.deleteChannel': {
|
||||
optional: true,
|
||||
custom: {
|
||||
|
|
|
|||
|
|
@ -275,6 +275,8 @@ class prefrenceList{
|
|||
constructor(channel){
|
||||
this.channel = channel;
|
||||
this.inputs = document.querySelectorAll(".channel-preference-list-item");
|
||||
|
||||
this.setupInput();
|
||||
}
|
||||
|
||||
setupInput(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue