diff --git a/src/app/channel/channelManager.js b/src/app/channel/channelManager.js index 042f286..525c94f 100644 --- a/src/app/channel/channelManager.js +++ b/src/app/channel/channelManager.js @@ -16,7 +16,6 @@ along with this program. If not, see .*/ //Local Imports const channelModel = require('../../schemas/channel/channelSchema'); -const flairModel = require('../../schemas/flairSchema'); const userModel = require('../../schemas/userSchema'); const loggerUtils = require('../../utils/loggerUtils'); const activeChannel = require('./activeChannel'); diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index 0198204..c6c2955 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -54,7 +54,6 @@ module.exports = class{ async setFlair(socket, data){ var userDB = await userModel.findOne({user: socket.user.user}); - const chanList = this.server.getConnectedChannels(socket) if(userDB){ try{ diff --git a/src/controllers/api/account/rankEnumController.js b/src/controllers/api/account/rankEnumController.js new file mode 100644 index 0000000..0776293 --- /dev/null +++ b/src/controllers/api/account/rankEnumController.js @@ -0,0 +1,29 @@ +/*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 .*/ + +//local imports +const permissionModel = require('../../../schemas/permissionSchema.js'); +const {exceptionHandler} = require('../../../utils/loggerUtils.js'); + +//api account functions +module.exports.get = async function(req, res){ + try{ + res.status(200); + return res.send(permissionModel.rankEnum); + }catch(err){ + return exceptionHandler(res, err); + } +} \ No newline at end of file diff --git a/src/controllers/api/channel/rankController.js b/src/controllers/api/channel/rankController.js index e85ef32..e779c7a 100644 --- a/src/controllers/api/channel/rankController.js +++ b/src/controllers/api/channel/rankController.js @@ -50,7 +50,7 @@ module.exports.get = async function(req, res){ //Send out the userlist we created res.status(200); - res.send(userList); + res.send(Object.fromEntries(userList)); }else{ //If we received bad input, we have only one action: bitch, moan, and complain! res.status(400); @@ -97,10 +97,10 @@ module.exports.post = async function(req, res){ } //Set rank - var rankList = await chanDB.setRank(userDB, data.rank); + await chanDB.setRank(userDB, data.rank); res.status(200); - res.send(rankList); + res.send(Object.fromEntries(await chanDB.getRankList())); }else{ //If we received bad input, we have only one action: bitch, moan, and complain! res.status(400); diff --git a/src/controllers/channelSettingsController.js b/src/controllers/channelSettingsController.js index 27226f2..a79e1a9 100644 --- a/src/controllers/channelSettingsController.js +++ b/src/controllers/channelSettingsController.js @@ -18,20 +18,27 @@ along with this program. If not, see .*/ const config = require('../../config.json'); //local imports -const {exceptionHandler} = require('../utils/loggerUtils.js'); +const {exceptionHandler} = require('../utils/loggerUtils'); const channelModel = require('../schemas/channel/channelSchema'); +const permissionModel = require('../schemas/permissionSchema'); //root index functions module.exports.get = async function(req, res){ try{ const chanName = (req.url.slice(1).replace('/settings','')); - const channel = await channelModel.findOne({name: chanName}); + const chanDB = await channelModel.findOne({name: chanName}); + const reqRank = await chanDB.getChannelRank(req.session.user); - if(channel == null){ + await chanDB.populate("rankList.user"); + + //Take out the permissions doc id since we don't need it. + delete chanDB.permissions._doc._id; + + if(chanDB == null){ throw new Error("Channel not found."); } - return res.render('channelSettings', {instance: config.instanceName, user: req.session.user, channel}); + return res.render('channelSettings', {instance: config.instanceName, user: req.session.user, channel: chanDB, reqRank, rankEnum: permissionModel.rankEnum}); }catch(err){ return exceptionHandler(res, err); } diff --git a/src/routers/api/accountRouter.js b/src/routers/api/accountRouter.js index d02d42f..d22e2d7 100644 --- a/src/routers/api/accountRouter.js +++ b/src/routers/api/accountRouter.js @@ -23,6 +23,7 @@ const loginController = require("../../controllers/api/account/loginController") const logoutController = require("../../controllers/api/account/logoutController"); const registerController = require("../../controllers/api/account/registerController"); const updateController = require("../../controllers/api/account/updateController"); +const rankEnumController = require("../../controllers/api/account/rankEnumController"); const deleteController = require("../../controllers/api/account/deleteController"); //globals @@ -45,6 +46,9 @@ router.post('/update', accountValidator.img(), accountValidator.securePass('passChange.newPass'), accountValidator.pass('passChange.confirmPass'), updateController.post); +//This might seem silly, but it allows us to cleanly get the current rank list to compare against, without storing it in multiple places +router.get('/rankEnum', rankEnumController.get); + router.post('/delete', accountValidator.pass(), deleteController.post); module.exports = router; \ No newline at end of file diff --git a/src/schemas/channel/channelSchema.js b/src/schemas/channel/channelSchema.js index 96a20e2..9dcb4b4 100644 --- a/src/schemas/channel/channelSchema.js +++ b/src/schemas/channel/channelSchema.js @@ -241,7 +241,7 @@ channelSchema.methods.setRank = async function(userDB,rank){ channelSchema.methods.getRankList = async function(){ //Create an empty array to hold the user list - const rankList = []; + const rankList = new Map() //Populate the user objects in our ranklist based off of their DB ID's await this.populate('rankList.user'); @@ -252,11 +252,12 @@ channelSchema.methods.getRankList = async function(){ const userObj = { id: rankObj.user.id, user: rankObj.user.user, + img: rankObj.user.img, rank: rankObj.rank } //Add our user object to the list - rankList.push(userObj); + rankList.set(rankObj.user.user, userObj); }); //return userList diff --git a/src/views/adminPanel.ejs b/src/views/adminPanel.ejs index 9418fc2..f53f4d0 100644 --- a/src/views/adminPanel.ejs +++ b/src/views/adminPanel.ejs @@ -22,6 +22,7 @@ along with this program. If not, see .--> <%- include('partial/navbar', {user}); %> +

<%= instance %> Admin Panel

<%- include('partial/adminPanel/channelList', {chanGuide}) %> <%- include('partial/adminPanel/userList', {user, userList, rankEnum}) %> <%- include('partial/adminPanel/permList', {permList, rankEnum}) %> diff --git a/src/views/channelSettings.ejs b/src/views/channelSettings.ejs index 03d183b..8a415e7 100644 --- a/src/views/channelSettings.ejs +++ b/src/views/channelSettings.ejs @@ -17,17 +17,16 @@ along with this program. If not, see .--> <%- include('partial/styles', {instance, user}); %> - - <%= instance %> - Channel Settings: <%= channel.name %> + + + <%= instance %> - <%= channel.name %> - Channel Settings <%- include('partial/navbar', {user}); %> -
- - - checked <% } %>> - -
+

<%- channel.name %> - Channel Settings

+ <%- include('partial/channelSettings/userList.ejs'); %> + <%- include('partial/channelSettings/settings.ejs'); %> + <%- include('partial/channelSettings/permList.ejs'); %> Delete Channel