Added user rank changes to admin page.

This commit is contained in:
rainbownapkin 2024-11-17 17:37:07 -05:00
parent 064109556c
commit 8a4a21cff0
13 changed files with 276 additions and 30 deletions

View file

@ -0,0 +1,54 @@
/*Canopy - The next generation of stoner streaming software
Copyright (C) 2024 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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 {validationResult, matchedData} = require('express-validator');
//local imports
const {exceptionHandler} = require('../../../utils/loggerUtils');
const permissionModel = require('../../../schemas/permissionSchema');
const userModel = require('../../../schemas/userSchema');
//api account functions
module.exports.post = async function(req, res){
try{
const validResult = validationResult(req);
if(validResult.isEmpty()){
const data = matchedData(req);
const user = await userModel.findOne({user: data.user});
if(user == null){
res.status(400);
res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
}else if(permissionModel.rankToNum(data.rank) >= permissionModel.rankToNum(req.session.user.rank)){
res.status(401);
return res.send({errors:[{type: "Unauthorized", msg: "New rank must be below that of the user changing it.", date: new Date()}]});
}
user.rank = data.rank;
await user.save();
res.status(200);
return res.send({user: user.user, id: user.id, rank: user.rank});
}else{
res.status(400);
res.send({errors: validResult.array()})
}
}catch(err){
return exceptionHandler(res, err);
}
}

View file

@ -0,0 +1,31 @@
/*Canopy - The next generation of stoner streaming software
Copyright (C) 2024 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.*/
//local imports
const channelModel = require('../../../schemas/channelSchema');
//api account functions
module.exports.get = async function(req, res){
try{
const chanGuide = await channelModel.getChannelList(true);
res.status(200);
return res.send(chanGuide);
}catch(err){
res.status(400);
return res.send(err.message);
}
}

View file

@ -0,0 +1,31 @@
/*Canopy - The next generation of stoner streaming software
Copyright (C) 2024 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.*/
//local imports
const userModel = require('../../../schemas/userSchema');
//api account functions
module.exports.get = async function(req, res){
try{
const userList = await userModel.getUserList(true);
res.status(200);
return res.send(userList);
}catch(err){
res.status(400);
return res.send(err.message);
}
}

View file

@ -20,8 +20,7 @@ const channelModel = require('../../../schemas/channelSchema');
//api account functions
module.exports.get = async function(req, res){
try{
//I'm not sanatizing this, it never gets processed...
const chanGuide = await channelModel.getChannelList(req.query.showHidden || req.query.showHidden === '');
const chanGuide = await channelModel.getChannelList();
res.status(200);
return res.send(chanGuide);