Fixed perms for schedule/channel playlists

This commit is contained in:
rainbow napkin 2025-04-04 20:38:40 -04:00
parent 8c990c14e6
commit e61d9deb52
3 changed files with 197 additions and 169 deletions

View file

@ -66,7 +66,7 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
//If the title is too long
if(!validator.isLength(data.playlist, {max:30})){
//Bitch, moan, complain...
@ -109,6 +109,7 @@ module.exports = class{
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -122,11 +123,13 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
//Delete playlist name
await chanDB.deletePlaylistByName(data.playlist);
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -140,6 +143,7 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
let url = data.url
//If we where given a bad URL
@ -172,6 +176,7 @@ module.exports = class{
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -185,6 +190,8 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
//Permcheck to make sure the user can fuck w/ the queue
if((!this.channel.queue.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
//Pull a valid start time from input, or make one up if we can't
let start = this.channel.queue.getStart(data.start);
@ -208,6 +215,7 @@ module.exports = class{
//Convert array of standard media objects to queued media objects, and push to schedule
this.channel.queue.scheduleMedia(queuedMedia.fromMediaArray(mediaList, start), socket, chanDB);
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -221,6 +229,7 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
//If the title is too long
if(!validator.isLength(data.name, {max:30})){
//Bitch, moan, complain...
@ -251,6 +260,7 @@ module.exports = class{
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -264,6 +274,7 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
//Find playlist
let playlist = chanDB.getPlaylistByName(data.playlist);
@ -287,6 +298,7 @@ module.exports = class{
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}
@ -300,6 +312,7 @@ module.exports = class{
chanDB = await channelModel.findOne({name: this.channel.name});
}
if(await chanDB.permCheck(socket.user, 'editChannelPlaylists')){
//If we don't have a valid UUID
if(!validator.isUUID(data.uuid)){
//Bitch, moan, complain...
@ -313,6 +326,7 @@ module.exports = class{
//Return playlists from channel doc
socket.emit('chanPlaylists', chanDB.getPlaylists());
}
}catch(err){
return loggerUtils.socketExceptionHandler(socket, err);
}

View file

@ -54,7 +54,7 @@ module.exports = class{
defineListeners(socket){
socket.on("queue", (data) => {this.queueURL(socket, data)});
socket.on("stop", (data) => {this.stopMedia(socket)});
socket.on("stop", (data) => {this.stopMedia(socket)}); //needs perms
socket.on("delete", (data) => {this.deleteMedia(socket, data)});
socket.on("clear", (data) => {this.deleteRange(socket, data)});
socket.on("move", (data) => {this.moveMedia(socket, data)});
@ -121,7 +121,14 @@ module.exports = class{
}
}
stopMedia(socket){
async stopMedia(socket){
//Get the current channel from the database
const chanDB = await channelModel.findOne({name: socket.chan});
console.log(!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin');
//Permcheck to make sure the user can fuck w/ the queue
if((!this.locked && await chanDB.permCheck(socket.user, 'scheduleMedia')) || await chanDB.permCheck(socket.user, 'scheduleAdmin')){
//If we're not currently playing anything
if(this.nowPlaying == null){
//If an originating socket was provided for this request
@ -143,6 +150,7 @@ module.exports = class{
//End the media
this.end();
}
}
async deleteMedia(socket, data){
//Get the current channel from the database

View file

@ -100,6 +100,12 @@ const channelPermissionSchema = new mongoose.Schema({
default: "admin",
required: true
},
editChannelPlaylists:{
type: mongoose.SchemaTypes.String,
enum: rankEnum,
default: "admin",
required: true
},
deleteChannel: {
type: mongoose.SchemaTypes.String,
enum: rankEnum,