Added user rank changes to admin page.
This commit is contained in:
parent
064109556c
commit
8a4a21cff0
13 changed files with 276 additions and 30 deletions
54
src/controllers/api/admin/changeRankController.js
Normal file
54
src/controllers/api/admin/changeRankController.js
Normal 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);
|
||||
}
|
||||
}
|
||||
31
src/controllers/api/admin/listChannelsController.js
Normal file
31
src/controllers/api/admin/listChannelsController.js
Normal 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);
|
||||
}
|
||||
}
|
||||
31
src/controllers/api/admin/listUsersController.js
Normal file
31
src/controllers/api/admin/listUsersController.js
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue