|
@@ -446,10 +446,29 @@ if (Meteor.isClient) {
|
|
|
|
|
|
Template.admin.helpers({
|
|
Template.admin.helpers({
|
|
queues: function() {
|
|
queues: function() {
|
|
- return Queues.find({});
|
|
|
|
|
|
+ var queues = Queues.find({}).fetch();
|
|
|
|
+ queues.map(function(queue) {
|
|
|
|
+ if (Rooms.find({type: queue.type}).count() !== 1) {
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ queue.display = Rooms.findOne({type: queue.type}).display;
|
|
|
|
+ return queue;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return queues;
|
|
},
|
|
},
|
|
playlists: function() {
|
|
playlists: function() {
|
|
- return Playlists.find({});
|
|
|
|
|
|
+ var playlists = Playlists.find({}).fetch();
|
|
|
|
+ playlists.map(function(playlist) {
|
|
|
|
+ if (Rooms.find({type: playlist.type}).count() !== 1) {
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ playlist.display = Rooms.findOne({type: playlist.type}).display;
|
|
|
|
+ return playlist;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ console.log(playlists);
|
|
|
|
+ return playlists;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -591,7 +610,7 @@ if (Meteor.isClient) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- "click #delete-room": function(){
|
|
|
|
|
|
+ "click .delete-room": function(){
|
|
var typeDel = $(this)[0].type;
|
|
var typeDel = $(this)[0].type;
|
|
console.log(typeDel);
|
|
console.log(typeDel);
|
|
Meteor.call("deleteRoom", typeDel);
|
|
Meteor.call("deleteRoom", typeDel);
|
|
@@ -1200,33 +1219,40 @@ if (Meteor.isServer) {
|
|
return Meteor.users.find({_id: this.userId, "profile.rank": "admin"});
|
|
return Meteor.users.find({_id: this.userId, "profile.rank": "admin"});
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ function isAdmin() {
|
|
|
|
+ var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
+ if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
Meteor.methods({
|
|
Meteor.methods({
|
|
pauseRoom: function(type) {
|
|
pauseRoom: function(type) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
getStation(type, function(station) {
|
|
getStation(type, function(station) {
|
|
if (station === undefined) {
|
|
if (station === undefined) {
|
|
- throw new Meteor.error(403, "Room doesn't exist.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Room doesn't exist.");
|
|
} else {
|
|
} else {
|
|
station.pauseRoom();
|
|
station.pauseRoom();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
resumeRoom: function(type) {
|
|
resumeRoom: function(type) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
getStation(type, function(station) {
|
|
getStation(type, function(station) {
|
|
if (station === undefined) {
|
|
if (station === undefined) {
|
|
- throw new Meteor.error(403, "Room doesn't exist.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Room doesn't exist.");
|
|
} else {
|
|
} else {
|
|
station.resumeRoom();
|
|
station.resumeRoom();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
createUserMethod: function(formData, captchaData) {
|
|
createUserMethod: function(formData, captchaData) {
|
|
@@ -1268,56 +1294,51 @@ if (Meteor.isServer) {
|
|
});
|
|
});
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid data.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid data.");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid genre.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid genre.");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
updateQueueSong: function(genre, oldSong, newSong) {
|
|
updateQueueSong: function(genre, oldSong, newSong) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
newSong.id = oldSong.id;
|
|
newSong.id = oldSong.id;
|
|
Queues.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
|
|
Queues.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
updatePlaylistSong: function(genre, oldSong, newSong) {
|
|
updatePlaylistSong: function(genre, oldSong, newSong) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
newSong.id = oldSong.id;
|
|
newSong.id = oldSong.id;
|
|
Playlists.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
|
|
Playlists.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
removeSongFromQueue: function(type, songId) {
|
|
removeSongFromQueue: function(type, songId) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
type = type.toLowerCase();
|
|
type = type.toLowerCase();
|
|
Queues.update({type: type}, {$pull: {songs: {id: songId}}});
|
|
Queues.update({type: type}, {$pull: {songs: {id: songId}}});
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
removeSongFromPlaylist: function(type, songId) {
|
|
removeSongFromPlaylist: function(type, songId) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
type = type.toLowerCase();
|
|
type = type.toLowerCase();
|
|
Playlists.update({type: type}, {$pull: {songs: {id: songId}}});
|
|
Playlists.update({type: type}, {$pull: {songs: {id: songId}}});
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
addSongToPlaylist: function(type, songData) {
|
|
addSongToPlaylist: function(type, songData) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
type = type.toLowerCase();
|
|
type = type.toLowerCase();
|
|
if (Rooms.find({type: type}).count() === 1) {
|
|
if (Rooms.find({type: type}).count() === 1) {
|
|
if (Playlists.find({type: type}).count() === 0) {
|
|
if (Playlists.find({type: type}).count() === 0) {
|
|
@@ -1339,27 +1360,31 @@ if (Meteor.isServer) {
|
|
Queues.update({type: type}, {$pull: {songs: {id: songData.id}}});
|
|
Queues.update({type: type}, {$pull: {songs: {id: songData.id}}});
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid data.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid data.");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid genre.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid genre.");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- throw new Meteor.error(403, "Invalid permissions.");
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
createRoom: function(display, tag) {
|
|
createRoom: function(display, tag) {
|
|
- var userData = Meteor.users.find(Meteor.userId());
|
|
|
|
- if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
createRoom(display, tag);
|
|
createRoom(display, tag);
|
|
} else {
|
|
} else {
|
|
- return false;
|
|
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
deleteRoom: function(type){
|
|
deleteRoom: function(type){
|
|
- Rooms.remove({type: type})
|
|
|
|
- Playlists.remove({type: type});
|
|
|
|
- Queues.remove({type: type});
|
|
|
|
|
|
+ if (isAdmin()) {
|
|
|
|
+ Rooms.remove({type: type});
|
|
|
|
+ Playlists.remove({type: type});
|
|
|
|
+ Queues.remove({type: type});
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ throw new Meteor.Error(403, "Invalid permissions.");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|